Macro ode
macro_rules! ode {
($($body:tt)*) => { ... };
}Expand description
Define an ODE (ordinary differential equation) model.
This is the primary entry point for building pharmacometric ODE models.
The macro generates and validates an ODE model and automatically generates its metadata
(parameter names, state labels, output labels, and inferred input routes).
Write bolus[oral] * oral_scale and infusion[iv] * iv_scale in the derivative
RHS. The macro uses the existing simulator input vectors; no routes or fa
field is needed. Use lag for delayed bolus inputs.
§Fields
| Field | Required | Description |
|---|---|---|
name | yes | Model name ("my_model") |
params | yes | Parameter identifiers [ka, ke, v] |
covariates | no | Covariate identifiers [wt, age] |
states | yes | State identifiers [gut, central] |
outputs | yes | Output identifiers [cp] |
diffeq | yes | Closure |x, p, t, dx, cov| { … } writing derivatives into dx |
lag | no | Closure returning route‑specific lag times via lag! { route => expr } |
init | no | Closure setting initial state values |
out | yes | Closure |x, p, t, cov, y| { … } mapping states to outputs |
crate | no | Escape hatch to override the resolved pharmsol path, e.g. "my_vendor::pharmsol" |
§Example
ⓘ
let model = ode! {
name: "one_cmt_iv",
params: [ke, v],
states: [central],
outputs: [cp],
diffeq: |x, _p, _t, dx, _cov| {
dx[central] = infusion[iv] - ke * x[central];
},
out: |x, _p, _t, _cov, y| {
y[cp] = x[central] / v;
},
};