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:

  1. Creating an Analyser item and passing in a Model for analysis;

  2. Checking for any Issues raised; and

  3. (optional: for code generation only) Retrieving a AnalysedModel item to pass to a Generator, 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

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

TODO