当前位置: 首页>>代码示例>>C++>>正文


C++ ObjRef::nextComputationTarget方法代码示例

本文整理汇总了C++中ObjRef::nextComputationTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjRef::nextComputationTarget方法的具体用法?C++ ObjRef::nextComputationTarget怎么用?C++ ObjRef::nextComputationTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjRef的用法示例。


在下文中一共展示了ObjRef::nextComputationTarget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: flagVariable

int flagVariable(const std::string& variableId, unsigned char type,
                 std::vector<iface::cellml_services::VariableEvaluationType> vets,
                 int& count, CellmlApiObjects* capi,
                 std::map<std::string, unsigned char>& variableTypes,
                 std::map<std::string, std::map<unsigned char, int> >& variableIndices)
{
    if (! capi->codeInformation)
    {
        std::cerr << "CellML Model Definition::flagVariable: missing model implementation?" << std::endl;
        return csim::UNABLE_TO_FLAG_VARIABLE;
    }
    ObjRef<iface::cellml_api::CellMLVariable> sv = findLocalVariable(capi, variableId);
    if (!sv)
    {
        std::cerr << "CellML Model Definition::flagVariable: unable to find source variable for: "
                  << variableId << std::endl;
        return csim::UNABLE_TO_FLAG_VARIABLE;
    }

    // FIXME: here we simply accept any flag combination. Code generation is the place
    // where flags will be checked for consistency?

    // check if source is already flagged with the specified type.
    std::map<std::string, unsigned char>::iterator currentAnnotation =
            variableTypes.find(getVariableUniqueId(sv));
    unsigned char currentTypes;
    if (currentAnnotation != variableTypes.end())
    {
        currentTypes = currentAnnotation->second;
        if (currentTypes & type)
        {
            std::cout << "Already flagged same type, nothing to do." << std::endl;
            return variableIndices[getVariableUniqueId(sv)][type];
        }
    }
    // find corresponding computation target
    ObjRef<iface::cellml_services::ComputationTargetIterator> cti =
            capi->codeInformation->iterateTargets();
    ObjRef<iface::cellml_services::ComputationTarget> ct(NULL);
    while(true)
    {
        ct = cti->nextComputationTarget();
        if (ct == NULL) break;
        if (ct->variable() == sv) break;
    }
    if (!ct)
    {
        std::cerr << "CellMLModelDefinition::flagVariable -- unable get computation target for the source of variable: "
                  << variableId << std::endl;
        return csim::NO_MATCHING_COMPUTATION_TARGET;
    }

    // check type of computation target and make sure compatible
    unsigned int i,compatible = 0;
    for (i=0; i<vets.size(); i++)
    {
        if (ct->type() == vets[i])
        {
            compatible = 1;
            break;
        }
    }
    if (!compatible)
    {
        std::cerr << "CellMLModelDefinition::flagVariable -- computation target for variable: "
                  << variableId << "; is the wrong type to be flagged" << std::endl;
        std::cerr << "Computation target for this source variable is: ";
        switch (ct->type())
        {
        case iface::cellml_services::CONSTANT:
            std::cerr << "CONSTANT";
            break;
        case iface::cellml_services::VARIABLE_OF_INTEGRATION:
            std::cerr << "VARIABLE_OF_INTEGRATION";
            break;
        case iface::cellml_services::STATE_VARIABLE:
            std::cerr << "STATE_VARIABLE";
            break;
        case iface::cellml_services::PSEUDOSTATE_VARIABLE:
            std::cerr << "PSEUDOSTATE_VARIABLE";
            break;
        case iface::cellml_services::ALGEBRAIC:
            std::cerr << "ALGEBRAIC";
            break;
        case iface::cellml_services::LOCALLY_BOUND:
            std::cerr << "LOCALLY_BOUND";
            break;
        case iface::cellml_services::FLOATING:
            std::cerr << "FLOATING";
            break;
        default:
            std::cerr << "Invalid";
        }
        std::cerr << std::endl;
        return csim::MISMATCHED_COMPUTATION_TARGET;
    }
    variableTypes[getVariableUniqueId(sv)] = currentTypes | type;
    variableIndices[getVariableUniqueId(sv)][type] = count++;
    return variableIndices[getVariableUniqueId(sv)][type];
}
开发者ID:nickerso,项目名称:csim,代码行数:100,代码来源:cellml_model_definition.cpp

