Analyse a model item¶
The Analyser class takes an existing, valid Model item, and checks it for mathematical sense.
This includes checking things like that all variables requiring initial values have them, that equations do not conflict with one another, and that any variables used in equations are actually defined in the model.
The three basic steps to model analysis are:
Creating an
Analyseritem and passing in aModelfor analysis;Checking for any
Issuesraised; and(optional: for code generation only) Retrieving a
AnalysedModelitem to pass to aGenerator, if required.
// Analyse the model: check for mathematical and modelling errors.
auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);
printIssues(analyser);
Full context: example_simulationToolDev.cpp
# Analyse a model: check for mathematical and modelling errors.
analyser = Analyser()
analyser.analyseModel(model)
print_issues_to_terminal(analyser)
Full context: example_simulationToolDev.py
Any issues or messages raised are stored within the class’s logger.
More information about accessing Issue items can be found on the Common actions > Retrieve Issue items page.
Use of the Analyser class is a prerequisite for the Generator class.
The generator makes use of the structures created during the analysis process, so takes a AnalyserModel as an input.
// Generate runnable code in other language formats for this model.
// Create a Generator instance. Note that by default this uses the C language profile.
auto generator = libcellml::Generator::create();
// Pass the generator the model for processing.
generator->setModel(analyser->model());
printIssues(generator);
Full context: example_simulationToolDev.cpp
# Generate runnable code in other language formats for this model.
# Create a Generator instance. Note that by default this is the C language.
generator = Generator()
# Pass the generator the analysed model for processing.
generator.processModel(analyser.model())
print_issues_to_terminal(generator)
Full context: example_simulationToolDev.py
TODO