Why Discontinuous Inputs Need Explicit Treatment
A QSP model may include an instantaneous dose, an infusion that starts or stops at a specified time, or an external signal that changes abruptly. Each is a discontinuity in the model input or state. An ordinary differential equation solver advances the state through time using evaluations of the model's right-hand side. If it steps across a discontinuity without being told where that discontinuity occurs, it may approximate the solution as though the input had changed gradually or at the wrong time. The resulting error can persist after the event.
The key distinction is between a jump in a state and a jump in a rate. A bolus dose directly changes an amount state at one instant. An infusion usually changes the rate of accumulation while leaving the amount state continuous. A stepwise signal changes an input to the right-hand side; unless the model specifies an instantaneous transfer, the state itself remains continuous.
This tutorial assumes that the underlying model has been written as an ODE system, with states separated from inputs and parameters. For an input-driven model, write
where \(x\) is the state vector, \(u(t)\) is a prescribed input, and \(\theta\) denotes parameters. Between known discontinuities, assume \(f\) is sufficiently regular for the chosen solver to integrate the model. At a scheduled event, specify the change explicitly: either update a state or change the input used on the next integration segment.
Bolus Doses: Apply a State Jump
Suppose \(A\) is an amount state measured in milligrams. A bolus of \(D\) mg delivered directly to this state at time \(t_e\) changes the amount instantaneously. The differential equation governs the evolution between doses, not the jump itself. For example, with first-order elimination, \(dA/dt=-kA\) between doses, where \(k\) has units of inverse time.
A reliable implementation integrates up to the dose time, records \(A(t_e^-)\), adds the dose, and restarts from \(A(t_e^+)\). With multiple simultaneous boluses into the same state, add their amounts together once. A dose at the initial time must also be handled explicitly: either include it in the initial state or apply it as an event at time zero, but not both.
Worked Example: Two Boluses with Elimination
Consider a hypothetical one-compartment amount model with \(dA/dt=-0.20A\) per hour between doses. The initial amount is zero. A 100 mg bolus is given at time 0 h and a 50 mg bolus at time 4 h. Find the amount just before and just after the second bolus, and then at time 6 h.
The initial bolus gives \(A(0^+)=100\) mg. Between time 0 and 4 h, exponential decay gives
The event adds 50 mg, so \(A(4^+)=44.9329+50=94.9329\) mg. Two hours later, the amount is
The first term is the remaining part of the 100 mg dose after 6 h; the second is the remaining part of the 50 mg dose after 2 h. This calculation uses the unrounded pre-dose amount in the formula, so its reported result is consistent with the stated dose and elimination rate.
Infusions and Stepwise Inputs: Change the Rate, Not the State
For a constant-rate infusion into the amount state \(A\), the rate \(R\) has units of amount per time. During infusion, the input contributes \(R\) to the derivative; outside the infusion interval, that contribution is zero. A convenient definition for an infusion starting at \(t_s\) and stopping at \(t_f\) is
If elimination occurs at rate \(kA\), then \(dA/dt=R_{\mathrm{in}}(t)-kA\). At infusion start and stop, the rate changes abruptly, but the amount does not jump. The choice of whether the input is on at the exact boundary is a convention for evaluating the derivative at one instant; it does not create an amount jump. Use one convention consistently, and ensure the integrator starts the next segment with the state at the boundary.
Worked Example: An Infusion with a Defined Stop Time
In a hypothetical model, an amount state begins at \(A(2)=0\) mg. A constant infusion of 12 mg/h runs from 2 h to 5 h, while elimination follows \(dA/dt=R_{\mathrm{in}}-0.10A\). Find the amount at 5 h and at 7 h.
On the infusion segment, the solution with constant rate \(R\) is \(A(t)=A(t_s)e^{-k(t-t_s)}+(R/k)(1-e^{-k(t-t_s)})\). This follows by multiplying \(dA/dt+kA=R\) by the integrating factor \(e^{kt}\), integrating over the segment, and solving for \(A(t)\). Here \(A(2)=0\), \(R/k=12/0.10=120\) mg, and the infusion lasts 3 h:
Stopping the infusion does not change the amount, so \(A(5^+)=31.1018\) mg. From 5 h to 7 h, the input is zero and the amount decays:
The expression using \(120(1-e^{-0.3})\) retains the unrounded value of \(A(5)\); the displayed four-significant-figure amount is for reporting.
A stepwise input can represent a changing synthesis signal, environmental exposure, or other prescribed control. If \(q(t)\) changes from one constant value to another, define it piecewise and use the appropriate value on each interval. Unless the model includes a jump mechanism, \(x(t)\) remains continuous at the change time, even though \(dx/dt\) can change abruptly.
Worked Example: A Step Change in Production
Suppose a hypothetical state \(y\), measured in amount units, obeys \(dy/dt=q(t)-0.5y\) per hour, with \(y(0)=0\). Production is \(q=4\) amount units per hour from 0 to 3 h, then \(q=1\) amount unit per hour. Find \(y(3)\) and \(y(5)\).
From 0 to 3 h, the constant-input solution has equilibrium \(q/k=4/0.5=8\). Thus
There is no state jump at 3 h, so \(y(3^+)=y(3^-)\). After the change, the new equilibrium is \(1/0.5=2\), and the interval lasts 2 h:
Using the prior segment's state as the initial condition for the new segment preserves continuity while allowing the derivative to reflect the new production rate.
Integration at Event Boundaries
Known discontinuities should be integration boundaries. For event times \(t_1<t_2<\cdots<t_m\), integrate each smooth segment up to its endpoint. At that endpoint, apply any state jumps, update the input schedule, and restart the solver for the next segment. This is called segmented integration. A solver with built-in event handling can perform the same operations, provided the event is registered as a boundary or reset and the solver restarts with the correct state and input.
Record each bolus time, infusion start and stop, and step change. Combine events at identical times and define their order if one event changes a state used by another.
Use the input that applies on the current open interval. Stop at the event time rather than allowing a numerical step to cross it unnoticed.
Add boluses as state jumps. For infusion or step changes, update the input schedule and preserve state continuity unless the model explicitly specifies a jump.
Continue from the post-event state. If reporting both sides of a bolus, label the values \(t_e^-\) and \(t_e^+\); do not treat them as one continuous observation.
A requested output time between two event times can be obtained from the solver's solution on that segment. However, interpolation must not span an event. Interpolating from a pre-bolus value to a post-bolus value invents intermediate amounts that the model never had. Similarly, interpolation across a step change can smooth a sharp change in the derivative and return values inconsistent with the piecewise model. Use dense output or interpolation only within a segment where the equations and inputs have the same form.
For a bolus into an amount state, a useful check is the event balance \(A(t_e^+)-A(t_e^-)=D\). For a rate change without a state jump, check that the state agrees on the two sides while its derivative matches the old and new inputs, respectively. These checks are particularly useful when implementing repeated dosing schedules or several inputs that share an event time.
Diagnostics, Alternatives, and Limitations
Common signs of a discontinuity-handling error include a bolus that appears smeared over time, a state that jumps at an infusion stop, a dose that appears twice, or a response that depends strongly on the solver's maximum step near a scheduled event. Compare results after reducing the maximum step, but do not use step-size reduction as a substitute for explicitly locating known events. A sufficiently small step can reduce the error from crossing an event, but it does not define the intended boundary or guarantee the correct dose convention.
Two standard implementation choices are solver-managed event handling and manual segmented integration. Solver event handling can be concise and can coordinate state resets with the solver's internal steps. It depends on registering the event and reset correctly, and the solver must restart its integration after a reset. Manual segmentation makes each interval and update explicit, which is often easier to inspect and test for a short schedule. It requires careful bookkeeping of event times and state values. Either approach is valid if the solver does not interpolate or take an uncorrected step across a discontinuity.
A further alternative is to approximate an instantaneous dose as a very short infusion. This changes the model: it replaces an instantaneous jump with delivery over a finite duration. Such an approximation may be useful when the physical administration truly occurs over that duration, but should not be used merely to avoid implementing a bolus event. Its accuracy depends on the chosen duration and the dynamics during delivery.
Discontinuity handling also relies on knowing the scheduled event times. If event times depend on a state crossing a threshold rather than on a fixed schedule, the solver must detect the crossing and locate it accurately; a coarse output grid alone is not a reliable event detector. Simultaneous events require a declared convention, especially if one reset affects another. Finally, numerical integration error remains within each segment, so event treatment complements rather than replaces appropriate solver and error-tolerance choices.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions below.
- A 20 mg bolus is added to an amount state at 3 h. What equation relates the state immediately before and after the event?
- An infusion starts at 1 h and stops at 4 h. Does the amount state jump at either boundary if no bolus is given?
- For \(dA/dt=R-kA\) during a constant infusion, what is the equilibrium amount when \(R=6\) mg/h and \(k=0.2\) per hour?
- Why should output interpolation not cross a bolus time?
Solutions. (1) \(A(3^+)=A(3^-)+20\) mg. (2) No. The infusion rate changes at each boundary, so the derivative may change, but the amount remains continuous. (3) At equilibrium, \(0=R-kA\), giving \(A=R/k=6/0.2=30\) mg. (4) The state has different left- and right-hand values at the bolus; interpolating between them invents values that do not belong to either continuous segment and does not represent the instantaneous jump.