Tutorials › Physiologically-Based Pharmacokinetics (PBPK) › Mass-Balance and Flux-Continuity Diagnostics

Compartmental Absorption and Transit Models · Tutorial 233 of 799

Mass-Balance and Flux-Continuity Diagnostics

Use local and global mass-balance checks to distinguish a model inconsistency from a numerical integration problem.

Intermediate 11 min read

What You'll Learn

  • Write a total mass balance for gut-segment amounts, absorbed mass, and material leaving the modeled gut.
  • Check that each intersegment transfer is the same outgoing and incoming flux.
  • State the regularity and boundary conditions needed for continuous-time nonnegative states.
  • Compare integrated absorption rates with the model’s cumulative absorbed-mass state.
  • Use residuals and numerical checks to locate bookkeeping and solver problems.
  • Distinguish diagnostics that test conservation from checks that test the model’s biological assumptions.

Why Audit Mass and Fluxes?

A sequential absorption model moves drug between states and out of the modeled gut, while absorption transfers drug into a cumulative absorbed amount. These transfers should reconcile: material leaving one segment through an interface must enter the next, and absorbed material must agree with the integral of the absorption rate. A model can produce a smooth concentration or amount profile and still violate these basic accounting rules because of a missing term, duplicated flux, inconsistent units, or numerical error.

The checks in this tutorial apply to a model whose gut is represented by \(N\) sequential segments. They do not determine whether the chosen segment structure or permeability assumptions are biologically correct. They test whether the implemented flows and states obey the mass accounting implied by the model.

Set Up the Accounting Equations

Let \(A_i(t)\) be the drug amount in segment \(i\), in mg, for \(i=1,\ldots,N\). Let \(u_i(t)\) be any external input directly into segment \(i\), in mg/h. Let \(J_i(t)\) be the flux from segment \(i\) to segment \(i+1\), in mg/h, for \(i=1,\ldots,N-1\). Let \(J_N(t)\) be the flux leaving the last modeled segment, and define \(J_0(t)=0\). Let \(R_i(t)\) be the absorption rate from segment \(i\), also in mg/h. The segment balance is

$$ \frac{dA_i}{dt}=u_i+J_{i-1}-J_i-R_i,\qquad i=1,\ldots,N. $$

This equation assumes that the listed inputs, intersegment transfers, absorption rates, and terminal outflow account for every change in each segment amount. If the formulation model contains a solid or other dose-containing state, that material must also be included in the total inventory, or its transfer into the segment model must be represented as an external input. Otherwise, a balance over the gut-segment states alone will appear to lose or gain mass.

Define cumulative absorbed mass \(B(t)\) and cumulative mass leaving the modeled gut \(F_{\mathrm{out}}(t)\) by

$$ \frac{dB}{dt}=\sum_{i=1}^{N}R_i,\qquad \frac{dF_{\mathrm{out}}}{dt}=J_N. $$

Both cumulative quantities have units of mg. They are bookkeeping states: \(B\) records all absorption through time, while \(F_{\mathrm{out}}\) records the material that has exited the modeled gut.

Definition: A mass-balance residual at time \(t\) is the difference between the accounted mass at \(t\) and the initial mass plus all external input through \(t\). For the states above,
$$ r_{\mathrm{MB}}(t)= \sum_{i=1}^{N}A_i(t)+B(t)+F_{\mathrm{out}}(t) -\sum_{i=1}^{N}A_i(0)-B(0)-F_{\mathrm{out}}(0) -\int_0^t\sum_{i=1}^{N}u_i(s)\,ds. $$

In an exact solution, \(r_{\mathrm{MB}}(t)=0\). In a numerical solution, it should be small relative to the mass scale and consistent with the solver’s accuracy. A residual is informative only if the inventory includes all relevant dose-containing states and every boundary input and output is counted once.

Why the Total Balance Holds

Sum the segment equations over \(i\). Each internal interface \(J_i\), for \(i=1,\ldots,N-1\), appears once as an outgoing term \(-J_i\) and once as an incoming term \(+J_i\). The two terms cancel. The \(J_0\) term is zero, and the only remaining transit outflow is \(-J_N\). Thus

$$ \frac{d}{dt}\sum_{i=1}^{N}A_i = \sum_{i=1}^{N}u_i-J_N-\sum_{i=1}^{N}R_i. $$

Adding \(dB/dt=\sum_i R_i\) and \(dF_{\mathrm{out}}/dt=J_N\) gives

$$ \frac{d}{dt}\left(\sum_{i=1}^{N}A_i+B+F_{\mathrm{out}}\right) =\sum_{i=1}^{N}u_i. $$

Integrating this equality from \(0\) to \(t\) gives the mass-balance residual formula and shows why absorption and terminal outflow must be included when checking total dose recovery. Internal transfers redistribute mass; they cannot change the total.

Worked Example: Checking Total Dose Recovery

