From 6d5853e7ea95dafb5cbdd8bc63181c810b419e1f Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 6 Oct 2026 12:15:07 +1300 Subject: [PATCH 1/4] Analyser/Generator: fixed various issues with a variable initialised by another variable. --- src/analyser.cpp | 171 ++++++++++---- src/analyser_p.h | 5 + src/api/libcellml/issue.h | 1 + src/bindings/javascript/issue.cpp | 1 + src/bindings/python/__init__.py | 1 + src/generator.cpp | 213 +++++++++++++----- src/generator_p.h | 13 +- src/issue.cpp | 1 + tests/analyser/analyser.cpp | 85 +++++++ tests/bindings/python/test_issue.py | 1 + tests/generator/generator.cpp | 24 ++ tests/generator/generatorvariabletracker.cpp | 34 +++ ...ystems_sharing_initialised_variable.cellml | 77 +++++++ .../variable_initialised_using_itself.cellml | 80 +++++++ ..._using_nla_based_algebraic_variable.cellml | 62 +++++ .../cellml_unit_scaling_constant/model.c | 2 +- .../cellml_unit_scaling_constant/model.py | 2 +- .../model.c | 108 +++++++++ .../model.cellml | 65 ++++++ .../model.h | 37 +++ .../model.py | 71 ++++++ .../model.c | 155 +++++++++++++ .../model.cellml | 89 ++++++++ .../model.h | 37 +++ .../model.py | 106 +++++++++ 25 files changed, 1339 insertions(+), 102 deletions(-) create mode 100644 tests/resources/analyser/nla_systems_sharing_initialised_variable.cellml create mode 100644 tests/resources/analyser/variable_initialised_using_itself.cellml create mode 100644 tests/resources/analyser/variable_initialised_using_nla_based_algebraic_variable.cellml create mode 100644 tests/resources/generator/constant_initialised_using_computed_constant/model.c create mode 100644 tests/resources/generator/constant_initialised_using_computed_constant/model.cellml create mode 100644 tests/resources/generator/constant_initialised_using_computed_constant/model.h create mode 100644 tests/resources/generator/constant_initialised_using_computed_constant/model.py create mode 100644 tests/resources/generator/variable_initialised_using_untracked_variable/model.c create mode 100644 tests/resources/generator/variable_initialised_using_untracked_variable/model.cellml create mode 100644 tests/resources/generator/variable_initialised_using_untracked_variable/model.h create mode 100644 tests/resources/generator/variable_initialised_using_untracked_variable/model.py diff --git a/src/analyser.cpp b/src/analyser.cpp index 1c3594e124..b45fae2ec3 100644 --- a/src/analyser.cpp +++ b/src/analyser.cpp @@ -2314,6 +2314,55 @@ void Analyser::AnalyserImpl::addInvalidVariableIssue(const AnalyserInternalVaria addIssue(issue); } +AnalyserInternalVariablePtrs Analyser::AnalyserImpl::initialisationDependencies(const AnalyserInternalVariablePtr &internalVariable) +{ + // Return the internal variables on which the initialisation of the given internal variable depends, i.e. the + // internal variable used to initialise it, if it is initialised using a variable, or the internal variables used + // to compute it, if it is a computed constant. + + AnalyserInternalVariablePtrs res; + + if ((internalVariable->mInitialisingVariable != nullptr) + && !isCellMLReal(internalVariable->mInitialisingVariable->initialValue())) { + res.push_back(Analyser::AnalyserImpl::internalVariable(owningComponent(internalVariable->mInitialisingVariable)->variable(internalVariable->mInitialisingVariable->initialValue()))); + } + + for (const auto &internalEquation : mInternalEquations) { + if ((internalEquation->mType == AnalyserInternalEquation::Type::COMPUTED_CONSTANT) + && (internalEquation->mUnknownVariables.front() == internalVariable)) { + for (const auto &dependency : internalEquation->mDependencies) { + res.push_back(Analyser::AnalyserImpl::internalVariable(dependency)); + } + } + } + + return res; +} + +bool Analyser::AnalyserImpl::initialisationDependsOn(const AnalyserInternalVariablePtr &internalVariable, + const AnalyserInternalVariablePtr &otherInternalVariable, + AnalyserInternalVariablePtrs &checkedInternalVariables) +{ + // Determine whether the initialisation of the given internal variable depends, directly or indirectly, on the other + // internal variable. + + for (const auto &dependency : initialisationDependencies(internalVariable)) { + if (dependency == otherInternalVariable) { + return true; + } + + if (std::find(checkedInternalVariables.begin(), checkedInternalVariables.end(), dependency) == checkedInternalVariables.end()) { + checkedInternalVariables.push_back(dependency); + + if (initialisationDependsOn(dependency, otherInternalVariable, checkedInternalVariables)) { + return true; + } + } + } + + return false; +} + void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) { // Reset a few things in case this analyser was to be used to analyse more @@ -2613,35 +2662,6 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) return; } - // Make sure that variables that are initialised using another variable are - // not initialised using an algebraic variable. - - for (const auto &internalVariable : mInternalVariables) { - if ((internalVariable->mInitialisingVariable != nullptr) - && !isCellMLReal(internalVariable->mInitialisingVariable->initialValue())) { - auto initialisingInternalVariable = Analyser::AnalyserImpl::internalVariable(owningComponent(internalVariable->mInitialisingVariable)->variable(internalVariable->mInitialisingVariable->initialValue())); - - if (initialisingInternalVariable->mType == AnalyserInternalVariable::Type::ALGEBRAIC_VARIABLE) { - auto issue = Issue::IssueImpl::create(); - - issue->mPimpl->setDescription("Variable '" + internalVariable->mVariable->name() - + "' in component '" + owningComponent(internalVariable->mVariable)->name() - + "' is initialised using variable '" + initialisingInternalVariable->mVariable->name() - + "', which is an algebraic variable. Only a reference to a constant, a computed constant, a state variable, or a computable non-linear algebraic variable is allowed."); - issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE); - issue->mPimpl->mItem->mPimpl->setVariable(internalVariable->mVariable); - - addIssue(issue); - } - } - } - - if (mAnalyser->errorCount() != 0) { - mAnalyserModel->mPimpl->mType = AnalyserModel::Type::INVALID; - - return; - } - // Make sure that our equations are valid. AnalyserInternalVariablePtrs addedExternalVariables; @@ -2769,18 +2789,40 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) } } } break; - case AnalyserInternalEquation::Type::NLA: - if (internalEquation->mNlaSiblings.size() + 1 < internalEquation->mUnknownVariables.size()) { + case AnalyserInternalEquation::Type::NLA: { + // Determine the number of NLA equations and the unknown variables of the NLA system as a whole. + // Note: the unknown variables of an NLA equation are not necessarily the same as those of its NLA siblings + // (e.g., x and y for one NLA equation, and x and z for its NLA sibling, i.e. two NLA equations for + // three unknown variables), so checking an NLA equation on its own is not enough. + + size_t nlaEquationCount = 0; + AnalyserInternalVariablePtrs nlaUnknownVariables; + + for (const auto &otherInternalEquation : mInternalEquations) { + if ((otherInternalEquation->mType == AnalyserInternalEquation::Type::NLA) + && (otherInternalEquation->mNlaSystemIndex == internalEquation->mNlaSystemIndex)) { + ++nlaEquationCount; + + for (const auto &unknownVariable : otherInternalEquation->mUnknownVariables) { + if (std::find(nlaUnknownVariables.begin(), nlaUnknownVariables.end(), unknownVariable) == nlaUnknownVariables.end()) { + nlaUnknownVariables.push_back(unknownVariable); + } + } + } + } + + if ((internalEquation->mNlaSiblings.size() + 1 < internalEquation->mUnknownVariables.size()) + || (nlaEquationCount < nlaUnknownVariables.size())) { // There are fewer NLA equations than unknown variables, so all the unknown variables involved in the // NLA system should be considered as underconstrained. - for (const auto &unknownVariable : internalEquation->mUnknownVariables) { - if (std::find(underconstrainedVariables.begin(), underconstrainedVariables.end(), unknownVariable) == underconstrainedVariables.end()) { - unknownVariable->mType = AnalyserInternalVariable::Type::UNDERCONSTRAINED; + for (const auto &nlaUnknownVariable : nlaUnknownVariables) { + if (std::find(underconstrainedVariables.begin(), underconstrainedVariables.end(), nlaUnknownVariable) == underconstrainedVariables.end()) { + nlaUnknownVariable->mType = AnalyserInternalVariable::Type::UNDERCONSTRAINED; - addInvalidVariableIssue(unknownVariable, Issue::ReferenceRule::ANALYSER_VARIABLE_UNDERCONSTRAINED); + addInvalidVariableIssue(nlaUnknownVariable, Issue::ReferenceRule::ANALYSER_VARIABLE_UNDERCONSTRAINED); - underconstrainedVariables.push_back(unknownVariable); + underconstrainedVariables.push_back(nlaUnknownVariable); } } } else if (internalEquation->mNlaSiblings.size() + 1 > internalEquation->mUnknownVariables.size()) { @@ -2797,8 +2839,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) } } } - - break; + } break; default: // Other types we don't care about. break; } @@ -2818,6 +2859,60 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) return; } + // Make sure that variables that are initialised using another variable are neither initialised using an algebraic + // variable nor, directly or indirectly, initialised using themselves. + // Note: this can only be done now since a variable-based constant may have been requalified as an algebraic + // variable (see above). + + for (const auto &internalVariable : mInternalVariables) { + if ((internalVariable->mInitialisingVariable != nullptr) + && !isCellMLReal(internalVariable->mInitialisingVariable->initialValue())) { + auto initialisingInternalVariable = Analyser::AnalyserImpl::internalVariable(owningComponent(internalVariable->mInitialisingVariable)->variable(internalVariable->mInitialisingVariable->initialValue())); + + if (initialisingInternalVariable->mType == AnalyserInternalVariable::Type::ALGEBRAIC_VARIABLE) { + // The variable is initialised using an algebraic variable, which is not allowed. + + auto issue = Issue::IssueImpl::create(); + + issue->mPimpl->setDescription("Variable '" + internalVariable->mVariable->name() + + "' in component '" + owningComponent(internalVariable->mVariable)->name() + + "' is initialised using variable '" + initialisingInternalVariable->mVariable->name() + + "', which is an algebraic variable. Only a reference to a constant, a computed constant, a state variable, or a computable non-linear algebraic variable is allowed."); + issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE); + issue->mPimpl->mItem->mPimpl->setVariable(internalVariable->mVariable); + + addIssue(issue); + } else { + AnalyserInternalVariablePtrs checkedInternalVariables; + + if (initialisationDependsOn(internalVariable, internalVariable, checkedInternalVariables)) { + // The variable is initialised using itself, directly or indirectly, which is not allowed. + + auto initialisingVariable = internalVariable->mInitialisingVariable; + auto initialValue = initialisingVariable->initialValue(); + auto issue = Issue::IssueImpl::create(); + + issue->mPimpl->setDescription("Variable '" + initialisingVariable->name() + + "' in component '" + owningComponent(initialisingVariable)->name() + + "' is initialised using " + + ((initialValue == initialisingVariable->name()) ? + "itself." : + "variable '" + initialValue + "', which depends, directly or indirectly, on variable '" + initialisingVariable->name() + "'.")); + issue->mPimpl->setReferenceRule(Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ITSELF); + issue->mPimpl->mItem->mPimpl->setVariable(initialisingVariable); + + addIssue(issue); + } + } + } + } + + if (mAnalyser->errorCount() != 0) { + mAnalyserModel->mPimpl->mType = AnalyserModel::Type::INVALID; + + return; + } + // Determine the type of our model. auto hasNlaEquations = std::any_of(mInternalEquations.begin(), mInternalEquations.end(), [=](const auto &ie) { diff --git a/src/analyser_p.h b/src/analyser_p.h index 2b821f2b86..91c9ec5062 100644 --- a/src/analyser_p.h +++ b/src/analyser_p.h @@ -257,6 +257,11 @@ class Analyser::AnalyserImpl: public Logger::LoggerImpl void addInvalidVariableIssue(const AnalyserInternalVariablePtr &variable, Issue::ReferenceRule referenceRule); + AnalyserInternalVariablePtrs initialisationDependencies(const AnalyserInternalVariablePtr &internalVariable); + bool initialisationDependsOn(const AnalyserInternalVariablePtr &internalVariable, + const AnalyserInternalVariablePtr &otherInternalVariable, + AnalyserInternalVariablePtrs &checkedInternalVariables); + void analyseModel(const ModelPtr &model); AnalyserExternalVariablePtrs::const_iterator findExternalVariable(const VariablePtr &variable) const; diff --git a/src/api/libcellml/issue.h b/src/api/libcellml/issue.h index 51d5bf41f1..56ee280deb 100644 --- a/src/api/libcellml/issue.h +++ b/src/api/libcellml/issue.h @@ -193,6 +193,7 @@ class LIBCELLML_EXPORT Issue ANALYSER_UNLINKED_UNITS, ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE, ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE, + ANALYSER_VARIABLE_INITIALISED_USING_ITSELF, ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS, ANALYSER_VOI_INITIALISED, ANALYSER_VOI_SEVERAL, diff --git a/src/bindings/javascript/issue.cpp b/src/bindings/javascript/issue.cpp index b21279ee3e..d4d9e7629f 100644 --- a/src/bindings/javascript/issue.cpp +++ b/src/bindings/javascript/issue.cpp @@ -43,6 +43,7 @@ EMSCRIPTEN_BINDINGS(libcellml_issue) { .value("ANALYSER_VARIABLE_OVERCONSTRAINED", libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_OVERCONSTRAINED) .value("ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE", libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE) .value("ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE", libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE) + .value("ANALYSER_VARIABLE_INITIALISED_USING_ITSELF", libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ITSELF) .value("ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS", libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS) .value("ANALYSER_VARIABLE_UNUSED", libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_UNUSED) .value("ANALYSER_VOI_INITIALISED", libcellml::Issue::ReferenceRule::ANALYSER_VOI_INITIALISED) diff --git a/src/bindings/python/__init__.py b/src/bindings/python/__init__.py index 1ccbbe13e1..eff4083542 100644 --- a/src/bindings/python/__init__.py +++ b/src/bindings/python/__init__.py @@ -312,6 +312,7 @@ class Object: 'ANALYSER_UNLINKED_UNITS', 'ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE', 'ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE', + 'ANALYSER_VARIABLE_INITIALISED_USING_ITSELF', 'ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS', 'ANALYSER_VOI_INITIALISED', 'ANALYSER_VOI_SEVERAL', diff --git a/src/generator.cpp b/src/generator.cpp index 4a4ecc2ec4..a67ba3e87d 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -107,23 +107,24 @@ bool Generator::GeneratorImpl::modelHasOdes(const AnalyserModelPtr &analyserMode double Generator::GeneratorImpl::scalingFactor(const AnalyserModelPtr &analyserModel, const VariablePtr &variable) const { - // Return the scaling factor for the given variable, accounting for the fact that a constant may be initialised by - // another variable which initial value may be defined in a different component. + // Return the scaling factor for the given (initialising) variable, accounting for the fact that it may be + // initialised using another variable which value may be held by a variable in a different component. + // Note: scaling is only performed at the connection level, i.e. between the given variable and the variable held + // by its analyser variable, and between the initial value variable and the variable held by its analyser + // variable. In other words, there is no scaling between the given variable and its initial value variable + // since they are in the same component (the analyser warns about them having different units). auto analyserVariable = analyserModel->analyserVariable(variable); + auto res = Units::scalingFactor(analyserVariable->variable()->units(), variable->units()); - if ((analyserVariable->type() == AnalyserVariable::Type::CONSTANT) - && !isCellMLReal(variable->initialValue())) { - auto variableComponent = owningComponent(variable); - auto initialValueVariable = variableComponent->variable(variable->initialValue()); + if (!isCellMLReal(variable->initialValue())) { + auto initialValueVariable = owningComponent(variable)->variable(variable->initialValue()); auto initialValueAnalyserVariable = analyserModel->analyserVariable(initialValueVariable); - if (variableComponent != owningComponent(initialValueAnalyserVariable->variable())) { - return Units::scalingFactor(initialValueVariable->units(), variable->units()); - } + res *= Units::scalingFactor(initialValueVariable->units(), initialValueAnalyserVariable->variable()->units()); } - return Units::scalingFactor(analyserVariable->variable()->units(), variable->units()); + return res; } bool Generator::GeneratorImpl::isNegativeNumber(const AnalyserEquationAstPtr &ast) const @@ -792,16 +793,22 @@ void Generator::GeneratorImpl::addNlaSystemsCode() auto methodBodySize = methodBody.size(); - for (const auto &constantDependency : analyserEquation->mPimpl->mConstantDependencies) { - if (isTrackedVariable(constantDependency, false)) { - methodBody += generateInitialisationCode(constantDependency, true); - } - } - std::vector dummyRemainingAnalyserEquations = mAnalyserModel->analyserEquations(); std::vector dummyAnalyserEquationsForDependencies; std::vector dummyGeneratedConstantDependencies; + for (const auto &constantDependency : analyserEquation->mPimpl->mConstantDependencies) { + if (isTrackedVariable(constantDependency, false) + && (std::find(dummyGeneratedConstantDependencies.begin(), dummyGeneratedConstantDependencies.end(), constantDependency) == dummyGeneratedConstantDependencies.end())) { + methodBody += generateInitialisationCode(constantDependency, + dummyRemainingAnalyserEquations, dummyAnalyserEquationsForDependencies, + dummyGeneratedConstantDependencies, false, + GenerateEquationCodeTarget::OBJECTIVE_FUNCTION, true); + + dummyGeneratedConstantDependencies.push_back(constantDependency); + } + } + for (const auto &dependency : analyserEquation->dependencies()) { if (((dependency->type() == AnalyserEquation::Type::COMPUTED_CONSTANT) || (dependency->type() == AnalyserEquation::Type::ALGEBRAIC)) @@ -929,30 +936,7 @@ std::string Generator::GeneratorImpl::generateDoubleOrVariableNameCode(const Var return generateDoubleCode(variable->initialValue()); } - auto initialValueVariable = owningComponent(variable)->variable(variable->initialValue()); - auto initialValueAnalyserVariable = mAnalyserModel->analyserVariable(initialValueVariable); - std::string arrayName; - - switch (initialValueAnalyserVariable->type()) { - case AnalyserVariable::Type::STATE: - arrayName = mProfile->statesArrayString(); - - break; - case AnalyserVariable::Type::CONSTANT: - arrayName = mProfile->constantsArrayString(); - - break; - case AnalyserVariable::Type::COMPUTED_CONSTANT: - arrayName = mProfile->computedConstantsArrayString(); - - break; - default: // If it is not one of the above types then it has to be an algebraic variable. - arrayName = mProfile->algebraicVariablesArrayString(); - - break; - } - - return arrayName + mProfile->openArrayString() + analyserVariableIndexString(initialValueAnalyserVariable) + mProfile->closeArrayString(); + return generateVariableNameCode(owningComponent(variable)->variable(variable->initialValue())); } std::string Generator::GeneratorImpl::generateVariableNameCode(const VariablePtr &variable, bool state) @@ -1768,13 +1752,45 @@ std::string Generator::GeneratorImpl::generateZeroInitialisationCode(const Analy + mProfile->commandSeparatorString() + "\n"; } -std::string Generator::GeneratorImpl::generateInitialisationCode(const AnalyserVariablePtr &analyserVariable, bool force) +std::string Generator::GeneratorImpl::generateInitialisationCode(const AnalyserVariablePtr &analyserVariable, + std::vector &remainingAnalyserEquations, + std::vector &analyserEquationsForDependencies, + std::vector &generatedConstantDependencies, + bool includeComputedConstants, + GenerateEquationCodeTarget target, + bool force) { if (!force && isTrackedVariable(analyserVariable, false)) { return {}; } + // If the analyser variable is initialised using an untracked variable (i.e. a constant or a computed constant) then + // generate some code for that untracked variable first since it needs to be declared before it can be used. + + std::string res; auto initialisingVariable = analyserVariable->initialisingVariable(); + + if (!isCellMLReal(initialisingVariable->initialValue())) { + auto initialValueAnalyserVariable = mAnalyserModel->analyserVariable(owningComponent(initialisingVariable)->variable(initialisingVariable->initialValue())); + + if (isTrackedVariable(initialValueAnalyserVariable, false)) { + if (initialValueAnalyserVariable->type() == AnalyserVariable::Type::CONSTANT) { + if (std::find(generatedConstantDependencies.begin(), generatedConstantDependencies.end(), initialValueAnalyserVariable) == generatedConstantDependencies.end()) { + res += generateInitialisationCode(initialValueAnalyserVariable, + remainingAnalyserEquations, analyserEquationsForDependencies, + generatedConstantDependencies, includeComputedConstants, target, + true); + + generatedConstantDependencies.push_back(initialValueAnalyserVariable); + } + } else { // AnalyserVariable::Type::COMPUTED_CONSTANT. + res += generateEquationCode(initialValueAnalyserVariable->analyserEquation(0), + remainingAnalyserEquations, analyserEquationsForDependencies, + generatedConstantDependencies, includeComputedConstants, target); + } + } + } + auto scalingFactor = Generator::GeneratorImpl::scalingFactor(mAnalyserModel, initialisingVariable); std::string scalingFactorCode; @@ -1791,7 +1807,8 @@ std::string Generator::GeneratorImpl::generateInitialisationCode(const AnalyserV code = replace(mProfile->variableDeclarationString(), "[CODE]", code); } - return mProfile->indentString() + return res + + mProfile->indentString() + code; } @@ -1822,7 +1839,9 @@ std::string Generator::GeneratorImpl::generateEquationCode(const AnalyserEquatio if ((analyserEquation->type() != AnalyserEquation::Type::NLA) && isTrackedVariable(constantDependency, false) && (std::find(generatedConstantDependencies.begin(), generatedConstantDependencies.end(), constantDependency) == generatedConstantDependencies.end())) { - res += generateInitialisationCode(constantDependency, true); + res += generateInitialisationCode(constantDependency, remainingAnalyserEquations, + analyserEquationsForDependencies, generatedConstantDependencies, + includeComputedConstants, target, true); generatedConstantDependencies.push_back(constantDependency); } @@ -1912,13 +1931,31 @@ bool Generator::GeneratorImpl::hasComputedConstantDependency(const AnalyserVaria return hasComputedConstantDependency(mAnalyserModel->analyserVariable(initialValueVariable)); } +void Generator::GeneratorImpl::computedConstantConstantDependencies(const AnalyserEquationPtr &analyserEquation, + std::vector &constantDependencies) +{ + // Retrieve the constants on which the given computed constant equation depends, either directly or through the + // computed constants on which it depends. + + for (const auto &constantDependency : analyserEquation->mPimpl->mConstantDependencies) { + constantDependencies.push_back(constantDependency); + } + + for (const auto &dependency : analyserEquation->dependencies()) { + if (dependency->type() == AnalyserEquation::Type::COMPUTED_CONSTANT) { + computedConstantConstantDependencies(dependency, constantDependencies); + } + } +} + std::string Generator::GeneratorImpl::generateInitialiseVariableCode(const AnalyserVariablePtr &analyserVariable, std::vector &remainingAnalyserEquations, std::vector &remainingStates, std::vector &remainingConstants, std::vector &remainingComputedConstants, std::vector &remainingAlgebraicVariables, - std::vector *generatedConstantDependencies) + std::vector &generatedConstantDependencies, + bool computedConstantsAvailable) { std::string res; @@ -1941,8 +1978,7 @@ std::string Generator::GeneratorImpl::generateInitialiseVariableCode(const Analy remainingComputedConstants : remainingAlgebraicVariables; - if (((generatedConstantDependencies == nullptr) && !hasComputedConstantDependency(initialValueAnalyserVariable)) - || (generatedConstantDependencies != nullptr)) { + if (computedConstantsAvailable || !hasComputedConstantDependency(initialValueAnalyserVariable)) { auto initialisingAnalyserVariable = std::find_if(remainingVariables.begin(), remainingVariables.end(), [&](const AnalyserVariablePtr &av) { return mAnalyserModel->areEquivalentVariables(initialValueVariable, av->variable()); @@ -1952,13 +1988,32 @@ std::string Generator::GeneratorImpl::generateInitialiseVariableCode(const Analy res += generateInitialiseVariableCode(AnalyserVariablePtr(*initialisingAnalyserVariable), remainingAnalyserEquations, remainingStates, remainingConstants, remainingComputedConstants, remainingAlgebraicVariables, - generatedConstantDependencies); + generatedConstantDependencies, computedConstantsAvailable); } } else { initialiseAnalyserVariable = false; } } + // A computed constant may depend on some constants that are initialised using a computed constant, i.e. constants + // that could not be initialised in initialiseArrays(), so initialise them first. + + if ((analyserVariable->type() == AnalyserVariable::Type::COMPUTED_CONSTANT) + && (std::find(remainingComputedConstants.begin(), remainingComputedConstants.end(), analyserVariable) != remainingComputedConstants.end())) { + std::vector constantDependencies; + + computedConstantConstantDependencies(analyserVariable->analyserEquation(0), constantDependencies); + + for (const auto &constantDependency : constantDependencies) { + if (std::find(remainingConstants.begin(), remainingConstants.end(), constantDependency) != remainingConstants.end()) { + res += generateInitialiseVariableCode(constantDependency, + remainingAnalyserEquations, remainingStates, remainingConstants, + remainingComputedConstants, remainingAlgebraicVariables, + generatedConstantDependencies, computedConstantsAvailable); + } + } + } + // Now initialise the analyser variable itself, if we can. if (initialiseAnalyserVariable) { @@ -1973,9 +2028,13 @@ std::string Generator::GeneratorImpl::generateInitialiseVariableCode(const Analy if (remainingVariable != remainingVariables.end()) { if (remainingVariables != remainingComputedConstants) { - res += generateInitialisationCode(AnalyserVariablePtr(*remainingVariable)); + std::vector dummyAnalyserEquationsForDependencies; + + res += generateInitialisationCode(AnalyserVariablePtr(*remainingVariable), + remainingAnalyserEquations, dummyAnalyserEquationsForDependencies, + generatedConstantDependencies, true, GenerateEquationCodeTarget::NORMAL); } else { - res += generateEquationCode(analyserVariable->analyserEquation(0), remainingAnalyserEquations, *generatedConstantDependencies); + res += generateEquationCode(analyserVariable->analyserEquation(0), remainingAnalyserEquations, generatedConstantDependencies); } remainingVariables.erase(remainingVariable); @@ -2031,11 +2090,13 @@ void Generator::GeneratorImpl::addImplementationInitialiseArraysMethodCode(std:: // Initialise our states. std::string methodBody; + std::vector generatedConstantDependencies; for (const auto &state : mAnalyserModel->states()) { methodBody += generateInitialiseVariableCode(state, remainingAnalyserEquations, remainingStates, remainingConstants, - remainingComputedConstants, remainingAlgebraicVariables); + remainingComputedConstants, remainingAlgebraicVariables, + generatedConstantDependencies, false); } // Use an initial guess of zero for rates computed using an NLA system (see the note below). @@ -2046,19 +2107,19 @@ void Generator::GeneratorImpl::addImplementationInitialiseArraysMethodCode(std:: } } - // Initialise our remaining constants. + // Initialise our remaining constants, except those that are initialised using a computed constant (they will be + // initialised in computeComputedConstants()). - while (!remainingConstants.empty()) { - methodBody += generateInitialiseVariableCode(AnalyserVariablePtr(*remainingConstants.begin()), + for (const auto &constant : mAnalyserModel->constants()) { + methodBody += generateInitialiseVariableCode(constant, remainingAnalyserEquations, remainingStates, remainingConstants, - remainingComputedConstants, remainingAlgebraicVariables); + remainingComputedConstants, remainingAlgebraicVariables, + generatedConstantDependencies, false); } // Initialise our computed constants that are initialised using an equation (e.g., x = 3 rather than x with an // initial value of 3). - std::vector generatedConstantDependencies; - for (const auto &equation : mAnalyserModel->analyserEquations()) { if (equation->type() == AnalyserEquation::Type::CONSTANT) { methodBody += generateEquationCode(equation, remainingAnalyserEquations, generatedConstantDependencies); @@ -2076,7 +2137,8 @@ void Generator::GeneratorImpl::addImplementationInitialiseArraysMethodCode(std:: if (algebraicVariable->initialisingVariable() != nullptr) { methodBody += generateInitialiseVariableCode(algebraicVariable, remainingAnalyserEquations, remainingStates, remainingConstants, - remainingComputedConstants, remainingAlgebraicVariables); + remainingComputedConstants, remainingAlgebraicVariables, + generatedConstantDependencies, false); } else if (algebraicVariable->analyserEquation(0)->type() == AnalyserEquation::Type::NLA) { methodBody += generateZeroInitialisationCode(algebraicVariable); } @@ -2100,6 +2162,20 @@ void Generator::GeneratorImpl::addImplementationComputeComputedConstantsMethodCo std::vector &remainingAlgebraicVariables) { if (!mProfile->implementationComputeComputedConstantsMethodString(modelHasOdes(mAnalyserModel)).empty()) { + // Keep track of our untracked computed constant equations. + // Note: some of them may be generated here (e.g., to compute an untracked computed constant that is used to + // initialise a state), but the code is local to this method, so they must remain available to the other + // methods (see below). + + std::vector untrackedAnalyserEquations; + + for (const auto &analyserEquation : remainingAnalyserEquations) { + if ((analyserEquation->type() == AnalyserEquation::Type::COMPUTED_CONSTANT) + && isTrackedEquation(analyserEquation, false)) { + untrackedAnalyserEquations.push_back(analyserEquation); + } + } + // Initialise our remaining states (which are initialised using a computed constant). std::string methodBody; @@ -2109,7 +2185,16 @@ void Generator::GeneratorImpl::addImplementationComputeComputedConstantsMethodCo methodBody += generateInitialiseVariableCode(state, remainingAnalyserEquations, remainingStates, remainingConstants, remainingComputedConstants, remainingAlgebraicVariables, - &generatedConstantDependencies); + generatedConstantDependencies, true); + } + + // Initialise our remaining constants (which are initialised using a computed constant). + + for (const auto &constant : mAnalyserModel->constants()) { + methodBody += generateInitialiseVariableCode(constant, + remainingAnalyserEquations, remainingStates, remainingConstants, + remainingComputedConstants, remainingAlgebraicVariables, + generatedConstantDependencies, true); } // Initialise our remaining computed constants. @@ -2120,7 +2205,7 @@ void Generator::GeneratorImpl::addImplementationComputeComputedConstantsMethodCo methodBody += generateInitialiseVariableCode(analyserEquation->computedConstant(0), remainingAnalyserEquations, remainingStates, remainingConstants, remainingComputedConstants, remainingAlgebraicVariables, - &generatedConstantDependencies); + generatedConstantDependencies, true); } } @@ -2131,7 +2216,15 @@ void Generator::GeneratorImpl::addImplementationComputeComputedConstantsMethodCo methodBody += generateInitialiseVariableCode(algebraicVariable, remainingAnalyserEquations, remainingStates, remainingConstants, remainingComputedConstants, remainingAlgebraicVariables, - &generatedConstantDependencies); + generatedConstantDependencies, true); + } + } + + // Make our untracked computed constant equations available to the other methods. + + for (const auto &untrackedAnalyserEquation : untrackedAnalyserEquations) { + if (std::find(remainingAnalyserEquations.begin(), remainingAnalyserEquations.end(), untrackedAnalyserEquation) == remainingAnalyserEquations.end()) { + remainingAnalyserEquations.push_back(untrackedAnalyserEquation); } } diff --git a/src/generator_p.h b/src/generator_p.h index 5c1a3f642a..753cb86a78 100644 --- a/src/generator_p.h +++ b/src/generator_p.h @@ -136,7 +136,13 @@ struct Generator::GeneratorImpl: public Logger::LoggerImpl }; std::string generateZeroInitialisationCode(const AnalyserVariablePtr &analyserVariable); - std::string generateInitialisationCode(const AnalyserVariablePtr &analyserVariable, bool force = false); + std::string generateInitialisationCode(const AnalyserVariablePtr &analyserVariable, + std::vector &remainingAnalyserEquations, + std::vector &analyserEquationsForDependencies, + std::vector &generatedConstantDependencies, + bool includeComputedConstants, + GenerateEquationCodeTarget target, + bool force = false); std::string generateEquationCode(const AnalyserEquationPtr &analyserEquation, std::vector &remainingAnalyserEquations, std::vector &analyserEquationsForDependencies, @@ -147,13 +153,16 @@ struct Generator::GeneratorImpl: public Logger::LoggerImpl std::vector &remainingAnalyserEquations, std::vector &generatedConstantDependencies); bool hasComputedConstantDependency(const AnalyserVariablePtr &analyserVariable); + void computedConstantConstantDependencies(const AnalyserEquationPtr &analyserEquation, + std::vector &constantDependencies); std::string generateInitialiseVariableCode(const AnalyserVariablePtr &analyserVariable, std::vector &remainingAnalyserEquations, std::vector &remainingStates, std::vector &remainingConstants, std::vector &remainingComputedConstants, std::vector &remainingAlgebraicVariables, - std::vector *generatedConstantDependencies = nullptr); + std::vector &generatedConstantDependencies, + bool computedConstantsAvailable); void addInterfaceComputeModelMethodsCode(); void addImplementationInitialiseArraysMethodCode(std::vector &remainingAnalyserEquations, diff --git a/src/issue.cpp b/src/issue.cpp index da64bd978e..cdcfe8a3ca 100644 --- a/src/issue.cpp +++ b/src/issue.cpp @@ -203,6 +203,7 @@ static const std::map> ruleToInfo {Issue::ReferenceRule::ANALYSER_UNLINKED_UNITS, {"ANALYSER_UNLINKED_UNITS", "", docsUrl, ""}}, {Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE, {"ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE", "", docsUrl, ""}}, {Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE, {"ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE", "", docsUrl, ""}}, + {Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ITSELF, {"ANALYSER_VARIABLE_INITIALISED_USING_ITSELF", "", docsUrl, ""}}, {Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS, {"ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS", "", docsUrl, ""}}, {Issue::ReferenceRule::ANALYSER_VOI_INITIALISED, {"ANALYSER_VOI_INITIALISED", "", docsUrl, ""}}, {Issue::ReferenceRule::ANALYSER_VOI_SEVERAL, {"ANALYSER_VOI_SEVERAL", "", docsUrl, ""}}, diff --git a/tests/analyser/analyser.cpp b/tests/analyser/analyser.cpp index ecc9db714b..7473357235 100644 --- a/tests/analyser/analyser.cpp +++ b/tests/analyser/analyser.cpp @@ -294,6 +294,64 @@ TEST(Analyser, variableInitialisedUsingAnotherVariable) EXPECT_EQ(libcellml::AnalyserModel::Type::INVALID, analyser->analyserModel()->type()); } +TEST(Analyser, variableInitialisedUsingNlaBasedAlgebraicVariable) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("analyser/variable_initialised_using_nla_based_algebraic_variable.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + const std::vector expectedIssues = { + "Variable 'b' in component 'main' is initialised using variable 'cc', which is an algebraic variable. Only a reference to a constant, a computed constant, a state variable, or a computable non-linear algebraic variable is allowed.", + }; + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ_ISSUES_CELLMLELEMENTTYPES_LEVELS_REFERENCERULES_URLS(expectedIssues, + expectedCellmlElementTypes(expectedIssues.size(), libcellml::CellmlElementType::VARIABLE), + expectedLevels(expectedIssues.size(), libcellml::Issue::Level::ERROR), + expectedReferenceRules(expectedIssues.size(), libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE), + expectedUrls(expectedIssues.size(), "https://libcellml.org/documentation/guides/latest/runtime_codes/index?issue=ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE"), + analyser); + + EXPECT_EQ(libcellml::AnalyserModel::Type::INVALID, analyser->analyserModel()->type()); +} + +TEST(Analyser, variableInitialisedUsingItself) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("analyser/variable_initialised_using_itself.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + const std::vector expectedIssues = { + "Variable 'kc' in component 'main' is initialised using variable 'cc', which depends, directly or indirectly, on variable 'kc'.", + "Variable 'f' in component 'main' is initialised using variable 'd', which depends, directly or indirectly, on variable 'f'.", + "Variable 'e' in component 'main' is initialised using variable 'f', which depends, directly or indirectly, on variable 'e'.", + "Variable 'd' in component 'main' is initialised using variable 'e', which depends, directly or indirectly, on variable 'd'.", + "Variable 'c' in component 'main' is initialised using variable 'b', which depends, directly or indirectly, on variable 'c'.", + "Variable 'b' in component 'main' is initialised using variable 'c', which depends, directly or indirectly, on variable 'b'.", + "Variable 'a' in component 'main' is initialised using itself.", + "Variable 'y' in component 'main' is initialised using variable 'z', which depends, directly or indirectly, on variable 'y'.", + "Variable 'z' in component 'main' is initialised using variable 'y', which depends, directly or indirectly, on variable 'z'.", + }; + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ_ISSUES_CELLMLELEMENTTYPES_LEVELS_REFERENCERULES_URLS(expectedIssues, + expectedCellmlElementTypes(expectedIssues.size(), libcellml::CellmlElementType::VARIABLE), + expectedLevels(expectedIssues.size(), libcellml::Issue::Level::ERROR), + expectedReferenceRules(expectedIssues.size(), libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_INITIALISED_USING_ITSELF), + expectedUrls(expectedIssues.size(), "https://libcellml.org/documentation/guides/latest/runtime_codes/index?issue=ANALYSER_VARIABLE_INITIALISED_USING_ITSELF"), + analyser); + + EXPECT_EQ(libcellml::AnalyserModel::Type::INVALID, analyser->analyserModel()->type()); +} + TEST(Analyser, nonInitialisedState) { auto parser = libcellml::Parser::create(); @@ -987,6 +1045,33 @@ TEST(Analyser, underconstrainedNlaSystem) EXPECT_EQ(libcellml::AnalyserModel::Type::UNDERCONSTRAINED, analyser->analyserModel()->type()); } +TEST(Analyser, nlaSystemsSharingInitialisedVariable) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("analyser/nla_systems_sharing_initialised_variable.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + const std::vector expectedIssues = { + "Variable 'k' in component 'main' is underconstrained.", + "Variable 'a' in component 'main' is underconstrained.", + "Variable 'd' in component 'main' is underconstrained.", + }; + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ_ISSUES_CELLMLELEMENTTYPES_LEVELS_REFERENCERULES_URLS(expectedIssues, + expectedCellmlElementTypes(expectedIssues.size(), libcellml::CellmlElementType::VARIABLE), + expectedLevels(expectedIssues.size(), libcellml::Issue::Level::ERROR), + expectedReferenceRules(expectedIssues.size(), libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_UNDERCONSTRAINED), + expectedUrls(expectedIssues.size(), "https://libcellml.org/documentation/guides/latest/runtime_codes/index?issue=ANALYSER_VARIABLE_UNDERCONSTRAINED"), + analyser); + + EXPECT_EQ(libcellml::AnalyserModel::Type::UNDERCONSTRAINED, analyser->analyserModel()->type()); +} + TEST(Analyser, overconstrainedNlaSystem) { auto parser = libcellml::Parser::create(); diff --git a/tests/bindings/python/test_issue.py b/tests/bindings/python/test_issue.py index 940cba285c..3c01b7078b 100644 --- a/tests/bindings/python/test_issue.py +++ b/tests/bindings/python/test_issue.py @@ -38,6 +38,7 @@ def test_reference_rule_enum(self): self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VARIABLE_OVERCONSTRAINED, int) self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VARIABLE_INITIALISED_MORE_THAN_ONCE, int) self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VARIABLE_INITIALISED_USING_ALGEBRAIC_VARIABLE, int) + self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VARIABLE_INITIALISED_USING_ITSELF, int) self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VARIABLE_INITIALISED_USING_VARIABLE_WITH_DIFFERENT_UNITS, int) self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VARIABLE_UNUSED, int) self.assertIsInstance(Issue.ReferenceRule.ANALYSER_VOI_INITIALISED, int) diff --git a/tests/generator/generator.cpp b/tests/generator/generator.cpp index 13af89e313..8b65c381df 100644 --- a/tests/generator/generator.cpp +++ b/tests/generator/generator.cpp @@ -1652,6 +1652,30 @@ TEST(Generator, variableInitialisedUsingAnotherVariable) EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_another_variable/model.py", generator->implementationCode(analyserModel, profile)); } +TEST(Generator, constantInitialisedUsingComputedConstant) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("generator/constant_initialised_using_computed_constant/model.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ(size_t(0), analyser->errorCount()); + + auto analyserModel = analyser->analyserModel(); + auto generator = libcellml::Generator::create(); + + EXPECT_EQ_FILE_CONTENTS("generator/constant_initialised_using_computed_constant/model.h", generator->interfaceCode(analyserModel)); + EXPECT_EQ_FILE_CONTENTS("generator/constant_initialised_using_computed_constant/model.c", generator->implementationCode(analyserModel)); + + auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); + + EXPECT_EQ_FILE_CONTENTS("generator/constant_initialised_using_computed_constant/model.py", generator->implementationCode(analyserModel, profile)); +} + TEST(Generator, modelOutOfScope) { libcellml::AnalyserModelPtr analyserModel; diff --git a/tests/generator/generatorvariabletracker.cpp b/tests/generator/generatorvariabletracker.cpp index b7ac79f255..d3ec90a31f 100644 --- a/tests/generator/generatorvariabletracker.cpp +++ b/tests/generator/generatorvariabletracker.cpp @@ -722,3 +722,37 @@ TEST(GeneratorVariableTracker, hodgkinHuxleySquidAxonModel1952DaeUntrackedVariab daeIssues, daeLevels, daeReferenceRules, daeExternalIssues, expectedLevels(daeExternalIssues.size(), libcellml::Issue::Level::ERROR), daeExternalReferenceRules); } + +TEST(GeneratorVariableTracker, variableInitialisedUsingUntrackedVariable) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("generator/variable_initialised_using_untracked_variable/model.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ(size_t(0), analyser->errorCount()); + + auto analyserModel = analyser->analyserModel(); + auto generatorVariableTracker = libcellml::GeneratorVariableTracker::create(); + + generatorVariableTracker->untrackAllVariables(analyserModel); + + EXPECT_EQ_ISSUES_LEVELS_REFERENCERULES(std::vector({"Variable 'a' in component 'main' is computed using an NLA system and cannot therefore be untracked."}), + expectedLevels(1, libcellml::Issue::Level::ERROR), + expectedReferenceRules(1, libcellml::Issue::ReferenceRule::GENERATOR_NLA_BASED_VARIABLE_NOT_UNTRACKABLE), + generatorVariableTracker); + + auto generator = libcellml::Generator::create(); + auto profile = libcellml::GeneratorProfile::create(); + + EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_untracked_variable/model.h", generator->interfaceCode(analyserModel, profile, generatorVariableTracker)); + EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_untracked_variable/model.c", generator->implementationCode(analyserModel, profile, generatorVariableTracker)); + + profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); + + EXPECT_EQ_FILE_CONTENTS("generator/variable_initialised_using_untracked_variable/model.py", generator->implementationCode(analyserModel, profile, generatorVariableTracker)); +} diff --git a/tests/resources/analyser/nla_systems_sharing_initialised_variable.cellml b/tests/resources/analyser/nla_systems_sharing_initialised_variable.cellml new file mode 100644 index 0000000000..c670b9a3ef --- /dev/null +++ b/tests/resources/analyser/nla_systems_sharing_initialised_variable.cellml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + t + + x + + k + + + + cc + + + 2 + k + + + + + + + a + a + + + + x + k + + + + + + + b + b + b + + + + x + cc + + + + + + + d + + + + x + k + + + + + diff --git a/tests/resources/analyser/variable_initialised_using_itself.cellml b/tests/resources/analyser/variable_initialised_using_itself.cellml new file mode 100644 index 0000000000..67e2ef4d61 --- /dev/null +++ b/tests/resources/analyser/variable_initialised_using_itself.cellml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + t + + x + + + + a + b + c + d + e + f + kc + s + + + + + + + + t + + y + + 1 + + + + + + + t + + z + + 1 + + + + cc + + + 2 + kc + + + + + diff --git a/tests/resources/analyser/variable_initialised_using_nla_based_algebraic_variable.cellml b/tests/resources/analyser/variable_initialised_using_nla_based_algebraic_variable.cellml new file mode 100644 index 0000000000..034376a4fa --- /dev/null +++ b/tests/resources/analyser/variable_initialised_using_nla_based_algebraic_variable.cellml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + t + + x + + 1 + + + + + + k + k + + + + x + 3 + + + + + cc + + + 2 + k + + + + + + + b + b + b + + + + x + 5 + + + + + diff --git a/tests/resources/generator/cellml_unit_scaling_constant/model.c b/tests/resources/generator/cellml_unit_scaling_constant/model.c index 78ceac60b7..3af9b7ddcf 100644 --- a/tests/resources/generator/cellml_unit_scaling_constant/model.c +++ b/tests/resources/generator/cellml_unit_scaling_constant/model.c @@ -87,7 +87,7 @@ void initialiseArrays(double *constants, double *computedConstants, double *alge constants[4] = constants[3]; constants[6] = 0.001*constants[2]; constants[5] = constants[6]; - constants[7] = constants[2]; + constants[7] = 0.001*constants[2]; constants[8] = constants[7]; } diff --git a/tests/resources/generator/cellml_unit_scaling_constant/model.py b/tests/resources/generator/cellml_unit_scaling_constant/model.py index 53ba24b239..0bfd6b2ffa 100644 --- a/tests/resources/generator/cellml_unit_scaling_constant/model.py +++ b/tests/resources/generator/cellml_unit_scaling_constant/model.py @@ -60,7 +60,7 @@ def initialise_arrays(constants, computed_constants, algebraic_variables): constants[4] = constants[3] constants[6] = 0.001*constants[2] constants[5] = constants[6] - constants[7] = constants[2] + constants[7] = 0.001*constants[2] constants[8] = constants[7] diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.c b/tests/resources/generator/constant_initialised_using_computed_constant/model.c new file mode 100644 index 0000000000..243f96ba7c --- /dev/null +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.c @@ -0,0 +1,108 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.1. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.8.0"; +const char LIBCELLML_VERSION[] = "0.7.1"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 3; +const size_t ALGEBRAIC_VARIABLE_COUNT = 0; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "main"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "main"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"kkc", "dimensionless", "main"}, + {"kc", "dimensionless", "main"}, + {"k", "dimensionless", "main"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"cc2", "dimensionless", "main"}, + {"cc3", "dimensionless", "main"}, + {"cc", "dimensionless", "main"} +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + constants[2] = 3.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + computedConstants[2] = 2.0*constants[2]; + constants[1] = computedConstants[2]; + computedConstants[0] = 3.0*constants[1]; + computedConstants[1] = computedConstants[0]+1.0; + states[0] = computedConstants[1]; + constants[0] = constants[1]; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = constants[1]+constants[0]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.cellml b/tests/resources/generator/constant_initialised_using_computed_constant/model.cellml new file mode 100644 index 0000000000..97cfc7b8c6 --- /dev/null +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.cellml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + t + + x + + + + kc + kkc + + + + + cc3 + + + cc2 + 1 + + + + + cc2 + + + 3 + kc + + + + + cc + + + 2 + k + + + + + diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.h b/tests/resources/generator/constant_initialised_using_computed_constant/model.h new file mode 100644 index 0000000000..ff5ddf061c --- /dev/null +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.1. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[4]; + char units[14]; + char component[5]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.py b/tests/resources/generator/constant_initialised_using_computed_constant/model.py new file mode 100644 index 0000000000..a29abc7e77 --- /dev/null +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.py @@ -0,0 +1,71 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.1. + +from enum import Enum +from math import * + + +__version__ = "0.8.0" +LIBCELLML_VERSION = "0.7.1" + +STATE_COUNT = 1 +CONSTANT_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 3 +ALGEBRAIC_VARIABLE_COUNT = 0 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "main"} +] + +CONSTANT_INFO = [ + {"name": "kkc", "units": "dimensionless", "component": "main"}, + {"name": "kc", "units": "dimensionless", "component": "main"}, + {"name": "k", "units": "dimensionless", "component": "main"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "cc2", "units": "dimensionless", "component": "main"}, + {"name": "cc3", "units": "dimensionless", "component": "main"}, + {"name": "cc", "units": "dimensionless", "component": "main"} +] + +ALGEBRAIC_VARIABLE_INFO = [ +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + constants[2] = 3.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + computed_constants[2] = 2.0*constants[2] + constants[1] = computed_constants[2] + computed_constants[0] = 3.0*constants[1] + computed_constants[1] = computed_constants[0]+1.0 + states[0] = computed_constants[1] + constants[0] = constants[1] + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = constants[1]+constants[0] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.c b/tests/resources/generator/variable_initialised_using_untracked_variable/model.c new file mode 100644 index 0000000000..023ebb6bc6 --- /dev/null +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.c @@ -0,0 +1,155 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.1. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.8.0"; +const char LIBCELLML_VERSION[] = "0.7.1"; + +const size_t STATE_COUNT = 3; +const size_t CONSTANT_COUNT = 0; +const size_t COMPUTED_CONSTANT_COUNT = 0; +const size_t ALGEBRAIC_VARIABLE_COUNT = 1; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "main"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "main"}, + {"y", "dimensionless", "main"}, + {"z", "dimensionless", "main"} +}; + +const VariableInfo CONSTANT_INFO[] = { +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { + {"a", "dimensionless", "main"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +typedef struct { + double voi; + double *states; + double *rates; + double *constants; + double *computedConstants; + double *algebraicVariables; +} RootFindingInfo; + +extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), + double *u, size_t n, void *data); + +void objectiveFunction0(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraicVariables = ((RootFindingInfo *) data)->algebraicVariables; + + algebraicVariables[0] = u[0]; + + double main_q = 3.0; + double main_k = main_q; + + f[0] = algebraicVariables[0]+sin(algebraicVariables[0])-(main_q+main_k); +} + +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraicVariables }; + double u[1]; + + u[0] = algebraicVariables[0]; + + nlaSolve(objectiveFunction0, u, 1, &rfi); + + algebraicVariables[0] = u[0]; +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + double main_q = 3.0; + double main_k = main_q; + states[0] = main_k; + states[1] = main_k; + algebraicVariables[0] = 0.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + double main_q = 3.0; + double main_k = main_q; + double main_cc = 2.0*main_k; + states[2] = main_cc; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + double main_q = 3.0; + double main_k = main_q; + rates[0] = main_q+main_k; + double main_cc = 2.0*main_k; + double main_kc = main_cc; + rates[1] = main_cc+main_kc; + findRoot0(voi, states, rates, constants, computedConstants, algebraicVariables); + rates[2] = algebraicVariables[0]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ +} diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.cellml b/tests/resources/generator/variable_initialised_using_untracked_variable/model.cellml new file mode 100644 index 0000000000..9a79f07c26 --- /dev/null +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.cellml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + t + + x + + + + q + k + + + + + + + + t + + y + + + + cc + kc + + + + + + + + t + + z + + a + + + + cc + + + 2 + k + + + + + + + a + + + a + + + + + q + k + + + + + diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.h b/tests/resources/generator/variable_initialised_using_untracked_variable/model.h new file mode 100644 index 0000000000..e96940776f --- /dev/null +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.1. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[2]; + char units[14]; + char component[5]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.py b/tests/resources/generator/variable_initialised_using_untracked_variable/model.py new file mode 100644 index 0000000000..2337364f5d --- /dev/null +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.py @@ -0,0 +1,106 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.1. + +from enum import Enum +from math import * + + +__version__ = "0.8.0" +LIBCELLML_VERSION = "0.7.1" + +STATE_COUNT = 3 +CONSTANT_COUNT = 0 +COMPUTED_CONSTANT_COUNT = 0 +ALGEBRAIC_VARIABLE_COUNT = 1 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "main"}, + {"name": "y", "units": "dimensionless", "component": "main"}, + {"name": "z", "units": "dimensionless", "component": "main"} +] + +CONSTANT_INFO = [ +] + +COMPUTED_CONSTANT_INFO = [ +] + +ALGEBRAIC_VARIABLE_INFO = [ + {"name": "a", "units": "dimensionless", "component": "main"} +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +from nlasolver import nla_solve + + +def objective_function_0(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic_variables = data[5] + + algebraic_variables[0] = u[0] + + main_q = 3.0 + main_k = main_q + + f[0] = algebraic_variables[0]+sin(algebraic_variables[0])-(main_q+main_k) + + +def find_root_0(voi, states, rates, constants, computed_constants, algebraic_variables): + u = [nan]*1 + + u[0] = algebraic_variables[0] + + u = nla_solve(objective_function_0, u, 1, [voi, states, rates, constants, computed_constants, algebraic_variables]) + + algebraic_variables[0] = u[0] + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + main_q = 3.0 + main_k = main_q + states[0] = main_k + states[1] = main_k + algebraic_variables[0] = 0.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + main_q = 3.0 + main_k = main_q + main_cc = 2.0*main_k + states[2] = main_cc + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + main_q = 3.0 + main_k = main_q + rates[0] = main_q+main_k + main_cc = 2.0*main_k + main_kc = main_cc + rates[1] = main_cc+main_kc + find_root_0(voi, states, rates, constants, computed_constants, algebraic_variables) + rates[2] = algebraic_variables[0] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + pass From 02fc822b2e7eda99836a192d4e42ae7c5d511d04 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 6 Oct 2026 12:46:57 +1300 Subject: [PATCH 2/4] Fixed false NLA underconstraint flags. --- src/analyser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/analyser.cpp b/src/analyser.cpp index b45fae2ec3..c73bb0b73d 100644 --- a/src/analyser.cpp +++ b/src/analyser.cpp @@ -2811,8 +2811,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) } } - if ((internalEquation->mNlaSiblings.size() + 1 < internalEquation->mUnknownVariables.size()) - || (nlaEquationCount < nlaUnknownVariables.size())) { + if (nlaEquationCount < nlaUnknownVariables.size()) { // There are fewer NLA equations than unknown variables, so all the unknown variables involved in the // NLA system should be considered as underconstrained. From 450156ede0757f5ddb75e836b803bcc626b8e2eb Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 6 Oct 2026 13:07:39 +1300 Subject: [PATCH 3/4] Fixed NLA system indexing across sibling groups. --- src/analyser.cpp | 37 +++- tests/analyser/analyser.cpp | 29 +++ tests/generator/generator.cpp | 24 +++ .../overconstrained_bridged_nla_system.cellml | 92 ++++++++ .../model.c | 199 ++++++++++++++++++ .../model.cellml | 76 +++++++ .../model.h | 37 ++++ .../model.py | 143 +++++++++++++ 8 files changed, 627 insertions(+), 10 deletions(-) create mode 100644 tests/resources/analyser/overconstrained_bridged_nla_system.cellml create mode 100644 tests/resources/generator/nla_initial_guess_using_computed_constant/model.c create mode 100644 tests/resources/generator/nla_initial_guess_using_computed_constant/model.cellml create mode 100644 tests/resources/generator/nla_initial_guess_using_computed_constant/model.h create mode 100644 tests/resources/generator/nla_initial_guess_using_computed_constant/model.py diff --git a/src/analyser.cpp b/src/analyser.cpp index c73bb0b73d..35b6200456 100644 --- a/src/analyser.cpp +++ b/src/analyser.cpp @@ -2694,14 +2694,9 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) } // Make the NLA equations that compute the same variables aware of one - // another and assign them an index for the NLA system in which they are - // used. + // another. if (internalEquation->mType == AnalyserInternalEquation::Type::NLA) { - if (internalEquation->mNlaSystemIndex == MAX_SIZE_T) { - internalEquation->mNlaSystemIndex = ++nlaSystemIndex; - } - for (const auto &otherInternalEquation : mInternalEquations) { if ((otherInternalEquation != internalEquation) && (otherInternalEquation->mType == AnalyserInternalEquation::Type::NLA)) { @@ -2724,14 +2719,36 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model) } // Consider otherInternalEquation as an NLA sibling of - // internalEquation, if there are some common unknown - // variables, and make sure that it has the same NLA system - // index as internalEquation. + // internalEquation, if there are some common unknown variables. if (!commonUnknownVariables.empty()) { internalEquation->mNlaSiblings.push_back(otherInternalEquation); + } + } + } + } + } + + // Assign an index to each of our NLA systems, i.e. to each set of NLA equations that are, directly or indirectly, + // NLA siblings of one another. + // Note: we cannot assign those indices while determining the NLA siblings since two sets of NLA equations may only + // be found to belong to the same NLA system once we come across an NLA equation that bridges them. + + for (const auto &internalEquation : mInternalEquations) { + if ((internalEquation->mType == AnalyserInternalEquation::Type::NLA) + && (internalEquation->mNlaSystemIndex == MAX_SIZE_T)) { + AnalyserInternalEquationPtrs nlaSystemEquations = {internalEquation}; + + internalEquation->mNlaSystemIndex = ++nlaSystemIndex; + + for (size_t i = 0; i < nlaSystemEquations.size(); ++i) { + for (const auto &nlaSibling : nlaSystemEquations[i]->mNlaSiblings) { + auto nlaSiblingEquation = nlaSibling.lock(); + + if (nlaSiblingEquation->mNlaSystemIndex == MAX_SIZE_T) { + nlaSiblingEquation->mNlaSystemIndex = nlaSystemIndex; - otherInternalEquation->mNlaSystemIndex = internalEquation->mNlaSystemIndex; + nlaSystemEquations.push_back(nlaSiblingEquation); } } } diff --git a/tests/analyser/analyser.cpp b/tests/analyser/analyser.cpp index 7473357235..b60035ab12 100644 --- a/tests/analyser/analyser.cpp +++ b/tests/analyser/analyser.cpp @@ -1099,6 +1099,35 @@ TEST(Analyser, overconstrainedNlaSystem) EXPECT_EQ(libcellml::AnalyserModel::Type::OVERCONSTRAINED, analyser->analyserModel()->type()); } +TEST(Analyser, overconstrainedBridgedNlaSystem) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("analyser/overconstrained_bridged_nla_system.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + const std::vector expectedIssues = { + "Variable 'b' in component 'main' is overconstrained.", + "Variable 'a' in component 'main' is overconstrained.", + "Variable 'c' in component 'main' is overconstrained.", + "Variable 'f' in component 'main' is overconstrained.", + "Variable 'e' in component 'main' is overconstrained.", + }; + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ_ISSUES_CELLMLELEMENTTYPES_LEVELS_REFERENCERULES_URLS(expectedIssues, + expectedCellmlElementTypes(expectedIssues.size(), libcellml::CellmlElementType::VARIABLE), + expectedLevels(expectedIssues.size(), libcellml::Issue::Level::ERROR), + expectedReferenceRules(expectedIssues.size(), libcellml::Issue::ReferenceRule::ANALYSER_VARIABLE_OVERCONSTRAINED), + expectedUrls(expectedIssues.size(), "https://libcellml.org/documentation/guides/latest/runtime_codes/index?issue=ANALYSER_VARIABLE_OVERCONSTRAINED"), + analyser); + + EXPECT_EQ(libcellml::AnalyserModel::Type::OVERCONSTRAINED, analyser->analyserModel()->type()); +} + TEST(Analyser, unsuitablyConstrainedNlaSystem) { auto parser = libcellml::Parser::create(); diff --git a/tests/generator/generator.cpp b/tests/generator/generator.cpp index 8b65c381df..bd16c66fdd 100644 --- a/tests/generator/generator.cpp +++ b/tests/generator/generator.cpp @@ -1676,6 +1676,30 @@ TEST(Generator, constantInitialisedUsingComputedConstant) EXPECT_EQ_FILE_CONTENTS("generator/constant_initialised_using_computed_constant/model.py", generator->implementationCode(analyserModel, profile)); } +TEST(Generator, nlaInitialGuessUsingComputedConstant) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("generator/nla_initial_guess_using_computed_constant/model.cellml")); + + EXPECT_EQ(size_t(0), parser->issueCount()); + + auto analyser = libcellml::Analyser::create(); + + analyser->analyseModel(model); + + EXPECT_EQ(size_t(0), analyser->errorCount()); + + auto analyserModel = analyser->analyserModel(); + auto generator = libcellml::Generator::create(); + + EXPECT_EQ_FILE_CONTENTS("generator/nla_initial_guess_using_computed_constant/model.h", generator->interfaceCode(analyserModel)); + EXPECT_EQ_FILE_CONTENTS("generator/nla_initial_guess_using_computed_constant/model.c", generator->implementationCode(analyserModel)); + + auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON); + + EXPECT_EQ_FILE_CONTENTS("generator/nla_initial_guess_using_computed_constant/model.py", generator->implementationCode(analyserModel, profile)); +} + TEST(Generator, modelOutOfScope) { libcellml::AnalyserModelPtr analyserModel; diff --git a/tests/resources/analyser/overconstrained_bridged_nla_system.cellml b/tests/resources/analyser/overconstrained_bridged_nla_system.cellml new file mode 100644 index 0000000000..e52fa10c0f --- /dev/null +++ b/tests/resources/analyser/overconstrained_bridged_nla_system.cellml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + t + + x + + 1 + + + + + + a + b + + x + + + + + + b + c + + x + + + + + + d + e + + x + + + + + + e + f + + x + + + + + + a + f + + x + + + + + + c + + x + + + + + + c + + x + + + + diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c new file mode 100644 index 0000000000..d261a2b760 --- /dev/null +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c @@ -0,0 +1,199 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.1. */ + +#include "model.h" + +#include +#include + +const char VERSION[] = "0.8.0"; +const char LIBCELLML_VERSION[] = "0.7.1"; + +const size_t STATE_COUNT = 1; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_VARIABLE_COUNT = 3; + +const VariableInfo VOI_INFO = {"t", "dimensionless", "main"}; + +const VariableInfo STATE_INFO[] = { + {"x", "dimensionless", "main"} +}; + +const VariableInfo CONSTANT_INFO[] = { + {"k", "dimensionless", "main"} +}; + +const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"cc", "dimensionless", "main"} +}; + +const VariableInfo ALGEBRAIC_VARIABLE_INFO[] = { + {"a", "dimensionless", "main"}, + {"b", "dimensionless", "main"}, + {"d", "dimensionless", "main"} +}; + +double * createStatesArray() +{ + double *res = (double *) malloc(STATE_COUNT*sizeof(double)); + + for (size_t i = 0; i < STATE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createConstantsArray() +{ + double *res = (double *) malloc(CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createComputedConstantsArray() +{ + double *res = (double *) malloc(COMPUTED_CONSTANT_COUNT*sizeof(double)); + + for (size_t i = 0; i < COMPUTED_CONSTANT_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +double * createAlgebraicVariablesArray() +{ + double *res = (double *) malloc(ALGEBRAIC_VARIABLE_COUNT*sizeof(double)); + + for (size_t i = 0; i < ALGEBRAIC_VARIABLE_COUNT; ++i) { + res[i] = NAN; + } + + return res; +} + +void deleteArray(double *array) +{ + free(array); +} + +typedef struct { + double voi; + double *states; + double *rates; + double *constants; + double *computedConstants; + double *algebraicVariables; +} RootFindingInfo; + +extern void nlaSolve(void (*objectiveFunction)(double *, double *, void *), + double *u, size_t n, void *data); + +void objectiveFunction0(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraicVariables = ((RootFindingInfo *) data)->algebraicVariables; + + algebraicVariables[0] = u[0]; + + f[0] = algebraicVariables[0]*algebraicVariables[0]-(states[0]+3.0); +} + +void findRoot0(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraicVariables }; + double u[1]; + + u[0] = algebraicVariables[0]; + + nlaSolve(objectiveFunction0, u, 1, &rfi); + + algebraicVariables[0] = u[0]; +} + +void objectiveFunction1(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraicVariables = ((RootFindingInfo *) data)->algebraicVariables; + + algebraicVariables[1] = u[0]; + + f[0] = algebraicVariables[1]*algebraicVariables[1]*algebraicVariables[1]-(states[0]+computedConstants[0]); +} + +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraicVariables }; + double u[1]; + + u[0] = algebraicVariables[1]; + + nlaSolve(objectiveFunction1, u, 1, &rfi); + + algebraicVariables[1] = u[0]; +} + +void objectiveFunction2(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraicVariables = ((RootFindingInfo *) data)->algebraicVariables; + + algebraicVariables[2] = u[0]; + + f[0] = sin(algebraicVariables[2])-2.0*states[0]; +} + +void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraicVariables }; + double u[1]; + + u[0] = algebraicVariables[2]; + + nlaSolve(objectiveFunction2, u, 1, &rfi); + + algebraicVariables[2] = u[0]; +} + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + states[0] = 1.0; + constants[0] = 3.0; + algebraicVariables[0] = 1.0; + algebraicVariables[2] = 1.0; +} + +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + computedConstants[0] = 2.0*constants[0]; + algebraicVariables[1] = computedConstants[0]; +} + +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + rates[0] = constants[0]; +} + +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables) +{ + findRoot0(voi, states, rates, constants, computedConstants, algebraicVariables); + findRoot1(voi, states, rates, constants, computedConstants, algebraicVariables); + findRoot2(voi, states, rates, constants, computedConstants, algebraicVariables); +} diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.cellml b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.cellml new file mode 100644 index 0000000000..4161f25036 --- /dev/null +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.cellml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + t + + x + + k + + + + cc + + + 2 + k + + + + + + + a + a + + + + x + 3 + + + + + + + b + b + b + + + + x + cc + + + + + + + d + + + + 2 + x + + + + + diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h new file mode 100644 index 0000000000..db45cfd5a6 --- /dev/null +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h @@ -0,0 +1,37 @@ +/* The content of this file was generated using the C profile of libCellML 0.7.1. */ + +#pragma once + +#include + +extern const char VERSION[]; +extern const char LIBCELLML_VERSION[]; + +extern const size_t STATE_COUNT; +extern const size_t CONSTANT_COUNT; +extern const size_t COMPUTED_CONSTANT_COUNT; +extern const size_t ALGEBRAIC_VARIABLE_COUNT; + +typedef struct { + char name[3]; + char units[14]; + char component[5]; +} VariableInfo; + +extern const VariableInfo VOI_INFO; +extern const VariableInfo STATE_INFO[]; +extern const VariableInfo CONSTANT_INFO[]; +extern const VariableInfo COMPUTED_CONSTANT_INFO[]; +extern const VariableInfo ALGEBRAIC_VARIABLE_INFO[]; + +double * createStatesArray(); +double * createConstantsArray(); +double * createComputedConstantsArray(); +double * createAlgebraicVariablesArray(); + +void deleteArray(double *array); + +void initialiseArrays(double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeComputedConstants(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); +void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraicVariables); diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py new file mode 100644 index 0000000000..4a11bcb712 --- /dev/null +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py @@ -0,0 +1,143 @@ +# The content of this file was generated using the Python profile of libCellML 0.7.1. + +from enum import Enum +from math import * + + +__version__ = "0.8.0" +LIBCELLML_VERSION = "0.7.1" + +STATE_COUNT = 1 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_VARIABLE_COUNT = 3 + +VOI_INFO = {"name": "t", "units": "dimensionless", "component": "main"} + +STATE_INFO = [ + {"name": "x", "units": "dimensionless", "component": "main"} +] + +CONSTANT_INFO = [ + {"name": "k", "units": "dimensionless", "component": "main"} +] + +COMPUTED_CONSTANT_INFO = [ + {"name": "cc", "units": "dimensionless", "component": "main"} +] + +ALGEBRAIC_VARIABLE_INFO = [ + {"name": "a", "units": "dimensionless", "component": "main"}, + {"name": "b", "units": "dimensionless", "component": "main"}, + {"name": "d", "units": "dimensionless", "component": "main"} +] + + +def create_states_array(): + return [nan]*STATE_COUNT + + +def create_constants_array(): + return [nan]*CONSTANT_COUNT + + +def create_computed_constants_array(): + return [nan]*COMPUTED_CONSTANT_COUNT + + +def create_algebraic_variables_array(): + return [nan]*ALGEBRAIC_VARIABLE_COUNT + + +from nlasolver import nla_solve + + +def objective_function_0(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic_variables = data[5] + + algebraic_variables[0] = u[0] + + f[0] = algebraic_variables[0]*algebraic_variables[0]-(states[0]+3.0) + + +def find_root_0(voi, states, rates, constants, computed_constants, algebraic_variables): + u = [nan]*1 + + u[0] = algebraic_variables[0] + + u = nla_solve(objective_function_0, u, 1, [voi, states, rates, constants, computed_constants, algebraic_variables]) + + algebraic_variables[0] = u[0] + + +def objective_function_1(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic_variables = data[5] + + algebraic_variables[1] = u[0] + + f[0] = algebraic_variables[1]*algebraic_variables[1]*algebraic_variables[1]-(states[0]+computed_constants[0]) + + +def find_root_1(voi, states, rates, constants, computed_constants, algebraic_variables): + u = [nan]*1 + + u[0] = algebraic_variables[1] + + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic_variables]) + + algebraic_variables[1] = u[0] + + +def objective_function_2(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic_variables = data[5] + + algebraic_variables[2] = u[0] + + f[0] = sin(algebraic_variables[2])-2.0*states[0] + + +def find_root_2(voi, states, rates, constants, computed_constants, algebraic_variables): + u = [nan]*1 + + u[0] = algebraic_variables[2] + + u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic_variables]) + + algebraic_variables[2] = u[0] + + +def initialise_arrays(states, rates, constants, computed_constants, algebraic_variables): + states[0] = 1.0 + constants[0] = 3.0 + algebraic_variables[0] = 1.0 + algebraic_variables[2] = 1.0 + + +def compute_computed_constants(voi, states, rates, constants, computed_constants, algebraic_variables): + computed_constants[0] = 2.0*constants[0] + algebraic_variables[1] = computed_constants[0] + + +def compute_rates(voi, states, rates, constants, computed_constants, algebraic_variables): + rates[0] = constants[0] + + +def compute_variables(voi, states, rates, constants, computed_constants, algebraic_variables): + find_root_0(voi, states, rates, constants, computed_constants, algebraic_variables) + find_root_1(voi, states, rates, constants, computed_constants, algebraic_variables) + find_root_2(voi, states, rates, constants, computed_constants, algebraic_variables) From 8ddeb1f0e4e7c100045258797ceeb49344762241 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 2 Dec 2026 16:40:18 +1300 Subject: [PATCH 4/4] Updated libCellML and its generator's versions. --- .../constant_initialised_using_computed_constant/model.c | 6 +++--- .../constant_initialised_using_computed_constant/model.h | 2 +- .../constant_initialised_using_computed_constant/model.py | 6 +++--- .../nla_initial_guess_using_computed_constant/model.c | 6 +++--- .../nla_initial_guess_using_computed_constant/model.h | 2 +- .../nla_initial_guess_using_computed_constant/model.py | 6 +++--- .../variable_initialised_using_untracked_variable/model.c | 6 +++--- .../variable_initialised_using_untracked_variable/model.h | 2 +- .../variable_initialised_using_untracked_variable/model.py | 6 +++--- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.c b/tests/resources/generator/constant_initialised_using_computed_constant/model.c index 243f96ba7c..b435278caa 100644 --- a/tests/resources/generator/constant_initialised_using_computed_constant/model.c +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.c @@ -1,12 +1,12 @@ -/* The content of this file was generated using the C profile of libCellML 0.7.1. */ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ #include "model.h" #include #include -const char VERSION[] = "0.8.0"; -const char LIBCELLML_VERSION[] = "0.7.1"; +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; const size_t STATE_COUNT = 1; const size_t CONSTANT_COUNT = 3; diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.h b/tests/resources/generator/constant_initialised_using_computed_constant/model.h index ff5ddf061c..3e65338fda 100644 --- a/tests/resources/generator/constant_initialised_using_computed_constant/model.h +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.h @@ -1,4 +1,4 @@ -/* The content of this file was generated using the C profile of libCellML 0.7.1. */ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ #pragma once diff --git a/tests/resources/generator/constant_initialised_using_computed_constant/model.py b/tests/resources/generator/constant_initialised_using_computed_constant/model.py index a29abc7e77..3218eaaf75 100644 --- a/tests/resources/generator/constant_initialised_using_computed_constant/model.py +++ b/tests/resources/generator/constant_initialised_using_computed_constant/model.py @@ -1,11 +1,11 @@ -# The content of this file was generated using the Python profile of libCellML 0.7.1. +# The content of this file was generated using the Python profile of libCellML 0.7.2. from enum import Enum from math import * -__version__ = "0.8.0" -LIBCELLML_VERSION = "0.7.1" +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" STATE_COUNT = 1 CONSTANT_COUNT = 3 diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c index d261a2b760..907b2fb184 100644 --- a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.c @@ -1,12 +1,12 @@ -/* The content of this file was generated using the C profile of libCellML 0.7.1. */ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ #include "model.h" #include #include -const char VERSION[] = "0.8.0"; -const char LIBCELLML_VERSION[] = "0.7.1"; +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; const size_t STATE_COUNT = 1; const size_t CONSTANT_COUNT = 1; diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h index db45cfd5a6..f472e3050a 100644 --- a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.h @@ -1,4 +1,4 @@ -/* The content of this file was generated using the C profile of libCellML 0.7.1. */ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ #pragma once diff --git a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py index 4a11bcb712..c2edf0431b 100644 --- a/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py +++ b/tests/resources/generator/nla_initial_guess_using_computed_constant/model.py @@ -1,11 +1,11 @@ -# The content of this file was generated using the Python profile of libCellML 0.7.1. +# The content of this file was generated using the Python profile of libCellML 0.7.2. from enum import Enum from math import * -__version__ = "0.8.0" -LIBCELLML_VERSION = "0.7.1" +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" STATE_COUNT = 1 CONSTANT_COUNT = 1 diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.c b/tests/resources/generator/variable_initialised_using_untracked_variable/model.c index 023ebb6bc6..f0bc4baea3 100644 --- a/tests/resources/generator/variable_initialised_using_untracked_variable/model.c +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.c @@ -1,12 +1,12 @@ -/* The content of this file was generated using the C profile of libCellML 0.7.1. */ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ #include "model.h" #include #include -const char VERSION[] = "0.8.0"; -const char LIBCELLML_VERSION[] = "0.7.1"; +const char VERSION[] = "0.8.1"; +const char LIBCELLML_VERSION[] = "0.7.2"; const size_t STATE_COUNT = 3; const size_t CONSTANT_COUNT = 0; diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.h b/tests/resources/generator/variable_initialised_using_untracked_variable/model.h index e96940776f..d9747ee95d 100644 --- a/tests/resources/generator/variable_initialised_using_untracked_variable/model.h +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.h @@ -1,4 +1,4 @@ -/* The content of this file was generated using the C profile of libCellML 0.7.1. */ +/* The content of this file was generated using the C profile of libCellML 0.7.2. */ #pragma once diff --git a/tests/resources/generator/variable_initialised_using_untracked_variable/model.py b/tests/resources/generator/variable_initialised_using_untracked_variable/model.py index 2337364f5d..4a6bb8aea4 100644 --- a/tests/resources/generator/variable_initialised_using_untracked_variable/model.py +++ b/tests/resources/generator/variable_initialised_using_untracked_variable/model.py @@ -1,11 +1,11 @@ -# The content of this file was generated using the Python profile of libCellML 0.7.1. +# The content of this file was generated using the Python profile of libCellML 0.7.2. from enum import Enum from math import * -__version__ = "0.8.0" -LIBCELLML_VERSION = "0.7.1" +__version__ = "0.8.1" +LIBCELLML_VERSION = "0.7.2" STATE_COUNT = 3 CONSTANT_COUNT = 0