Please look at page 45 of the Phoenix 1.4 Modeling Language Reference Guide (Help>Documents>...);
Modeling discontinuous events
There are many kinds of models involving discrete time-based events at which discontinuous changes can occur in a model. The following is a partial example of an entero-hepatic reflux model.
1 deriv(a = -a*k10 - a*k1b + g*kg1)
# central cpt
2 deriv(b = a*k1b - qbg)
# bile cpt
3 deriv(g = qbg - g*kg1)
# gut cpt
4 double(qbg)
#qbg is flow rate from bile to gut
5 stparm(tCycle=..., tReflux=...)
# times are parameters
# introduce the time sequence:
6 double(i)
7 sequence{
8 i = 0;
9 while(i<10){
10 i = i + 1;
11 qbg = 0;
12 sleep(tCycle - tReflux);
13 qbg = (b/tReflux);
14 sleep(tReflux);
15 qbg = 0;
16 }
17 }
The model has three compartments: a for plasma, b for bile, and g for gut. Normally the compound flows from gut to plasma and from plasma to bile, as well as flowing through the normal elimination path. There is also a flow from bile to gut, which is the reflux path. This is modeled as a zero-order flow of rate qbg. The flow is turned on and off to model the reflux.
Lines 1-3 give the differential equations for the three compartments. The variable qbg is a variable representing the flow rate from bile to gut, and it is initially zero.
Line 4 declares a variable, qbg, which will be used in some of the equations and statements.
Line 5 designates that there are two structural parameters giving the cycle time between reflux events (tCycle) and the duration (tReflux) of each event.
Line 6 declares a variable, i, which will be used in some of the equations and statements.
Lines 7-17 are grouped with the sequence keyword. This introduces timesequenced procedure into the model.
Line 8 sets the initial value for the variable i to 0.
Line 9 groups the next 6 statements into a loop that will repeat up to 10 times.
Line 10 adds one to the value of i (number of iterations).
Line 11 sets the initial value for the variable qbg to 0.
Line 12 allows tCycle - tReflux time units to pass.
Line 13 turns on the reflux by setting qbg to the rate necessary to empty the bile compartment within duration tReflux.
Lines 14-15 say to wait for tReflux time units, and then turn off the flow, after which the cycle repeats.