From d6f5b87ecb3ca1b4560ae3a6840584474fd9bb42 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Mon, 8 Apr 2024 14:56:53 +1200 Subject: [PATCH] Interpreter: added some (empty) methods to compute a model. qwe qwe --- src/api/libcellml/interpreter.h | 36 +++++++++++++++++++ src/bindings/interface/interpreter.i | 12 +++++++ src/bindings/javascript/interpreter.cpp | 4 +++ src/interpreter.cpp | 16 +++++++++ tests/bindings/javascript/interpreter.test.js | 5 +++ tests/bindings/python/test_interpreter.py | 5 +++ tests/coverage/coverage.cpp | 13 ++++++- 7 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/api/libcellml/interpreter.h b/src/api/libcellml/interpreter.h index 8d9dfa1740..0ee2ec4ead 100644 --- a/src/api/libcellml/interpreter.h +++ b/src/api/libcellml/interpreter.h @@ -65,6 +65,42 @@ class LIBCELLML_EXPORT Interpreter */ void setModel(const AnalyserModelPtr &model); + /** + * @brief Initialise the model's variables. + * + * Initialise the model's variables. + * + * @sa computeComputedConstants, computeRates, computeVariables + */ + void initialiseVariables(); + + /** + * @brief Compute the model's computed constants. + * + * Compute the model's computed constants. + * + * @sa initialiseVariables, computeRates, computeVariables + */ + void computeComputedConstants(); + + /** + * @brief Compute the model's rates. + * + * Compute the model's rates. + * + * @sa initialiseVariables, computeComputedConstants, computeVariables + */ + void computeRates(); + + /** + * @brief Compute the model's variables. + * + * Compute the model's variables. + * + * @sa initialiseVariables, computeComputedConstants, computeRates + */ + void computeVariables(); + private: Interpreter(); /**< Constructor, @private. */ diff --git a/src/bindings/interface/interpreter.i b/src/bindings/interface/interpreter.i index 8373681836..74297669b9 100644 --- a/src/bindings/interface/interpreter.i +++ b/src/bindings/interface/interpreter.i @@ -16,6 +16,18 @@ %feature("docstring") libcellml::Interpreter::setModel "Sets the model to interpret."; +%feature("docstring") libcellml::Interpreter::initialiseVariables +"Initialises the model's variables."; + +%feature("docstring") libcellml::Interpreter::computeComputedConstants +"Computes the model's computed constants."; + +%feature("docstring") libcellml::Interpreter::computeRates +"Computes the model's rates."; + +%feature("docstring") libcellml::Interpreter::computeVariables +"Computes the model's variables."; + %{ #include "libcellml/interpreter.h" %} diff --git a/src/bindings/javascript/interpreter.cpp b/src/bindings/javascript/interpreter.cpp index 8ff8f6ebf5..ab9a12926d 100644 --- a/src/bindings/javascript/interpreter.cpp +++ b/src/bindings/javascript/interpreter.cpp @@ -26,5 +26,9 @@ EMSCRIPTEN_BINDINGS(libcellml_interpreter) .smart_ptr_constructor("Interpreter", &libcellml::Interpreter::create) .function("model", &libcellml::Interpreter::model) .function("setModel", &libcellml::Interpreter::setModel) + .function("initialiseVariables", &libcellml::Interpreter::initialiseVariables) + .function("computeComputedConstants", &libcellml::Interpreter::computeComputedConstants) + .function("computeRates", &libcellml::Interpreter::computeRates) + .function("computeVariables", &libcellml::Interpreter::computeVariables) ; } diff --git a/src/interpreter.cpp b/src/interpreter.cpp index ba71cda7b6..7833357b33 100644 --- a/src/interpreter.cpp +++ b/src/interpreter.cpp @@ -45,4 +45,20 @@ void Interpreter::setModel(const AnalyserModelPtr &model) mPimpl->mModel = model; } +void Interpreter::initialiseVariables() +{ +} + +void Interpreter::computeComputedConstants() +{ +} + +void Interpreter::computeRates() +{ +} + +void Interpreter::computeVariables() +{ +} + } // namespace libcellml diff --git a/tests/bindings/javascript/interpreter.test.js b/tests/bindings/javascript/interpreter.test.js index ce4532cca0..f503bf20cf 100644 --- a/tests/bindings/javascript/interpreter.test.js +++ b/tests/bindings/javascript/interpreter.test.js @@ -37,5 +37,10 @@ describe("Interpreter tests", () => { i.setModel(a.model()) expect(i.model()).toBeDefined() + + i.initialiseVariables() + i.computeComputedConstants() + i.computeRates() + i.computeVariables() }) }) diff --git a/tests/bindings/python/test_interpreter.py b/tests/bindings/python/test_interpreter.py index 0fb8b9e10e..807caaf59f 100644 --- a/tests/bindings/python/test_interpreter.py +++ b/tests/bindings/python/test_interpreter.py @@ -37,6 +37,11 @@ def test_algebraic_eqn_computed_var_on_rhs(self): self.assertIsNotNone(i.model()) + i.initialiseVariables() + i.computeComputedConstants() + i.computeRates() + i.computeVariables() + if __name__ == '__main__': unittest.main() diff --git a/tests/coverage/coverage.cpp b/tests/coverage/coverage.cpp index df993d458e..943ac1abb1 100644 --- a/tests/coverage/coverage.cpp +++ b/tests/coverage/coverage.cpp @@ -842,8 +842,10 @@ TEST(Coverage, generator) TEST(Coverage, interpreter) { + // Get an interpreter for the HH52 model. + auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("coverage/generator/model.cellml")); + auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.cellml")); auto analyser = libcellml::Analyser::create(); analyser->analyseModel(model); @@ -851,11 +853,20 @@ TEST(Coverage, interpreter) auto analyserModel = analyser->model(); auto interpreter = libcellml::Interpreter::create(); + // Make sure that Interpreter::model() works as expected. + EXPECT_EQ(nullptr, interpreter->model()); interpreter->setModel(analyserModel); EXPECT_EQ(analyserModel, interpreter->model()); + + // Fully initialise the HH52 model. + + interpreter->initialiseVariables(); + interpreter->computeComputedConstants(); + interpreter->computeRates(); + interpreter->computeVariables(); } TEST(CoverageValidator, degreeElementWithOneSibling)