示例#1
0
	MeshPtr CreateCube()
	{
		static const std::vector<GLfloat> cubeVerts =
		{
			0.5f,  0.5f,  0.5f, 1.0f, 0.0f,
			0.5f,  0.5f, -0.5f, 0.0f, 0.0f,
			0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
			0.5f, -0.5f,  0.5f, 0.0f, 0.0f,
			-0.5f,  0.5f,  0.5f, 0.0f, 0.0f,
			-0.5f,  0.5f, -0.5f, 0.0f, 1.0f,
			-0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
			-0.5f, -0.5f,  0.5f, 0.0f, 1.0f
		};

		static const std::vector<unsigned int> cubeIdxs =
		{
			0, 2, 1, 0, 3, 2, // Right
			4, 5, 6, 4, 6, 7, // Left
			0, 7, 3, 0, 4, 7, // Top
			1, 6, 2, 1, 5, 6, // Bottom
			0, 5, 1, 0, 4, 5, // Front
			3, 7, 6, 3, 6, 2  // Back
		};

		auto vertexBuffer = std::make_shared<Buffer>(BufferTarget::ArrayBuffer);
		vertexBuffer->UploadData(cubeVerts.data(), GetVectorSize(cubeVerts));
		auto indexBuffer = std::make_shared<Buffer>(BufferTarget::ElementArrayBuffer);
		indexBuffer->UploadData(cubeIdxs.data(), GetVectorSize(cubeIdxs));

		return std::make_shared<Mesh>(vertexBuffer, VertexPosUv::ATTRIBUTES, indexBuffer, sizeof(GLuint), 36);
	}
void AbstractParameterisedSystem<VECTOR>::CheckParametersOnLoad(const std::vector<double>& rParameters, const std::vector<std::string>& rParameterNames)
{
    if (GetVectorSize(mParameters) != rGetParameterNames().size())
    {
        // Subclass constructor didn't give default values, so we need the archive to provide them all
        if (rParameterNames.size() != rGetParameterNames().size())
        {
            EXCEPTION("Number of ODE parameters in archive does not match number in class.");
        }
        CreateVectorIfEmpty(mParameters,rGetParameterNames().size());
    }

    // Check whether the archive specifies parameters that don't appear in this class,
    // and create a map from archive index to local index
    std::vector<unsigned> index_map(rParameterNames.size());
    for (unsigned i=0; i<rParameterNames.size(); ++i)
    {
        index_map[i] = find(rGetParameterNames().begin(), rGetParameterNames().end(), rParameterNames[i])
                       - rGetParameterNames().begin();
        if (index_map[i] == rGetParameterNames().size())
        {
            EXCEPTION("Archive specifies a parameter '" + rParameterNames[i] + "' which does not appear in this class.");
        }
    }

    for (unsigned i=0; i<rParameterNames.size(); ++i)
    {
        SetVectorComponent(mParameters,index_map[i],rParameters[i]);
    }

    // Paranoia check
    assert(GetVectorSize(mParameters) == rGetParameterNames().size());
}
double AbstractParameterisedSystem<VECTOR>::GetAnyVariable(unsigned index, double time,
                                                           VECTOR* pDerivedQuantities)
{
    if (index < mNumberOfStateVariables)
    {
        return GetVectorComponent(mStateVariables, index);
    }
    else if (index - mNumberOfStateVariables < GetVectorSize(mParameters))
    {
        return GetVectorComponent(mParameters, index - mNumberOfStateVariables);
    }
    else
    {
        unsigned offset = mNumberOfStateVariables + GetVectorSize(mParameters);
        if (index - offset < GetNumberOfDerivedQuantities())
        {
            VECTOR dqs;
            if (pDerivedQuantities == NULL)
            {
                dqs = ComputeDerivedQuantitiesFromCurrentState(time);
                pDerivedQuantities = &dqs;
            }
            double value = GetVectorComponent(*pDerivedQuantities, index - offset);
            if (pDerivedQuantities == &dqs)
            {
                DeleteVector(dqs);
            }
            return value;
        }
        else
        {
            EXCEPTION("Invalid index passed to GetAnyVariable.");
        }
    }
}
std::string AbstractParameterisedSystem<VECTOR>::GetStateMessage(const std::string& rMessage, VECTOR Y)
{
    std::stringstream res;
    res << rMessage << std::endl << "State:" << std::endl;
    assert(rGetStateVariableNames().size()==GetVectorSize(Y));
    const std::vector<std::string>& r_units = rGetStateVariableUnits();
    for (unsigned i=0; i<GetVectorSize(Y); i++)
    {
        res << "\t" << rGetStateVariableNames()[i] << ":" << GetVectorComponent(Y, i);
        if (!r_units.empty())
        {
            res << " " << r_units[i];
        }
        res << std::endl;
    }
    return res.str();
}
void AbstractParameterisedSystem<VECTOR>::SetParameter(unsigned index, double value)
{
    if (index >= GetVectorSize(mParameters))
    {
        EXCEPTION("The index passed in must be less than the number of parameters.");
    }
    SetVectorComponent(mParameters, index, value);
}
double AbstractParameterisedSystem<VECTOR>::GetParameter(unsigned index) const
{
    if (index >= GetVectorSize(mParameters))
    {
        EXCEPTION("The index passed in must be less than the number of parameters.");
    }
    return GetVectorComponent(mParameters, index);
}
示例#7
0
std::vector<POVMSType> POVMS_Attribute::GetTypeVector()
{
    std::vector<POVMSType> result;
    result.resize(GetVectorSize());
    int len = result.size() * sizeof(POVMSType);

    Get(kPOVMSType_VectorType, (void *)&result[0], &len);

    return result;
}
void AbstractParameterisedSystem<VECTOR>::SetDefaultInitialConditions(const VECTOR& rInitialConditions)
{
    if (GetVectorSize(rInitialConditions) != mNumberOfStateVariables)
    {
        EXCEPTION("The number of initial conditions must be that of the number of state variables.");
    }
    assert(mpSystemInfo);
    std::vector<double> inits;
    CopyToStdVector(rInitialConditions, inits);
    mpSystemInfo->SetDefaultInitialConditions(inits);
}
示例#9
0
 void CheckDerivedQuantities(AbstractParameterisedSystem<VECTOR_TYPE>& rCell,
                             const VECTOR_TYPE& rStateVec)
 {
     TS_ASSERT_EQUALS(rCell.GetNumberOfDerivedQuantities(), 2u);
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityIndex("FonRT"), 0u);
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityIndex("potassium_currents"), 1u);
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityUnits(0u), "per_millivolt");
     TS_ASSERT_EQUALS(rCell.GetDerivedQuantityUnits(1u), "microA_per_cm2");
     VECTOR_TYPE derived = rCell.ComputeDerivedQuantitiesFromCurrentState(0.0);
     const double FonRT = 0.037435728309031795;
     const double i_K_total = 1.0007;
     TS_ASSERT_EQUALS(GetVectorSize(derived), 2u);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 0), FonRT, 1e-12);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 1), i_K_total, 1e-4);
     DeleteVector(derived);
     derived = rCell.ComputeDerivedQuantities(0.0, rStateVec);
     TS_ASSERT_EQUALS(GetVectorSize(derived), 2u);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 0), FonRT, 1e-12);
     TS_ASSERT_DELTA(GetVectorComponent(derived, 1), i_K_total, 1e-4);
     DeleteVector(derived);
 }
