From Meal State to a Simulation Rule
A PBPK model must turn a description such as “fasting before the meal, fed afterward” into a rule that can be evaluated throughout a simulation. The key implementation requirement is that a change in gastric emptying rate changes how quickly drug leaves the stomach, not how much drug exists. At a meal-state transition, the gastric amount remains continuous unless a separate, explicitly modelled input or removal occurs.
This tutorial represents drug leaving the stomach as transfer to a cumulative bookkeeping amount. It does not specify how the receiving amount is subsequently handled. That separation makes it possible to test the gastric emptying implementation on its own: every milligram leaving the gastric amount must appear in the cumulative emptied amount.
The first-order assumption means that, at any instant, the amount emptying per unit time is proportional to the amount currently in the stomach. The model also assumes that the gastric amount is represented as a well-mixed amount for purposes of this transfer, and that the selected rate is nonnegative. The rate may depend on meal state or on time since a meal, but it must be defined unambiguously at every time the solver evaluates the equations.
A simple state-dependent implementation uses a fasting rate \(k_f\) and a fed rate \(k_d\). A state variable \(S(t)\) identifies which condition applies, and the rate is selected by a rule such as \(k_g(t)=k_f\) when \(S(t)\) is fasting and \(k_g(t)=k_d\) when \(S(t)\) is fed. More elaborate fed-state functions can vary continuously with time after a meal. The implementation principle is the same: determine one rate at the current simulation time, then use it consistently in both transfer equations.
State Changes Without Amount Resets
Meal times are event times: they may change the rule used to calculate \(k_g(t)\). They do not, by themselves, add or remove drug from the stomach. For example, a meal at time \(t_m\) may switch the model from \(k_f\) to \(k_d\). At that instant the amount immediately before and after the switch satisfies \(A_g(t_m^+)=A_g(t_m^-)\). The rate can jump even though the amount does not.
A robust implementation records the event time, updates the meal-state indicator or the parameters of the fed-state function, and continues integrating from the current \(A_g\). It must not reinitialize \(A_g\) to the administered dose, set it to zero, or transfer an arbitrary fraction merely because the state changed. A new oral dose, if present, is a distinct input event: it increases \(A_g\) by the dose amount and must be included in the model’s administered-mass ledger.
Specify meal-state transitions and the rate rule for each state, including any dependence on elapsed time since a meal.
Set \(A_g\) from the dose or initial condition. Initialize \(E\) to the cumulative amount already emptied, commonly zero for a newly initialized dose.
At each solver evaluation, calculate \(k_g(t)\), then use \(k_g(t)A_g(t)\) as the outflow from \(A_g\) and the inflow to \(E\).
At a state event, update the rate rule without resetting the amounts. Check that gastric drug plus cumulative emptied drug equals initial drug plus any administered doses.
When the rate has a discontinuity at a known meal time, a solver can be stopped at that time and restarted with the new rate rule. An event-aware solver can instead locate and process the discontinuity. Either approach should use the pre-event rate up to the event and the post-event rule afterward. A solver need not assign a special physical meaning to the derivative at the single instant of transition; the amount trajectory is governed by the rates on either side.
Why the Mass Ledger Holds
The conservation check follows directly from the paired equations. Adding them cancels the transfer term, regardless of whether the selected rate is fasting, fed, constant, or time-varying:
Therefore \(A_g(t)+E(t)\) is constant between external inputs and removals. Taking \(A_g(0)\) to include any doses administered at \(t=0\), the corresponding expected ledger is \(A_g(t)+E(t)=A_g(0)+E(0)+\sum_{0<t_j\leq t}D_j\), provided there are no other sources or sinks in this two-amount accounting system.
For an interval \([t_0,t_1]\) with an integrable, nonnegative rate, the gastric amount also has a useful solution. The linear equation \(A_g'=-k_g(t)A_g\) can be multiplied by the integrating factor \(\exp\left[\int_{t_0}^{t}k_g(u)\,du\right]\), which gives the solution for any initial amount, including zero:
The amount emptied over that interval is the starting gastric amount minus the ending amount, so \(E(t_1)-E(t_0)=A_g(t_0)-A_g(t_1)\). This relation also shows why changing the rate affects the trajectory but does not create a discontinuity in the amount: the rate changes the accumulated integral after the event, not the value already present at the event.
Worked Example: A Fasting-to-Fed-to-Fasting Schedule
Hypothetical setup. A 100 mg dose is initially in the stomach. The rate is \(k_f=0.80\) h\(^{-1}\) from time 0 to 1 h, \(k_d=0.20\) h\(^{-1}\) from 1 to 4 h, and \(k_f=0.80\) h\(^{-1}\) from 4 to 5 h. Assume no other inputs or losses. Calculate the gastric and cumulative emptied amounts at 1, 4, and 5 h.
From 0 to 1 h, the constant-rate solution is \(A_g(1)=100\exp[-(0.80)(1)]=100\exp(-0.80)=44.93\) mg. Thus \(E(1)=100-44.93=55.07\) mg.
The meal-state change at 1 h does not reset the 44.93 mg remaining. Over the next 3 h, \(A_g(4)=44.93\exp[-(0.20)(3)]=44.93\exp(-0.60)=24.66\) mg. Hence \(E(4)=100-24.66=75.34\) mg.
At 4 h the rate returns to the fasting value, while \(A_g\) remains 24.66 mg at the transition. Over the next hour, \(A_g(5)=24.66\exp(-0.80)=11.08\) mg, and \(E(5)=100-11.08=88.92\) mg. At each reported time, gastric plus emptied amount is 100 mg, up to rounding.
Implementing a Time-Varying Fed Rate
A fed-state rate need not be a single constant. For example, a specified function may make the rate approach a baseline as time passes after a meal. The function and its parameters should be evaluated from the current simulation time and meal-event history, rather than applied as an informal adjustment to the amount. The continuous-time solution uses the integral of that rate over the interval.
Worked Example: A Fed Rate That Changes With Time
Hypothetical setup. Immediately after a meal at time 0, let \(A_g(0)=80\) mg. For the next 2 h, suppose the fed rate is \(k_g(t)=0.15+0.45\exp(-0.50t)\) h\(^{-1}\), where \(t\) is in hours. Find the amount remaining and the amount emptied at 2 h, assuming \(E(0)=0\).
First calculate the integrated rate:
Substituting into the time-varying-rate solution gives \(A_g(2)=80\exp(-0.8689)=33.55\) mg. The amount emptied is \(E(2)=80-33.55=46.45\) mg. The two amounts sum to 80.00 mg after rounding. In a numerical model, the rate function must be used for both sides of the transfer at every solver evaluation; calculating the fed function only for \(A_g\) but using a different rate for \(E\) would not implement this model.
Numerical Checks and Failure Modes
A simulation generally approximates the continuous equations using finite steps and a numerical solver. A simple Euler step illustrates the bookkeeping requirement. For step size \(\Delta t\), a rate evaluated at the beginning of the step gives the update
The increments cancel exactly in the discrete ledger when they use the same transfer amount. Higher-order solvers may calculate intermediate rates and states, but the same principle applies: the flux removed from one state must be the flux added to the other. In addition, the numerical solution should be checked for plausible nonnegative amounts and convergence as tolerances or step sizes are tightened.
Worked Example: A Discrete Transfer and an Inconsistent Update
Hypothetical setup. At the start of a 0.5 h step, \(A_g=50\) mg and \(E=0\) mg. The selected rate is \(0.40\) h\(^{-1}\). Use one explicit Euler step, then consider what happens if the receiving ledger is mistakenly updated using \(0.40\) h\(^{-1}\) while the gastric amount is updated using \(0.10\) h\(^{-1}\).
With a consistent rate, the transfer is \((0.40)(50)(0.5)=10\) mg. The update is \(A_g=50-10=40\) mg and \(E=0+10=10\) mg; their sum remains 50 mg.
With the inconsistent rates, the gastric update transfers \((0.10)(50)(0.5)=2.5\) mg, so \(A_g=47.5\) mg, while the ledger is incorrectly increased by \((0.40)(50)(0.5)=10\) mg, giving \(E=10\) mg. The sum is 57.5 mg, an artificial gain of 7.5 mg. This discrepancy is not a property of fed-state physiology; it is an implementation error caused by using different transfer terms.
A useful diagnostic is the residual \(R(t)=A_g(t)+E(t)-A_g(0)-E(0)-\sum_{0<t_j\leq t}D_j\). In the ideal model, \(R(t)=0\). A numerical simulation should keep the residual close to zero within the solver’s expected numerical accuracy. A growing residual can point to inconsistent rate use, an incorrect sign, a duplicated or omitted transfer, an unrecorded input or sink, or inaccurate numerical integration. Check the event and dose ledger as well as the equations.
Importantly, a missed state event alone does not necessarily make the mass ledger fail. If the simulation uses the same selected rate in both equations, then \(d(A_g+E)/dt=0\) for any rate, even if that rate is the wrong one because the meal transition was missed. The ledger may pass while the predicted gastric trajectory is inaccurate. Compare the simulated state history and rate history against the intended schedule to detect this separate trajectory error.
Choosing an Implementation and Knowing Its Limits
A piecewise-constant fasting/fed model is straightforward when the state schedule and rates are specified, and it makes transitions easy to inspect. A time-varying fed function can represent a changing rate after a meal, but it requires a clearly defined time origin and parameterization. The earlier material on solid and liquid emptying time courses, lagged models, and transit-time distributions describes alternative representations of emptying profiles. Those representations are not interchangeable implementation details: each implies a different rate or time-course structure and should be coded according to its own definition.
For any representation, distinguish the physiological rule from the numerical update. A model may pass the mass ledger and still use an incorrect meal schedule, rate, or function. Conversely, a correct schedule cannot compensate for an equation implementation that loses or duplicates mass. Inspect both the rate selected at each time and the amount ledger.
This two-amount formulation verifies gastric transfer only. It does not determine intestinal absorption, downstream drug input, or systemic concentration. Those require additional compartments and processes. Likewise, first-order emptying is a modelling assumption; a real formulation or meal may require another representation. The mass check remains valuable in larger models, but the ledger must then include all destinations, inputs, and losses being assessed.
Common Mistakes
- Resetting the gastric amount at a meal. A state change selects a new rate; it does not replace the amount already present.
- Using different rates for donor and recipient equations. This breaks the cancellation of transfer terms and can create or destroy drug in the ledger.
- Treating a passing ledger as proof of a correct fed-state trajectory. A missed event can leave the ledger intact if the same rate is used in both equations; verify the state and rate histories separately.
- Confusing transfer with elimination. Drug emptied from the stomach has left \(A_g\), but it has not vanished from the mass ledger. Record it in \(E\) or in an explicitly modelled receiving compartment.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A model has \(A_g=30\) mg and \(E=20\) mg at a meal event, with no dose at that time. What should the two amounts be immediately after the rate changes?
- With constant \(k_g=0.30\) h\(^{-1}\), \(A_g(0)=60\) mg, and \(E(0)=0\), calculate both amounts after 2 h.
- Why can a missed meal-state event produce a wrong gastric trajectory without causing a mass-ledger residual?
- In an Euler step, \(A_g\) decreases by 4 mg but \(E\) increases by 5 mg. What is the change in the ledger total, and name one likely implementation problem.
Solutions. (1) The amounts remain \(A_g=30\) mg and \(E=20\) mg at the instant of the rate change; the total remains 50 mg. (2) \(A_g(2)=60\exp[-(0.30)(2)]=60\exp(-0.60)=32.93\) mg, so \(E(2)=60-32.93=27.07\) mg. (3) With the same rate in both equations, the transfer terms cancel for any selected rate. A missed event can select the wrong rate and therefore change the trajectory, while still preserving the sum. (4) The ledger total increases by \(5-4=1\) mg. A likely problem is that the donor and recipient equations used different transfer amounts, or that numerical updates were not paired consistently.