Parameter Sensitivities with OpenModelica

This section describes the use of OpenModelica to compute parameter sensitivities using forward sensitivity analysis together with the Sundials/IDA solver.

Note: this is a very short preliminary description which soon will be considerably improved, since this a rather new feature and will continuous improved.

Note: OpenModelica version 1.10 or newer is required.


Parameter sensitivity analysis aims at analyzing the behavior of the corresponding model states w.r.t. model parameters.

Formally, consider a Modelica model as a DAE system:

F(x, \dot x, y, p, t) = 0 \; x(t_0) = x_0(p)

where x(t) \in \mathbf{R}^n represent state variables, \dot x(t) \in \mathbf{R}^n represent state derivatives, y(t) \in \mathbf{R}^k represent algebraic variables, p \in \mathbf{R}^m model parameters.

For parameter sensitivity analysis the derivatives

\frac{\partial x}{ \partial p}

are required which quantify, according to their mathematical definition, the impact of parameters p on states x. In the Sundials/IDA implementation the derivatives are used to evolve the solution over the time by:

\dot s_i = \frac{\partial x}{ \partial p_i}

An Example

This section demonstrates the usage of the sensitivities analysis in OpenModelica on an example. This module is enabled by the following OpenModelica compiler flag:

>>> setCommandLineOptions("--calculateSensitivities")
Listing 6
model LotkaVolterra
  Real x(start=5, fixed=true),y(start=3, fixed=true);
  parameter Real mu1=5,mu2=2;
  parameter Real lambda1=3,lambda2=1;
  0 = x*(mu1-lambda1*y) - der(x);
  0 = -y* (mu2 -lambda2*x) - der(y);
end LotkaVolterra;

Also for the simulation it is needed to set IDA as solver integration method and add a further simulation flag -idaSensitivity to calculate the parameter sensitivities during the normal simulation.

>>> simulate(LotkaVolterra, method="ida", simflags="-idaSensitivity")
record SimulationResult
    resultFile = "«DOCHOME»/LotkaVolterra_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'ida', fileNamePrefix = 'LotkaVolterra', options = '', outputFormat = 'mat', variableFilter = '.*', cflags = '', simflags = '-idaSensitivity'",
    messages = "LOG_SUCCESS       | info    | The initialization finished successfully without homotopy method.
LOG_SUCCESS       | info    | The simulation finished successfully.
    timeFrontend = 0.005041393,
    timeBackend = 0.002635878,
    timeSimCode = 0.000840839,
    timeTemplates = 0.003819148,
    timeCompile = 0.43288498,
    timeSimulation = 0.019725055,
    timeTotal = 0.465081864
end SimulationResult;

Now all calculated sensitivities are stored into the results mat file under the $Sensitivities block, where all currently every top-level parameter of the Real type is used to calculate the sensitivities w.r.t. every state.


Figure 77 Results of the sensitivities calculated by IDA solver.


Figure 78 Results of the LotkaVolterra equations.