void AbstractParameterisedSystem<VECTOR>::SetStateVariables(const VECTOR& rStateVariables)
{

    if ( mNumberOfStateVariables != GetVectorSize(rStateVariables) )
    {
        EXCEPTION("The size of the passed in vector must be that of the number of state variables.");
    }

    CreateVectorIfEmpty(mStateVariables, mNumberOfStateVariables);
    for (unsigned i=0; i<mNumberOfStateVariables; i++)
    {
        SetVectorComponent(mStateVariables, i, GetVectorComponent(rStateVariables, i));
    }
}
示例#11
0
void TestGetMatrix(int matrix, MatrixSize sz) {
	ILOG("Testing matrix %s", GetMatrixNotation(matrix, sz));
	u8 fullMatrix[16];

	u8 cols[4];
	u8 rows[4];

	GetMatrixColumns(matrix, sz, cols);
	GetMatrixRows(matrix, sz, rows);

	GetMatrixRegs(fullMatrix, sz, matrix);

	int n = GetMatrixSide(sz);
	VectorSize vsz = GetVectorSize(sz);
	for (int i = 0; i < n; i++) {
		// int colName = GetColumnName(matrix, sz, i, 0);
		// int rowName = GetRowName(matrix, sz, i, 0);
		int colName = cols[i];
		int rowName = rows[i];
		ILOG("Column %i: %s", i, GetVectorNotation(colName, vsz));
		ILOG("Row %i: %s", i, GetVectorNotation(rowName, vsz));

		u8 colRegs[4];
		u8 rowRegs[4];
		GetVectorRegs(colRegs, vsz, colName);
		GetVectorRegs(rowRegs, vsz, rowName);

		// Check that the individual regs are the expected ones.
		std::stringstream a, b, c, d;
		for (int j = 0; j < n; j++) {
			a.clear();
			b.clear();
			a << (int)fullMatrix[i * 4 + j] << " ";
			b << (int)colRegs[j] << " ";

			c.clear();
			d.clear();

			c << (int)fullMatrix[j * 4 + i] << " ";
			d << (int)rowRegs[j] << " ";
		}
		ILOG("Col: %s vs %s", a.str().c_str(), b.str().c_str());
		if (a.str() != b.str())
			ILOG("WRONG!");
		ILOG("Row: %s vs %s", c.str().c_str(), d.str().c_str());
		if (c.str() != d.str())
			ILOG("WRONG!");
	}
}
void AbstractParameterisedSystem<VECTOR>::SetAnyVariable(unsigned index, double value)
{
    if (index < mNumberOfStateVariables)
    {
        SetVectorComponent(mStateVariables, index, value);
    }
    else if (index - mNumberOfStateVariables < GetVectorSize(mParameters))
    {
        SetVectorComponent(mParameters, index - mNumberOfStateVariables, value);
    }
    else
    {
        EXCEPTION("Cannot set the value of a derived quantity, or invalid index.");
    }
}