flow: Flow between compartments

View source: R/compartment.R

flowR Documentation

Flow between compartments

Description

This building block describes a flow between compartments.

Usage

flow(definition, from = NA_character_, to = NA_character_)

Arguments

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)

Details

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.

Value

A building block of type 'flow'

Examples

# 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)

# 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)

sebastianueckert/assemblerr documentation built on Sept. 30, 2022, 9:12 a.m.