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, route declarations).
§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] |
routes | no | Route declarations [bolus(oral) -> gut, infusion(iv) -> central] |
diffeq | yes | Closure |x, p, t, dx, cov| { … } writing derivatives into dx |
lag | no | Closure returning route‑specific lag times via lag! { route => expr } |
fa | no | Closure returning bioavailability fractions |
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],
routes: [infusion(iv) -> central],
diffeq: |x, _p, _t, dx, _cov| {
dx[central] = -ke * x[central];
},
out: |x, _p, _t, _cov, y| {
y[cp] = x[central] / v;
},
};