Macro ode
ode!() { /* proc-macro */ }Expand description
Build an equation::ODE while inferring nstates, ndrugs and
nout from the maximum literal bracket-indices used in the closures.
§Fields (any order, comma-separated)
| Field | Required | Signature |
|---|---|---|
diffeq | yes | |x, p, t, dx, bolus, rateiv, cov| { … } |
out | yes | |x, p, t, cov, y| { … } |
init | no | |p, t, cov, x| { … } |
lag | no | |p, t, cov| lag! { … } |
fa | no | |p, t, cov| fa! { … } |
§Inference rules
- nstates = max literal index of the state / derivative vectors + 1
- ndrugs = max literal index of bolus / rateiv vectors + 1
- nout = max literal index of the output vector + 1
Parameter names are taken from the closure signatures so you can name them
however you like. Only literal integer indices (e.g. x[2]) are
detected; computed indices require manual .with_nstates() etc.
§Example
ⓘ
use pharmsol::prelude::*;
let ode = ode! {
diffeq: |x, p, _t, dx, b, rateiv, _cov| {
fetch_params!(p, ke, kcp, kpc, _v);
dx[0] = rateiv[0] + b[0] - ke * x[0] - kcp * x[0] + kpc * x[1];
dx[1] = kcp * x[0] - kpc * x[1];
},
out: |x, p, _t, _cov, y| {
fetch_params!(p, _ke, _kcp, _kpc, v);
y[0] = x[0] / v;
},
};
// Inferred: nstates=2, ndrugs=1, nout=1