void SimulationExperimentViewInformationParametersWidget::updateParameters(double pCurrentPoint)
{
    // Update our data

    for (auto property : allProperties()) {
        CellMLSupport::CellmlFileRuntimeParameter *parameter = mParameters.value(property);

        if (parameter != nullptr) {
            CellMLSupport::CellmlFileRuntimeParameter::Type parameterType = parameter->type();

            if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::Voi) {
                property->setDoubleValue(pCurrentPoint, false);
            } else if (   (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::Constant)
                       || (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::ComputedConstant)) {
                property->setDoubleValue(mSimulation->data()->constants()[parameter->index()], false);
            } else if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::Rate) {
                property->setDoubleValue(mSimulation->data()->rates()[parameter->index()], false);
            } else if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::State) {
                property->setDoubleValue(mSimulation->data()->states()[parameter->index()], false);
            } else if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::Algebraic) {
                property->setDoubleValue(mSimulation->data()->algebraic()[parameter->index()], false);
            } else if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::Data) {
                property->setDoubleValue(parameter->data()[parameter->index()], false);
            }
        }
    }

    // Check whether any of our properties has actually been modified

    mSimulation->data()->checkForModifications();
}
void SimulationExperimentViewInformationParametersWidget::propertyChanged(Core::Property *pProperty)
{
    // Update our simulation data

    CellMLSupport::CellmlFileRuntimeParameter *parameter = mParameters.value(pProperty);

    if (parameter != nullptr) {
        CellMLSupport::CellmlFileRuntimeParameter::Type parameterType = parameter->type();

        if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::Constant) {
            mSimulation->data()->constants()[parameter->index()] = pProperty->doubleValue();
        } else if (parameterType == CellMLSupport::CellmlFileRuntimeParameter::Type::State) {
            mSimulation->data()->states()[parameter->index()] = pProperty->doubleValue();
        }
    }

    // Recompute our 'computed constants' and 'variables'
    // Note #1: we would normally call
    //          mSimulation->data()->checkForModifications() after recomputing
    //          our 'computed constants' and 'variables, but the recomputation
    //          will eventually result in updateParameters() above to be called,
    //          which will check for modifications...
    // Note #2: some state variables may be considered as computed constants by
    //          the CellML API. This is fine when we need to initialise things,
    //          but not after the user has modified one or several model
    //          parameters (see issue #234 for more information), hence our
    //          passing false to mSimulation->data()->reset()...

    mSimulation->data()->reset(false);
}
예제 #3
0
bool SingleCellViewSimulationResults::createDataStore()
{
    // Note: the boolean value we return is true if we have had no problem
    //       creating our data store, false otherwise. This is the reason, for
    //       example, we return true when there is either no runtime or if the
    //       simulation size is zero...

    // Delete the previous data store, if any

    deleteDataStore();

    // Make sure that we have a runtime

    if (!mRuntime)
        return true;

    // Retrieve the size of our data and make sure that it is valid

    qulonglong simulationSize = qulonglong(mSimulation->size());

    if (!simulationSize)
        return true;

    // Create our data store and populate it with a variable of integration, as
    // well as with constant, rate, state and algebraic variables

    try {
        mDataStore = new CoreDataStore::CoreDataStore(simulationSize);

        mPoints = mDataStore->addVoi();
        mConstants = mDataStore->addVariables(mRuntime->constantsCount(), mSimulation->data()->constants());
        mRates = mDataStore->addVariables(mRuntime->ratesCount(), mSimulation->data()->rates());
        mStates = mDataStore->addVariables(mRuntime->statesCount(), mSimulation->data()->states());
        mAlgebraic = mDataStore->addVariables(mRuntime->algebraicCount(), mSimulation->data()->algebraic());
    } catch (...) {
        deleteDataStore();

        return false;
    }

    // Customise our variable of integration, as well as our constant, rate,
    // state and algebraic variables

    mPoints->setUri(uri(mRuntime->variableOfIntegration()->componentHierarchy(),
                        mRuntime->variableOfIntegration()->name()));
    mPoints->setLabel(mRuntime->variableOfIntegration()->name());
    mPoints->setUnit(mRuntime->variableOfIntegration()->unit());

    for (int i = 0, iMax = mRuntime->parameters().count(); i < iMax; ++i) {
        CellMLSupport::CellmlFileRuntimeParameter *parameter = mRuntime->parameters()[i];
        CoreDataStore::DataStoreVariable *variable = 0;

        switch (parameter->type()) {
        case CellMLSupport::CellmlFileRuntimeParameter::Constant:
        case CellMLSupport::CellmlFileRuntimeParameter::ComputedConstant:
            variable = mConstants[parameter->index()];

            break;
        case CellMLSupport::CellmlFileRuntimeParameter::Rate:
            variable = mRates[parameter->index()];

            break;
        case CellMLSupport::CellmlFileRuntimeParameter::State:
            variable = mStates[parameter->index()];

            break;
        case CellMLSupport::CellmlFileRuntimeParameter::Algebraic:
            variable = mAlgebraic[parameter->index()];

            break;
        default:
            // Not a type in which we are interested, so do nothing

            ;
        }

        if (variable) {
            variable->setUri(uri(parameter->componentHierarchy(),
                                 parameter->formattedName()));
            variable->setLabel(parameter->formattedName());
            variable->setUnit(parameter->formattedUnit(mRuntime->variableOfIntegration()->unit()));
        }
    }

    return true;
}