Figure 1A: Concentrations: Default parameter set
The inflow and outflow concentrations are graphed as
functions of time. The inflow concentration, Cin, is given
by a function generator, fgen_1. Note that the outflow
concentration, Cout, has reduced amplitude and is more
spread out. Cout equals C, the concentration in the
compartment, because the compartment is instantaneously
well mixed.
Figure 1B: Quantity: Default parameter set
The quantity of C, given in nanomoles, is calculated by two
different methods.
Q(t)=Volume*C(t), and
Qintegral(t) = integral from 0 to t [Flow*(Cin-Cout)] dt.
Figure 2A: Area of Cin and Cout: Default Parameter set
The running integral of Cin and Cout with respect to time is
plotted. Eventually the areas are equal after a "long" time,
in this case 40 seconds.
Figure 2B: Transit Time: Default parameter set
The running calculation of Tbar_in, Tbar_out, and Tbar_sys
is plotted along with the calculation of Tbar_sys equal to
Volume/Flow (green dashed line). It is seen that after 40
seconds when the area of the output concentration curve
matches the area of the input concentration curve, Tbar_sys
(orange line) approaches the value given by the system
transit time (green dashed line).
Figure 3: Error when Cin constant: CinConstant parameter set
It is necessary to change parameter sets to the CinConstant
parameter set and rerun the model. The error in the numeric
solution given by
Error(t) = Canalytic(t)-C(t) is plotted.
The amount of error in a solution usually depends on the
model step size, the particular solver used, and the
parameters given to the solver. The solvers can be found on
the Run Time graphical user interface (GUI) under the Pages
button. Compare the error from the solver, Auto (used here)
with the Euler solver with 1 step.
/* MODEL NUMBER: 0282
MODEL NAME: Comp1FlowPlus
SHORT DESCRIPTION: Models single compartment with inflowing and outflowing
concentration of a single substance.
*/
import nsrunit; unit conversion on;
math Comp1FlowPlus {
// INDEPENDENT VARIABLE
realDomain t sec; t.min=0; t.max=40; t.delta=0.1;
// PARAMETERS
real C0 = 0 mM, // Initial Concentration
Volume = 0.06 ml, // Volume of compartment
Flow = 0.01 ml/sec; // Flow rate (volume per second)
extern real Cin(t) mM; // Inflowing concentration (defined with
// function generator)
// VARIABLES
real C(t) mM, // Concentration in compartment
Cout(t) mM; // Outflowing concentration NOTE that Cout=C because
// the compartment is instantaneously well mixed.
// INITIAL CONDITION
when(t = t.min) C=C0;
// ORDINARY DIFFERENTIAL EQUATION
C:t = (Flow/Volume)*(Cin-Cout);
Cout = C;
//ADDITIONAL CALCULATIONS
// ANALYTIC SOLUTION FOR CONSTANT INFLOW CONCENTRATION
real Canalytic(t) mM;
Canalytic=C0+(Cin-C0)*(1-exp(-Flow*t/Volume));
// QUANTITY OF SUBSTANCE FROM TWO DIFFERENT CALCULATIONS
real Q(t) nmol, // Quantity = Volume* Concentration
Qintegral(t) nmol; // Quantity = integral of Flow multiplying inflow
// concentration minus outflow concentration
Q = Volume*C;
when (t=t.min) Qintegral=Volume*C0;
Qintegral:t = Flow*(Cin-Cout);
// AREA AND TRANSIT TIME OF INFLOW AND OUTFLOW CONCENTRATIONS
private real S2_in(t) mM*sec^2, S2_out(t) mM*sec^2; // First moments
real Area_in(t) mM*sec, Area_out(t) mM*sec, // Areas
Tbar_in(t) sec, Tbar_out(t) sec, Tbar_sys(t) sec; // Transit times
when(t=t.min) {Area_in = 0; S2_in = 0;
Area_out = 0; S2_out = 0; }
Area_in:t = Cin;
Area_out:t = Cout;
S2_in:t = Cin*t;
S2_out:t = Cout*t;
Tbar_in = if(Area_in>0) S2_in /Area_in else 0;
Tbar_out = if(Area_out>0) S2_out/Area_out else 0;
Tbar_sys = Tbar_out-Tbar_in;
} // END
/* Diagram
+-----------------------------+
Flow*Cin ---> C ---> Flow*Cout
| Volume | Cout = C
| instantaneously well mixed |
+-----------------------------+
DETAILED DESCRIPTION:
A Flow carries an inflow concentration, Cin, into a one
compartment model with a given Volume. Cin is constantly and
instantaneously well mixed becoming C, the concentration in the
compartment. C empties out of the compartment and is designated Cout.
No reactions occur in this system.
For a constant concentration of inflowing material
the analytic solution is given.
Various methods for checking the
calculations in a model are illustrated: (1) comparison with an
analytic solution, (2) two methods of calculating the amount of
material in a compartment with flow, (3) comparison of the running
integrals of inflow and outflow concentrations, and (4) calculation
of the system transit time of a compartment model with flow by
two different methods.
SHORTCOMINGS/GENERAL COMMENTS:
- None.
KEY WORDS:
Course, compartment, compartmental, tutorial, flow
REFERENCES: None.
REVISION HISTORY:
JSim SOFTWARE COPYRIGHT AND REQUEST FOR ACKNOWLEDGMENT OF USE:
JSim software was developed with support from NIH grants HL088516,
and HL073598. Please cite these grants in any publication for which
this software is used and send one reprint of published abstracts or
articles to the address given below. Academic use is unrestricted.
Software may be copied so long as this copyright notice is included.
Copyright (C) 1999-2010 University of Washington.
Contact Information:
The National Simulation Resource,
Director J. B. Bassingthwaighte,
Department of Bioengineering,
University of Washington, Seattle, WA
98195-5061
*/