Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,8 @@ void Analyser::AnalyserImpl::analyseEquationAst(const AnalyserEquationAstPtr &as
// We have found the first occurrence of our variable of
// integration, but now we must ensure that it (or any of
// its equivalent variables) is not initialised.

auto isVoiInitialised = false;
// Note: we keep track of our variable of integration even if it is initialised, so that we only
// check it once (and therefore report any issue only once).

for (const auto &voiEquivalentVariable : equivalentVariables(voi)) {
if (!voiEquivalentVariable->initialValue().empty()) {
Expand All @@ -1043,17 +1043,13 @@ void Analyser::AnalyserImpl::analyseEquationAst(const AnalyserEquationAstPtr &as
issue->mPimpl->mItem->mPimpl->setVariable(voiEquivalentVariable);

addIssue(issue);

isVoiInitialised = true;
}
}

if (!isVoiInitialised) {
mAnalyserModel->mPimpl->mVoi = AnalyserVariable::AnalyserVariableImpl::create();
mAnalyserModel->mPimpl->mVoi = AnalyserVariable::AnalyserVariableImpl::create();

mAnalyserModel->mPimpl->mVoi->mPimpl->populate(AnalyserVariable::Type::VARIABLE_OF_INTEGRATION,
0, nullptr, voi, mAnalyserModel, {});
}
mAnalyserModel->mPimpl->mVoi->mPimpl->populate(AnalyserVariable::Type::VARIABLE_OF_INTEGRATION,
0, nullptr, voi, mAnalyserModel, {});
}
} while (voi == nullptr);
} else {
Expand Down
26 changes: 26 additions & 0 deletions tests/analyser/analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ TEST(Analyser, initialisedVariableOfIntegrationInNonFirstComponent)
EXPECT_EQ(libcellml::AnalyserModel::Type::INVALID, analyser->analyserModel()->type());
}

TEST(Analyser, initialisedVariableOfIntegrationWithSeveralOdes)
{
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("analyser/initialised_variable_of_integration_several_odes.cellml"));

EXPECT_EQ(size_t(0), parser->issueCount());

const std::vector<std::string> expectedIssues = {
"Variable 'time' in component 'my_component' cannot be both a variable of integration and initialised.",
};

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_VOI_INITIALISED),
expectedUrls(expectedIssues.size(), "https://libcellml.org/documentation/guides/latest/runtime_codes/index?issue=ANALYSER_VOI_INITIALISED"),
analyser);

EXPECT_EQ(libcellml::AnalyserModel::Type::INVALID, analyser->analyserModel()->type());
EXPECT_EQ(nullptr, analyser->analyserModel()->voi());
}

TEST(Analyser, twoVariablesOfIntegration)
{
auto parser = libcellml::Parser::create();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version='1.0' encoding='UTF-8'?>
<model name="initialised_variable_of_integration_several_odes" xmlns="http://www.cellml.org/cellml/2.0#" xmlns:cellml="http://www.cellml.org/cellml/2.0#">
<units name="per_second">
<unit exponent="-1" units="second"/>
</units>
<component name="my_component">
<variable name="time" units="second" initial_value="0"/>
<variable name="x" units="dimensionless" initial_value="1"/>
<variable name="y" units="dimensionless" initial_value="2"/>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>time</ci>
</bvar>
<ci>x</ci>
</apply>
<cn cellml:units="per_second">1</cn>
</apply>
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>time</ci>
</bvar>
<ci>y</ci>
</apply>
<cn cellml:units="per_second">2</cn>
</apply>
</math>
</component>
</model>
Loading