Skip to content

Commit

Permalink
Interpreter: added some (empty) methods to compute a model.
Browse files Browse the repository at this point in the history
qwe

qwe
  • Loading branch information
agarny committed Apr 8, 2024
1 parent 99672cd commit d6f5b87
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/api/libcellml/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down
12 changes: 12 additions & 0 deletions src/bindings/interface/interpreter.i
Original file line number Diff line number Diff line change
Expand Up @@ -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"
%}
Expand Down
4 changes: 4 additions & 0 deletions src/bindings/javascript/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
}
16 changes: 16 additions & 0 deletions src/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions tests/bindings/javascript/interpreter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ describe("Interpreter tests", () => {
i.setModel(a.model())

expect(i.model()).toBeDefined()

i.initialiseVariables()
i.computeComputedConstants()
i.computeRates()
i.computeVariables()
})
})
5 changes: 5 additions & 0 deletions tests/bindings/python/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 12 additions & 1 deletion tests/coverage/coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,20 +842,31 @@ 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);

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)
Expand Down

0 comments on commit d6f5b87

Please sign in to comment.