Use of Basic Elements II – Ordinary Differential Equation System

This second example shall illustrate the formulation of an ordinary differential equation system (ODE system) in MOSAICmodeling. This example is the “Oregonator”, a theoretical model for a type of autocatalytic reactions. In this example, we will use the publication by D’Ambrosio et al. (2018), DOI: 10.1007/s10910-018-0922-5, as basis.

Model description

The model consists of three differential equations:

 \frac{\mathrm{d}X}{\mathrm{d}t} = k_1 \cdot A \cdot Y - k_2 \cdot X \cdot Y + k_3 \cdot A \cdot X - 2 \cdot k_4 \cdot X^2 \\[2ex] \frac{\mathrm{d}Y}{\mathrm{d}t} = - k_1 \cdot A \cdot Y - k_2 \cdot X \cdot Y + f \cdot k_5 \cdot A \cdot Z \\[2ex] \frac{\mathrm{d}Z}{\mathrm{d}t} = k_3 \cdot A \cdot X - k_5 \cdot A \cdot Z.

Therein, X, Y, and Z are the concentrations of relevant intermediates of this reaction network, i.e., \mathrm{HBrO}_2, \mathrm{Br}^-, and Ce(IV). A is the concentration of \mathrm{BrO}_3^-, a constant. All k_k and f are parameters of the kinetics. For a more thorough discussion of the underlying physics, please consult the literature on the oregonator. We want to focus on the model implementation here.

Model workflow

Notation

We beginn by setting up the notation. Therefore, perform the following steps:

  1. Go to the Notation tab in the “Model” section
  2. Add a description of your notation
  3. Add the base names below by clicking on “+ Name” at the bottom, entering these names, adding a description of the variable and confirming it
  4. Go to the Indicies tab and add the index below
  5. Once you have added all variables and symbols, click on “Save” at the top of the editor and save your notation at a suitable location in your folder structure
Base names
  • A, concentration of \mathrm{BrO}_3^- in mol/L
  • f, Stoichiometric factor
  • k, kinetic factor in various units
  • t, time in s
  • X, concentration of \mathrm{HBrO}_2 in mol/L
  • Y, concentration of \mathrm{Br}^- in mol/L
  • Z, concentration of Ce(IV) in mol/L
Indices
  • k, Index of kinetic factors 1..NK

The notation of this example has ID 182866.

Equations

Go to the Equation tab. Proceed as follows:

  1. Load the notation you just created
  2. Add an informative description of the current equation
  3. Type the first model equation in LaTeX style into the window MosaicTex. For the differential operator, you must use \diff{Var}{IndependentVariable}
  4. Save the equation at a suitable location in your folder structure
  5. Click on “New” at the top of the editor and repeat the steps 1 and 2
  6. Enter the second model equation
  7. Save this second equation as well

The three equations are available in MOSAICmodeling with the IDs 182867, 182868, and 182869.

Equation system

Now, we will combine our equations to an equation system. To this end, go to the Equation System tab and carry on as described below:

  1. Load your notation from above
  2. Add a suitable description
  3. Go to the tab Connected Elements and click on “+ EQU/EQS” at the bottom of the editor
  4. In the opening popup window, select your three equations and confirm (you can also add them one-by-one). They will then appear in the overview of connected elements
  5. Save your equation system

The equation system has ID 182870 within MOSAICmodeling.

Simulation workflow

Start by going to the “Simulation” section of MOSAICmodeling.

Equation system

Go to the tab Equation System and select your newly saved equation system from above.

Indexing

Proceed to the tab Indexing. Specify the maximum value of the index for the kinetic factors, i.e., 5. Click on Confirm Index Data.

Specification

Go to the tab Specifications and then select the tab Variables. Proceed as follows:

  1. Add a helpful description of the simulation
  2. In the specification window, you can see all possible variable classifications. Select ALL VARIABLES at the top. You should now see the four variables that are part of your model
  3. Change the entry in the column Type for A, f and k_1k_5 to Design Value
  4. Change the type classification of the variables X, latex Y$, and Z to state variable.  The variable t should already be classified as differential value. Your degree of freedom should now be zero
  5. Assign the values given in Table 1 to the four variables
  6. On the right side, set 2000.0 as end point for the differential variable $latex $
  7. Save your variable specification by clicking on the “Save” button above the calculation of the degrees of freedom
  8. Save your simulation by clicking on “Save” at the top of the editor

The simulation is available with ID 182871. The associated variable specification has ID 182872. Note that the values specificed for the state variables are used as initial conditions.

NameDescriptionValue / Initial condition
AConcentration of \mathrm{BrO}_3^- in mol/L0.06
fStoichiometric factor1.0
k_{k=1}Kinetic parameter1.34
k_{k=2}Kinetic parameter1.6 \cdot 10^9
k_{k=3}Kinetic parameter8.0 \cdot 10^3
k_{k=4}Kinetic parameter4.0 \cdot 10^7
k_{k=5}Kinetic parameter1.0
XConcentration of \mathrm{HBrO}_2 in mol/L7.8 \cdot 10^{-9}
YConcentration of \mathrm{Br}^- in mol/L8.502 \cdot 10^{-8}
ZConcentration of Ce(IV) in mol/L0.0190464
tDifferential variable time in s0
Table 1: Overview of design values and initial conditions.

Evaluation

Finally, we want to determine the solution of our model:

  1. Go to the Evaluation tab, then go to the Code Generation tab
  2. Select your preferred language specification, e.g., Matlab ODE std
  3. Click on Generate Code
  4. Go to the tab View Code and copy the code into your respective modeling environment, e.g., Matlab
  5. Execute the code
  6. You will notice that (i) the solution requires a significant amount of time, and (ii) the solution does not fluctuate at all. The long computational time is caused by ODE45, which is not suitable for stiff systems such as the ODE system in this example. Therefore, replace the following line with the one given below that
% [X,Y] = ode45(@(X,Y)calculateDifferentials(X,Y,PARAMS),X_INTERVAL,Y_INIT');
[X,Y] = ode23s(@(X,Y)calculateDifferentials(X,Y,PARAMS),X_INTERVAL,Y_INIT');

You will now receive a solution must faster, but without any fluctuation. The problem here is the accuracy of the applied solver. Now, change the respective options as shown below:

% [X,Y] = ode45(@(X,Y)calculateDifferentials(X,Y,PARAMS),X_INTERVAL,Y_INIT');
% [X,Y] = ode23s(@(X,Y)calculateDifferentials(X,Y,PARAMS),X_INTERVAL,Y_INIT');
[X,Y] = ode23s(@(X,Y)calculateDifferentials(X,Y,PARAMS),X_INTERVAL,Y_INIT',odeset('RelTol',1e-7,'AbsTol',1e-7));

Execute the code again. You should now observe a fluctuation of the three concentrations. This illustrates that – although MOSAICmodeling (or any other modeling tool) can help you with setting up the model equations – it does not absolve you from knowing about numerical issues and how to address them in the tool of your preference.