Skip to content

How do I reset the solver upon a step input

Max Schelker edited this page Aug 29, 2016 · 2 revisions

The ODE solver employed in D2D uses automatic step size control. Although this typically allows for efficient numerical simulation of the initial value problem, this can be problematic when the inputs are discontinuous. In such cases, the simulation may skip over aforementioned events. Rather than limiting the maximum step size manually, it is better specify such events. This signals the solver to only integrate up to the point of the event and then re-initialize the integrator to perform the remainder of the simulation.

In D2D, there are two ways to deal with discontinuous input functions. One is via the event system (see [Advanced events and pre-equilibration](Advanced events and pre-equilibration)), the other is via input functions. The former is more flexible, while the latter is typically easier to use. This wiki page will show the required information to be able to use the latter.

For this purpose, we use the following model:

DESCRIPTION
"Simple pulse test"

PREDICTOR
t               T   min         time	0	200

COMPARTMENTS
cyt             V   pl          vol.    1

STATES
stateA          C   nmol/l      conc.   cyt     1

INPUTS
pulse           C   nmol/l      conc.   "step2(t,10,50,0,100,10)"
        
REACTIONS
                ->  stateA      CUSTOM	"pulse"
stateA          ->              CUSTOM  "1.0"

DERIVED

OBSERVABLES
A_obs           C  au   conc.   1  1    "stateA"
                
ERRORS
A_obs           "1.0"

CONDITIONS
init_stateA     "0"

Now compile, simulate and plot the system using the following commands:

arInit;
arLoadModel('pulseTest');
arCompileAll;
arPlot;

without.png

From the plot it can be concluded that the simulation completely skips over the simulation. To avoid this, add events at the points of discontinuity. In order to automatically scan for events in the inputs, invoke arFindInputs. This command will scan the model inputs for step1 and step2 commands and add events at these points.

arFindInputs;
arPlot;

with.png

From the plot, it can be concluded that the events are now properly taken into account. Note that this approach only accounts for discontinuities due to step functions in the inputs. Other types of discontinuities are not covered by arFindInputs and require use of the actual event system described in [Advanced events and pre-equilibration](Advanced events and pre-equilibration).

Clone this wiki locally