| cmpt.2 {heR.IndoorAir} | R Documentation |
Function to return the instantaneous and, optionally, the time-averaged time series of pollutant concentrations in an arbitrary number of compartments given the time-dependent volume, flow, emissions, and removal profiles. Non-flow removal is by deposition and/or filtration. Species can optionally re-enter a room due to desorption from surfaces. Flows include indoors to-and-from the outdoors, inter-compartmental, recirculatory, and the supplies, return(s), and make-up of a mechanical HVAC system.
Note: This new sorption version of cmpt (cmpt.2) is still undergoing testing although it has been tested for 1 and 2 compartment cases against the cold cmpt and with the two.cmpt function. When I am confident it is completely correct and efficient, I will rename it cmpt. Until then I will keep the old cmpt around, though it is not included in this package.
cmpt(ndim, t, f, etaii, etaix, e, dep, des,
v, s, p, o, a0, s0,
algorithm = 2, abs = 0.01, rel = 0.1,
surfaces=TRUE, do.ave=FALSE, verbose = FALSE)
ndim |
number of dimensions (compartments) |
t |
times at which to calculate concentrations |
f |
a 3-way array of air flows, see below for details. |
etaii |
a matrix of recirculating air removal efficiencies, see below. |
etaix |
a matrix of return and make-up air removal efficiencies, see below. |
e |
a matrix of emission rates, see below. |
dep |
a matrix of deposition loss-rates, see below. |
des |
a matrix of desorption rates, see below. |
v |
a matrix of compartment volumes, see below. |
s |
a matrix of compartment surface areas, see below. |
p |
a matrix of penetration efficiencies, see below. |
o |
a vector of outdoor concentrations, see below. |
a0 |
a vector of initial air concentrations, see below. |
s0 |
a vector of initial surface concentrations, see below. |
algorithm |
the numerical solution algorithm to use, a number from 1 to 10, defaulting to 2, see below. |
abs |
the absolute error tolerance |
rel |
the relative error tolerance |
surfaces |
logical, whether to include surface compartments in the calculation, defaults to TRUE; to include desorption
in the model the user must set surfaces=TRUE. With surfaces=FALSE surface deposition will still occur, but to an irreversible sink. |
do.ave |
logical, to calculate time-averaged concentrations for each compartment or not, defaults to FALSE |
verbose |
logical, whether to produce descriptive output on the differential equation coefficients or not, defaults to FALSE |
The input parameters take the form of a vector, a matrix, or a 3-way array, and, except for the initial concentrations, they can all be varied in time.
Note: ndim is the number of dimensions (compartments) and ntimes is the number of time steps.
c(ndim+2,ndim+2,ntimes), containing the flows between each compartment, between each compartment and the outdoors, between each compartment and itself (recirculation), and between each compartment and the mechanical HVAC (heating, ventilation, and/or air conditioning) system for each time.c(ndim, ntimes), containing the recirculating filter removal efficiencies for each time.c(ndim+1, ntimes), containing the return air filter removal efficiencies for each time.c(ndim, ntimes), containing the compartment volumes for each time.c(ndim, ntimes), containing the compartment surface areas for each time.c(ndim, ntimes), containing the pollutant source emission rate for each compartment and time.ntimes, containing the outdoor pollutant concentration for each time.c(ndim, ntimes), containing the outdoor to indoor pollutant penetration efficiency for each compartment and time.c(ndim, ntimes), containing the pollutant deposition loss-rate for each compartment and time.c(ndim, ntimes), containing the pollutant desorption rate for each compartment and time.ndim, containing the initial pollutant air concentration for each compartment.ndim, containing the initial pollutant surface concentration for each compartment.
The general form of a time cross-section of the f 3-way array is:
| f00 | f01 | ... | f02 | ... | f0N | f0X |
| f10 | f11 | ... | f12 | ... | f1N | f1X |
| f20 | f21 | ... | f22 | ... | f2N | f2X |
| ... | ... | ... | ... | ... | ... | ... |
| fN0 | fN1 | ... | fN2 | ... | fNN | fNX |
| fX0 | fX1 | ... | fX2 | ... | fXN | fXX |
where for i = 0,1,2,...; j = 0,1,2,..., fij = the flow between compartments; for i =0,1,2,..., fii = the recirculating flow; for i=0,1,2,..., fNi, fiN = the flow to/from outdoors; for i=0,1,2,..., fXi, fiX = the flow to/from the HVAC; fNN and fXX are meaningless and ignored.
The general form of the matrix inputs are as follows:
| x0(t1) | x0(t2) | x0(t3) | ... |
| x1(t1) | x1(t2) | x1(t3) | ... |
| x2(t1) | x2(t2) | x2(t3) | ... |
| ... | ... | ... | ... |
where for i=0,1,2,...; j=1,2,..., xi(tj) is the parameter value for
compartment i at time j. For etaix, there is
one additional row in the matrix for the pollutant removal efficiency of flows
from outdoors to the mechanical ventilator (i.e., the make-up air flow).
Defaults are zero for all parameters except for volumes, which are set to 100, 200, 300, etc., and penetration efficiencies, which are set to 1.
Each system of coupled compartments is solved numerically using the GNU Scientific Library (GSL). Algorithm types are as follows:
| 1 | rk2 | Embedded 2nd order Runge-Kutta, 3rd order error estimate |
| 2 | rk4 | 4th order Runge-Kutta, classical |
| 3 | rkf45 | Embedded 4th order Runge-Kutta-Fehlberg, 5th order error |
| 4 | rkck | Embedded 4th order Runge-Kutta Cash-Karp, 5th order error |
| 5 | rk8pd | Embedded 8th order Runge-Kutta Prince-Dormand, 9th order error |
| 6 | rk2imp | Implicit 2nd order Runge-Kutta at Gaussian points |
| 7 | rk4imp | Implicit 4th order Runge-Kutta at Gaussian points |
| 8 | bsimp | Implicit Bulirsch-Stoer method of Bader and Deuflhard. Requires Jacobian. |
| 9 | gear1 | M=1 implicit Gear method |
| 10 | gear2 | M=2 implicit Gear method |
The default algorithm is 'rk4', and is used if (1 > algorithm > 5),
i.e., if the passed value is out of range.
If surfaces=TRUE, then twice as many compartments are treated, because there
is a surface compartment corresponding to each air compartment. In this case, mass
deposited to each surface is tracked and can re-enter air compartments when the
desorption coefficient is non-zero.
[add some more stuff based on notes in cmpt.2.c ...]
A list with the following components:
airconc |
a data frame containing the instantaneous air concentrations in each compartment |
airave |
a data frame with the time-averaged air concentrations in each compartment |
surfconc |
a data frame containing the instantaneous surface concentrations in each compartment |
surfave |
a data frame with the time-averaged surface concentrations in each compartment |
times |
the times concentrations were calculated |
params |
a list containing input parameter objects, see above. |
other |
a list containing information about the calculation: the algorithm type, the absolute error tolerance, and the relative error tolerance. |
[The following does not include desorption (surface compartments)...and will be rewritten]
The GNU Scientific Library ODE solver will solve a system of n first-order ordinary differential equations of the form:
dyi(t)/dt = fi(t,y1(t), y2(t),..., yn(t))
with i = 1,2,3,...
For the present function, we solve a system of n coupled equations with constant coefficients for any given time step:
dy1(t)/dt = k10 + k11 y1(t) + k12 y2(t) + ... + k1n yn(t)
dy2(t)/dt = k20 + k21 y1(t) + k22 y2(t) + ... + k2n yn(t)
...
dyn(t)/dt = kn0 + kn1 y1(t) + kn2 y2(t) + ... + knn yn(t)
The yi, i=1,2,3,..., are the concentrations inside each compartment. The kij, i=1,2,3,...; j=0,1,2,3,..., are the constant coefficients, which are written in terms of physical parameters such as flow between compartments, or emissions, or loss to filtration, etc.
The kij can change between "time steps", but are strictly constant within any given time step. These "time steps" are those specified by the user, although, internally, the routine adaptively selects the best time increments to use when evaluating the solution at the user-specified times.
This function solves the above n-dimensional system for an arbitrary number of equations and for arbitrary coefficients kij. The user can specify any configuration.
To obtain time-averaged concentrations across all of the specified time
breaks, a system of n=ndim linear algebraic equations is solved
by LU decomposition. A system of equations in terms of the average
concentration in each compartment Ci is obtained for each time
break by taking the integral
of the above set of differential equations and dividing by the current time
interval.
A11 C1 + A12 C2 + ... + A1n Cn = B1
A21 C1 + A22 C2 + ... + A2n Cn = B2
...
An1 C1 + A2n C2 + ... + Ann Cn = Bn
The coefficients A and constants B are calculated from the ODE coefficients and instantaneous concentrations determined earlier.
If the user selects parameter values such that loss or gain for some equation coefficients are very much smaller or larger than other terms, i.e., that some quantities vary at a very different rate than others, or if a quantity is intended to vary at a very much larger rate than the specified time steps, it is possible for the solution algorithm to break down and given erroneous results (e.g., negatives solution values or values that "blow up").
For example, cases where removal rates are extremely large compared to the time step (e.g., 500-1000 / min for 1 min time steps) will be problematic. These removal rates can be for ventilation, deposition, or HVAC-related. Small volumes can lead to similar problems.
The one.cmpt function is intended to simplify one-compartment
calculations by reducing complexity in the specification of input parameters.
The two.cmpt function also requires relatively simple input
specifications for the two-compartment case. In contrast to cmpt,
one.cmpt and
two.cmpt use analytical solutions of the mass balance equation.
Neil Klepeis, http://exposurescience.org
The GNU Scientific Library (GSL) is used by this function for the numerical solution of a system of linear ordinary differential equations (ODE) and to solve a set of linear algebraic equations using LU decomposition. See http://www.gnu.org/software/gsl
plot.cmpt is a function to plot the results of a cmpt calculation as a Trellis of concentrations and/or parameters
one.cmpt is a one-compartment model with sophisticated removal mechanisms
two.cmpt is a two-compartment model with sophisticated removal mechanisms
tcm is a simplified two-compartment model with removal mechanisms limited to air exchange with the outdoors and between rooms