Suppose a hypothetical model starts with a 100 mg dose in its modeled gut states and has no external input after time zero. At \(t=8\) h, the segment amounts are \(A_1=8\) mg and \(A_2=5\) mg. The cumulative absorbed mass is \(B=72\) mg, and cumulative mass leaving the gut is \(F_{\mathrm{out}}=15\) mg. Assume the initial cumulative states were both zero.

The accounted mass at 8 h is

$$ A_1+A_2+B+F_{\mathrm{out}} =8+5+72+15=100\ \mathrm{mg}. $$

There was no later input, so the initial mass plus cumulative input is also 100 mg. Therefore \(r_{\mathrm{MB}}(8\ \mathrm{h})=100-100=0\) mg: the reported states recover the full dose. This check does not show that the regional absorption pattern is correct; it shows only that these amounts reconcile with the stated dose and boundary flows.

Check Continuity at Every Interface

An interface is one physical transfer from a donor segment to its adjacent receiver. The same flux must be subtracted from the donor and added to the receiver. If the implementation calculates separate outgoing and incoming quantities, define the interface discrepancy

$$ e_i(t)=J_i^{\mathrm{out}}(t)-J_i^{\mathrm{in}}(t),\qquad i=1,\ldots,N-1. $$

The discrepancy should be zero, up to numerical precision. The two quantities have the same units, mg/h, and must refer to the same interface and time. If one is a rate and the other is an amount transferred over a time step, they cannot be compared until the rate has been integrated over that step.

Worked Example: Finding a Discontinuous Interface Flux

Consider two hypothetical segments. The flux from segment 1 is \(J_1^{\mathrm{out}}=0.40A_1\), with \(A_1=30\) mg. The receiving equation for segment 2 has been coded to use \(J_1^{\mathrm{in}}=11.5\) mg/h. The other rates are \(R_1=2\) mg/h, \(J_2=0.25A_2\) with \(A_2=20\) mg, and \(R_2=3\) mg/h. There are no direct inputs.

The donor-side flux is

$$ J_1^{\mathrm{out}}=0.40\ \mathrm{h}^{-1}\times30\ \mathrm{mg}=12\ \mathrm{mg/h}. $$

The interface discrepancy is \(e_1=12-11.5=0.5\) mg/h, so the transfer is not continuous in the implementation. The coded rates imply \(dA_1/dt=-12-2=-14\) mg/h and \(dA_2/dt=11.5-5-3=3.5\) mg/h. Their combined derivative is \(-10.5\) mg/h. If the donor’s 12 mg/h outflow were also the receiver’s inflow, the combined derivative would instead be \(-10\) mg/h. The extra loss of 0.5 mg/h is exactly the interface discrepancy. The correction is to use the same \(J_1\) in both equations, not to adjust the absorption rates to hide the imbalance.

Nonnegative States: Conditions and Numerical Checks

Amounts and cumulative absorbed mass should not become negative when the model starts with nonnegative amounts and uses nonnegative inputs and rates. For the continuous-time model, however, the boundary check needs more than the statement that an outgoing rate vanishes at zero. A sufficient standard setup is that the state equation \(dx/dt=f(t,x)\) has a vector field that is measurable in time, locally Lipschitz in the state \(x\) (uniformly on compact state and time sets), and has a unique solution while it exists. In addition, for every nonnegative state with \(x_i=0\), require \(f_i(t,x)\geq0\) for almost every \(t\). Under these conditions, the nonnegative orthant is forward invariant: a solution starting there remains there for as long as it exists.

For a gut segment at \(A_i=0\), nonnegative inputs and inflows, together with an outflow and absorption rate that are zero at zero amount, give \(dA_i/dt\geq0\). For example, \(J_i=k_iA_i\) and \(R_i=k_{a,i}A_i\), with nonnegative rate constants, satisfy the zero-at-zero condition. The regularity and uniqueness assumptions matter: a boundary derivative condition alone is not enough to guarantee invariance for an irregular vector field.

Numerical methods can still produce negative amounts even when the continuous model preserves nonnegativity. Inspect the minimum state over time and compare it with the scale of the amount, the solver’s tolerances, and the time-step behavior. A small negative value may be numerical error; a large or persistent negative value can indicate an incorrect flux sign, an inconsistent state update, or steps that are too large. Clipping negative values to zero may conceal these causes and can itself alter mass balance.

Worked Example: A Negative Euler Step Does Not Prove a Negative Model State

For a hypothetical single amount, let \(dA/dt=-kA\), with \(A(0)=1\) mg and \(k=3\ \mathrm{h}^{-1}\). The continuous solution is \(A(t)=A(0)e^{-kt}\), which is positive for every finite \(t\geq0\). Use one explicit Euler step of \(\Delta t=0.5\) h.

The Euler update is

$$ A_{\mathrm{new}}=A_{\mathrm{old}}+\Delta t(-kA_{\mathrm{old}}) =1\ \mathrm{mg}\left(1-(0.5\ \mathrm{h})(3\ \mathrm{h}^{-1})\right) =-0.5\ \mathrm{mg}. $$

