This building block describes a flow between compartments.
flow(definition, from = NA_character_, to = NA_character_)
definition | Equation describing the flow |
---|---|
from | Name of the source compartment (NA for an inflow without source) |
to | Name of the sink compartment (NA for an outflow without sink) |
A building block of type 'flow'
Flows define the connections between compartments and the equations according to which exchanges occur.
The first function argument is the flow equation. It is defined using R formulas that can start with the tilde ~
operator and do not
need to have a left-hand side (i.e., ~k0
is a valid flow definition).
Flow equations can contains the special variables A
and C
which can be used to refer to the amount and concentration in the compartment specified via
the from=
argument. For example, the following code creates a flow building block describing the first-order transfer from the depot to the central
compartment
flow(~ka*A, "depot", "central")
When the model is rendered, A
and C
will get replaced with the corresponding compartment reference. assemblerr will raise an error if A
or C
are used
without specifying the from=
compartment (such as in an inflow).
The connection between compartments can be specified using the from=
and to=
arguments of the function. Setting either from=
or to=
to NA
allows
the definition of in and outflows without a source or sink. Setting both arguments to NA
results in error.
When flows are rendered they are converted to ordinary differential equations (ODEs). The connection between compartments together with the flow equations allow assemblerr to determine whether an analytic solution can be generated. This automatic optimization of differential equations can be disabled via the rendering options.
# one-compartment model with first-order elimination m <- model() + prm_log_normal("v") + prm_log_normal("cl") + compartment("central", volume = ~v) + flow(declaration(~cl*C), from = "central") + obs_additive(~C["central"]) # an analytic solution is generated render(m)#> $PROBLEM #> $INPUT ID TIME DV AMT #> $DATA data.csv IGNORE=@ #> $SUBROUTINES ADVAN1 TRANS2 #> $PK #> V = THETA(1) * EXP(ETA(1)) #> CL = THETA(2) * EXP(ETA(2)) #> $ERROR #> Y = A(1)/V + EPS(1) #> $ESTIMATION METHOD=COND MAXEVAL=999999 #> $THETA (0, 1, Inf) ; POP_V #> $THETA (0, 1, Inf) ; POP_CL #> $OMEGA 0.1 ; IIV_V #> $OMEGA 0.1 ; IIV_CL #> $SIGMA 1; RUV_ADD# one-compartment model with Michaelis-Menten elimination m2 <- model() + prm_log_normal("v") + prm_log_normal("vmax") + prm_no_var("km") + compartment("central", volume = ~v) + flow(declaration(~vmax*C/(km+C)), from = "central") + obs_additive(~C["central"]) # an ODE is generated render(m2)#> $PROBLEM #> $INPUT ID TIME DV AMT #> $DATA data.csv IGNORE=@ #> $SUBROUTINES ADVAN13 TOL=6 #> $MODEL COMP=(CENTRAL) #> $PK #> V = THETA(1) * EXP(ETA(1)) #> VMAX = THETA(2) * EXP(ETA(2)) #> KM = THETA(3) #> $DES #> DADT(1) = -(VMAX * (A(1)/V)/(KM + A(1)/V)) #> $ERROR #> Y = A(1)/V + EPS(1) #> $ESTIMATION METHOD=COND MAXEVAL=999999 #> $THETA (0, 1, Inf) ; POP_V #> $THETA (0, 1, Inf) ; POP_VMAX #> $THETA (0, 1, Inf) ; POP_KM #> $OMEGA 0.1 ; IIV_V #> $OMEGA 0.1 ; IIV_VMAX #> $SIGMA 1; RUV_ADD