Flows define the connections between compartments and the equations according to which exchanges occur.
Flow equations
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).
Compartment connections
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.
Conversion to differential equations
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.