The exact continuous value at 0.5 h is \(e^{-1.5}\) mg, or approximately \(0.2231\) mg. The negative Euler result is therefore a time-stepping failure, not a property of the continuous model. A smaller step or a suitable positivity-preserving method is needed, followed by renewed mass-balance checks.

Compare Integrated Absorption With Cumulative Mass

By definition, cumulative absorbed mass must satisfy

$$ B(t)-B(0)=\int_0^t\sum_{i=1}^{N}R_i(s)\,ds. $$

This identity provides a local check on absorption bookkeeping that complements total dose recovery. One approach is to integrate the absorption rates independently and compare the result with the change in the cumulative state \(B\). Another is to solve \(dB/dt=\sum_iR_i\) as part of the differential-equation system. Agreement is expected within the accuracy of the integration and numerical quadrature. A discrepancy can reveal that a regional rate was omitted, counted twice, assigned different units, or evaluated differently in the two calculations.

Worked Example: Comparing Flux Integration With the Absorbed-Mass State

In a hypothetical one-segment model, the total absorption rate is recorded at times 0, 1, and 2 h as 0, 4, and 4 mg/h. Use the trapezoidal rule on each one-hour interval to estimate the integrated absorbed mass over 0–2 h.

For the first interval, the estimate is \((0+4)/2\times1=2\) mg. For the second, it is \((4+4)/2\times1=4\) mg. Thus the integrated flux estimate is \(2+4=6\) mg. If the cumulative absorbed-mass state changes from \(B(0)=0\) to \(B(2)=6.0\) mg, the two checks agree at the precision shown. If the reported state were instead \(6.3\) mg, the discrepancy would be \(0.3\) mg. The next step would be to inspect the rate calculation, the \(B\)-state equation, units, and quadrature or solver tolerances—not to assume that either calculation is automatically correct.

Use Residuals to Diagnose, Not to Certify

A useful audit evaluates mass balance over the whole time course and interface continuity at each time or time step. It also checks nonnegative amounts and compares integrated absorption with the cumulative absorbed state. These checks are complementary: a global balance can pass while regional fluxes are assigned to the wrong interfaces, and a locally continuous flux can still be omitted from the cumulative absorbed-mass equation.

Compare residual magnitudes with the dose and with solver tolerances rather than relying on a universal cutoff. Examine whether errors grow over time, occur at particular step boundaries, or scale with a specific flux. A discontinuous jump can suggest a bookkeeping or event-handling problem; gradual drift can suggest accumulated integration error. Repeating the calculation with tighter tolerances or smaller time steps helps distinguish numerical error from a structural coding error.

CheckWhat it testsWhat it does not establish
Total mass balanceWhether modeled inventory reconciles with initial mass and external inputsWhether regional absorption is biologically correct
Interface continuityWhether each transfer leaving one segment enters its neighbor at the same rateWhether the chosen transit or permeability rate is appropriate
Nonnegative statesWhether amounts are physically admissible and numerical integration is behaving plausiblyWhether the model’s structure is adequate
Absorption integral versus \(B\)Whether rates and cumulative absorption are implemented consistentlyWhether the absorption-rate assumptions match biological reality

A common mistake is to conclude that a zero total mass-balance residual proves every part of the model is correct. It proves only that the chosen accounting terms reconcile. For example, a rate assigned to the wrong region could still conserve total mass. Conversely, a small residual does not establish that the permeability or transit assumptions are appropriate. Conservation diagnostics test internal consistency; scientific adequacy requires evidence beyond these checks.

Key takeaway: Count every modeled dose-containing state and boundary flow, use one shared flux per interface, and verify that cumulative absorption equals the integrated absorption rate. Interpret any residual alongside numerical accuracy and the model’s stated accounting boundaries.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. A model begins with 50 mg and has no later input. At one time point, 6 mg remains in the gut, 35 mg has been absorbed, and 9 mg has left the modeled gut. What is the mass-balance residual?
  2. An interface has an outgoing rate of 7 mg/h and an incoming rate of 7.2 mg/h. Give the discrepancy using outgoing minus incoming, and state its implication.
  3. For \(dA/dt=-0.8A\), \(A(0)=10\) mg, and \(k=0.8\ \mathrm{h}^{-1}\), calculate the explicit Euler update after a 0.5 h step. Is a negative result expected from this step?
  4. Over one hour, an absorption rate is 2 mg/h at both endpoints. What does the trapezoidal rule give for absorbed mass over that interval?

Solutions. (1) The accounted mass is \(6+35+9=50\) mg, so the residual is \(50-50=0\) mg. (2) The discrepancy is \(7-7.2=-0.2\) mg/h; the receiver gains 0.2 mg/h more than the donor loses, so the interface is discontinuous. (3) \(A_{\mathrm{new}}=10[1-(0.5)(0.8)]=6\) mg. This Euler step is positive; the continuous solution is also positive. (4) The trapezoidal estimate is \((2+2)/2\times1=2\) mg.