Skip to main content

ode

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

FieldRequiredDescription
nameyesModel name ("my_model")
paramsyesParameter identifiers [ka, ke, v]
covariatesnoCovariate identifiers [wt, age]
statesyesState identifiers [gut, central]
outputsyesOutput identifiers [cp]
diffeqyesClosure |x, p, t, dx, cov| { … } writing derivatives into dx
lagnoClosure returning route‑specific lag times via lag! { route => expr }
initnoClosure setting initial state values
outyesClosure |x, p, t, cov, y| { … } mapping states to outputs
cratenoEscape 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;
    },
};