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());
}
N_Vector ParameterisedCvode::ComputeDerivedQuantities(double time,
                                                      const N_Vector& rState)
{
    N_Vector derived_quantities = NULL;
    CreateVectorIfEmpty(derived_quantities,1);
    SetVectorComponent(derived_quantities, 0,
                       2*GetVectorComponent(mParameters,0) + GetVectorComponent(rState,0));
    return derived_quantities;
}
VECTOR AbstractParameterisedSystem<VECTOR>::GetInitialConditions() const
{
    assert(mpSystemInfo);
    VECTOR v;
    InitialiseEmptyVector(v);
    CreateVectorIfEmpty(v, mNumberOfStateVariables);
    CopyFromStdVector(mpSystemInfo->GetInitialConditions(), v);
    return v;
}
ParameterisedCvode::ParameterisedCvode() : AbstractCvodeSystem(1) // 1 here is the number of variables
{
    this->mpSystemInfo = OdeSystemInformation<ParameterisedCvode>::Instance();
    Init();
    if (!noParameterDefaults)
    {
        CreateVectorIfEmpty(mParameters,1);
        SetVectorComponent(mParameters, 0, 0.0);
        if (fakeSecondParameter)
        {
            SetVectorComponent(mParameters, 1, -1.0);
        }
    }
}
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));
    }
}