示例2: update


//.........这里部分代码省略.........
    // If the model contains some imports then we want to to go through the
    // variables defined or referenced in our main CellML file and do a mapping
    // between the source of a variable and a variable in the main CellML file
    // Note: indeed, when it comes to CellML 1.1 files, we only want to list the
    //       parameters that are either defined or referenced in our main CellML
    //       file. Not only does it make sense, but also only the parameters
    //       listed in a main CellML file can be referenced in SED-ML...

    QMap<iface::cellml_api::CellMLVariable *, iface::cellml_api::CellMLVariable *> mainVariables = QMap<iface::cellml_api::CellMLVariable *, iface::cellml_api::CellMLVariable *>();
    ObjRef<iface::cellml_api::CellMLComponentSet> localComponents = model->localComponents();
    ObjRef<iface::cellml_api::CellMLComponentIterator> localComponentsIter = localComponents->iterateComponents();

    if (hasComponentImports) {
        for (ObjRef<iface::cellml_api::CellMLComponent> component = localComponentsIter->nextComponent();
             component; component = localComponentsIter->nextComponent()) {
            ObjRef<iface::cellml_api::CellMLVariableSet> variables = component->variables();
            ObjRef<iface::cellml_api::CellMLVariableIterator> variablesIter = variables->iterateVariables();

            for (ObjRef<iface::cellml_api::CellMLVariable> variable = variablesIter->nextVariable();
                 variable; variable = variablesIter->nextVariable()) {
                ObjRef<iface::cellml_api::CellMLVariable> sourceVariable = variable->sourceVariable();

                mainVariables.insert(sourceVariable, variable);
            }
        }
    }

    // Go through all our computation targets and determine which ones are
    // referenced in our main CellML file, and sort them by component and
    // variable name

    ObjRef<iface::cellml_services::ComputationTargetIterator> computationTargetIter = genericCodeInformation->iterateTargets();

    for (ObjRef<iface::cellml_services::ComputationTarget> computationTarget = computationTargetIter->nextComputationTarget();
         computationTarget; computationTarget = computationTargetIter->nextComputationTarget()) {
        // Make sure that our computation target is defined or referenced in our
        // main CellML file, if it has imports

        ObjRef<iface::cellml_api::CellMLVariable> variable = computationTarget->variable();
        iface::cellml_api::CellMLVariable *mainVariable = mainVariables.value(variable);
        iface::cellml_api::CellMLVariable *realVariable = mainVariable?mainVariable:variable.getPointer();

        if (   hasComponentImports && !mainVariable
            &&  (computationTarget->type() != iface::cellml_services::VARIABLE_OF_INTEGRATION)) {
            continue;
        }

        // Determine the type of our computation target

        CellmlFileRuntimeParameter::ParameterType parameterType;

        switch (computationTarget->type()) {
        case iface::cellml_services::VARIABLE_OF_INTEGRATION:
            parameterType = CellmlFileRuntimeParameter::Voi;

            break;
        case iface::cellml_services::CONSTANT:
            // We are dealing with a constant, but the question is whether that
            // constant is a 'proper' constant, a 'computed' constant or even a
            // rate, and this can be determined by checking whether the computed
            // target has an initial value or even a degree
            // Note: a state variable that is initialised using the initial
            //       value of another variable will have its rate considered as
            //       a constant. However, when it comes to the GUI, we really
            //       want it to be seen as a rate hence we check for the degree
            //       of the computed target...
开发者ID:fethio,项目名称:opencor,代码行数:67,代码来源:cellmlfileruntime.cpp

示例3: instantiateCellmlApiObjects

int CellmlModelDefinition::instantiateCellmlApiObjects()
{
    try
    {
        // create an annotation set to manage our variable usages
        ObjRef<iface::cellml_services::AnnotationToolService> ats = CreateAnnotationToolService();
        ObjRef<iface::cellml_services::AnnotationSet> as = ats->createAnnotationSet();
        mCapi->annotations = as;
        // mapping the connections between variables is a very expensive operation, so we want to
        // only do it once and keep hold of the mapping (tracker item 3294)
        ObjRef<iface::cellml_services::CeVASBootstrap> cvbs = CreateCeVASBootstrap();
        ObjRef<iface::cellml_services::CeVAS> cevas = cvbs->createCeVASForModel(mCapi->model);
        std::wstring msg = cevas->modelError();
        if (msg != L"")
        {
            std::cerr << "loadModel: Error creating CellML Variable Association Service: "
                      << ws2s(msg) << std::endl;
            return -2;
        }
        mCapi->cevas = cevas;
        // now check we can generate code and grab hold of the initial code information
        ObjRef<iface::cellml_services::CodeGeneratorBootstrap> cgb = CreateCodeGeneratorBootstrap();
        ObjRef<iface::cellml_services::CodeGenerator> cg = cgb->createCodeGenerator();
        try
        {
            cg->useCeVAS(cevas);
            ObjRef<iface::cellml_services::CodeInformation> cci = cg->generateCode(mCapi->model);
            msg = cci->errorMessage();
            if (msg != L"")
            {
                std::cerr << "CellmlModelDefintion::loadModel: Error generating code: "
                          << ws2s(msg) << std::endl;
                return -4;
            }
            // TODO: we are only interested in models we can work with?
            if (cci->constraintLevel() != iface::cellml_services::CORRECTLY_CONSTRAINED)
            {
                std::cerr << "CellmlModelDefintion::loadModel: Model is not correctly constrained: "
                          << std::endl;
                return -5;
            }
            mCapi->codeInformation = cci;
            // always flag all state variables and the variable of integration
            ObjRef<iface::cellml_services::ComputationTargetIterator> cti = cci->iterateTargets();
            while (true)
            {
                ObjRef<iface::cellml_services::ComputationTarget> ct = cti->nextComputationTarget();
                if (ct == NULL) break;
                if (ct->degree() > 0) break; // only want to initialise the base variables not the differential
                ObjRef<iface::cellml_api::CellMLVariable> v(ct->variable());
                if (ct->type() == iface::cellml_services::STATE_VARIABLE)
                {
                    mVariableTypes[getVariableUniqueId(v)] = csim::StateType;
                    mVariableIndices[getVariableUniqueId(v)][csim::StateType] = mStateCounter;
                    mStateCounter++;
                }
                else if (ct->type() == iface::cellml_services::VARIABLE_OF_INTEGRATION)
                {
                    mVariableTypes[getVariableUniqueId(v)] = csim::IndependentType;
                    mNumberOfIndependentVariables++;
                }
                else
                {
                    // need to initialise the variable type
                    mVariableTypes[getVariableUniqueId(v)] = csim::UndefinedType;
                }
            }
        }
        catch (...)
        {
            std::cerr << "loadModel: Error generating the code information for the model" << std::endl;
            return -3;
        }
        // if we get to here, everything worked.
        mModelLoaded = true;
    }
    catch (...)
    {
      std::wcerr << L"Error instantiating CellML API objects." << std::endl;
      return -1;
    }
    return csim::CSIM_OK;
}
开发者ID:nickerso,项目名称:csim,代码行数:83,代码来源:cellml_model_definition.cpp


注:本文中的ObjRef::nextComputationTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。