Documente Academic
Documente Profesional
Documente Cultură
Codes
DOUGLAS A. SCHWER, JOHN E. TOLSMA, WILLIAM H. GREEN, JR., and
PAUL I. BARTON*
Department of Chemical Engineering, Massachusetts Institute of Technology, 77 Massachusetts Ave., Cambridge,
MA 02139, USA
A method of updating and reusing legacy FORTRAN codes for combustion simulations is presented using the
DAEPACK software package. The procedure is demonstrated on two codes that come with the CHEMKIN-II
package, CONP and SENKIN, for the constant-pressure batch reactor simulation. Using DAEPACK generated
code, analytical derivative calculations, sparsity pattern information, and hidden discontinuity information can
be obtained for the models of interest. This information can be easily integrated with different solvers giving
the modeler great flexibility in selecting the best solution procedure. Using the generated code, the CONP code
was connected to three different solvers, and the SENKIN code was connected to two different solvers. The
effect of model formulation, analytical derivatives, sparsity, and sensitivity equation solution method were
analyzed for three large kinetic mechanisms for methane, acetylene, and n-heptane. For the n-heptane model,
with 544 species and 2446 reactions, a factor of 10-speed improvement over the original solution procedure was
found using analytical derivatives and sparse linear algebra. For sensitivity calculations, for a small number of
parameters, a factor of 55 improvement over the original solution procedure was found for the n-heptane
problem. Upon closer examination of results, no one method is found to always be superior to other methods,
and selection of the appropriate solution procedure requires an examination of the specific kinetic mechanism,
which is easily conducted using DAEPACK generated code. © 2002 by The Combustion Institute
however, significant portions of these legacy complex, and interconnected hierarchies of sub-
codes must be rewritten to take advantage of routines.
the new solvers, which is often a time consuming DAEPACK is a collection of programs de-
and error prone task. Unless the interfaces veloped to help modelers apply modern algo-
remain consistent, a considerable amount of rithms and techniques to their FORTRAN1
work is also necessary to validate the new code models efficiently and accurately. At the core of
to the same degree as the previous, older codes. DAEPACK is a source code analyzer. The
In this paper, we present a new method to analyzer is able to parse FORTRAN source
automate this process of updating legacy codes. code and extract information needed for more
We demonstrate this procedure on a simple modern solvers, such as the calculation of ana-
chemical simulation and show how this can lytical derivatives, sparsity information, and hid-
improve computational performance in some den discontinuities. DAEPACK then generates
cases by over an order of magnitude. To accom- automatically auxiliary subroutines to calculate
plish this, we use a software package developed this information, making it available to the
at MIT called DAEPACK [6]. We first describe modeler for analysis and for interfacing with
DAEPACK and then discuss the chemical sys- modern solvers.
tems and solution techniques used for these For this paper, two aspects of DAEPACK are
simulations. We then apply DAEPACK to cal- demonstrated for programs of interest to the
culate analytical derivatives and sparsity infor- combustion community. The first aspect is the
mation for three separate chemical kinetic generation of analytical derivatives. For stiff
mechanisms, and examine the efficiency of the ODE/DAE solution procedures, derivatives of
derivative calculations. Finally, we compute the the model are necessary for using robust solu-
resulting simulations with and without sensitiv- tion techniques. Numerical derivatives, espe-
ity computations, using several solvers and tech- cially for very large models, are costly and not
niques that can be easily interfaced with DA- always accurate, and determining and coding
EPACK generated code. All computations were the analytical derivatives by hand can be time
conducted on an 800 MHz Pentium-III com- consuming for complex subroutine libraries.
puter with 256 MB running Linux. Several methods for obtaining analytical Jaco-
bians automatically have been developed [7].
DAEPACK currently implements the sparse
forward mode method of automatic differenti-
DESCRIPTION OF DAEPACK ation [7] and we plan to add other modes in
future releases of the software.
The oldest and most prevalent approach used In addition to calculating analytical deriva-
for modeling and simulation is the FORTRAN- tives, DAEPACK can also generate sparsity
based paradigm. The model is typically encap- patterns for a particular model. With the model
sulated into a single subroutine that calculates in symbolic form, the generated code can auto-
the residuals for the system of equations of matically determine the sparsity pattern and
interest. Very often, the residual subroutine adapt it to the current state of the model. This
calls third-party subroutine libraries to compute is extremely useful for kinetic models, where
the residuals. Older solution techniques typi- one program can generally read in many differ-
cally require only the residual subroutine and ent kinetic models, each having its own sparsity
some other easily obtainable model informa- pattern. The occurrence information can then
tion. Newer techniques, however, often require be used by the modeler to estimate the potential
much more specific information about the sys- of exploiting sparsity, and also as input into
tem of equations, but also offer much more sparse linear algebra solvers such as the Harwell
efficient, robust, and sometimes more accurate MA48 libraries [8].
solution procedures. This information is typi-
cally difficult to obtain and code into the sub- 1
The current implemention is for FORTRAN code, how-
routine, especially with the use of calls to third- ever, the approach is valid for all procedural programming
party subroutine libraries which can have large, languages.
272 D. A. SCHWER ET AL.
component that generates new code computing chosen for its simplicity, yet it has many things
the natural interval extension of the model [19]. in common with more complex systems. The
This new code may be used, for example, to governing ordinary differential equations are
solve systems of equations using interval New- given below:
ton/generalized bisection. Another component
generates new code computing the convex re- dY i
⫽ W iw i (1)
laxations of nonconvex functions in the model dt
[20]. This code is necessary for many global
冘
N
optimization and non-convex mixed integer dT
non-linear programming algorithms. Finally, a Cp ⫽ ⫺ W kh kw k (2)
dt k⫽1
component has been developed to generate the
information necessary to perform reliable and where is the gas density, T is the temperature,
correct numerical integration and parametric Cp is the mixture specific heat, Yi is the mass
sensitivity analysis of models containing discon- fraction, Wi is the molecular weight, wi is the net
tinuities [21–23]. This DAEPACK component species production rate, and hi is the enthalpy of
generates new code that allows the user to lock species i. The code uses the CHEMKIN-II
the model so that it evaluates a smooth func- library to calculate both the thermodynamic
tion. This is achieved by setting a flag that fixes properties as well as the chemical production
the trace of statements executed despite the and destruction rates. The basic chemical equa-
presence of IF statements and discontinuous tions are summarized here, but the interested
intrinsic functions such as MIN and MAX. This reader should consult the original CHEMKIN
new code also extracts the discontinuity func- report for more details.
tions associated with the discrete events, which For this paper, we consider an elementary
are necessary for performing simulation and reaction system with N species and M reactions.
sensitivity analysis correctly and efficiently.
In general, any reaction j is described by its
The current paper applies DAEPACK to two
stoichiometric coefficients:
relatively simple programs used extensively by
the combustion community and included with
冘 ⬘ A º 冘 ⬙ A
N N
the CHEMKIN-II packages [24, 25]. Both ij i kj k (3)
programs simulate a constant-pressure batch i⫽1 k⫽1
reactor. The first program, CONP, computes
where ij⬘ and ij⬙ are the stoichiometric coeffi-
only the simulation, while the second program,
cients for species i, reaction j. For elementary
SENKIN [26], computes the simulation with
reactions, each reaction rate j is calculated as:
sensitivities. We first construct the model and
then outline the solution techniques used for
写C 写C
N N
solving the model. We then apply DAEPACK r j ⫽ k f, j 共T兲 kj⬘
k ⫺ k b, j 共T兲 kj⬙
k (4)
to the system and examine the sparsity of some k⫽1 k⫽1
common, large scale kinetic systems and the
efficiency of analytical derivative calculations as where Ck is the concentration of species k, kf,j is
compared to numerical differences. Then we the forward-rate temperature dependent term,
implement new solvers into the CONP and and kb,j is the backward-rate temperature de-
SENKIN code and evaluate the performance of pendent term. For the majority of reactions, the
using DAEPACK and the new solvers with forward-rate temperature dependent term kf,j is
CONP and SENKIN. calculated using Arrhenius coefficients, kf, j
⫽ Aj T nj exp共⫺Ea, j /RT兲, where Aj is termed the
A-factor for reaction j. The backward tempera-
GOVERNING EQUATIONS ture dependence is either determined in a sim-
ilar manner, or more often calculated through
The system we examine in detail solves the equilibrium arguments using the thermo-chem-
adiabatic, constant pressure problem for a per- ical data. The concentration of species k can be
fectly stirred, batch reactor. This system was expressed in terms of the density:
274 D. A. SCHWER ET AL.
冘␣ C
N
of O and H radicals to start the simulation.
C M, j ⫽ ij i (8) The second mechanism we investigate is an
i⫽1
acetylene flame soot-formation mechanism
where ␣ij is a third-body efficiency and varies for from Wang and Frenklach [30]. This mechanism
different reactions and different species. ␣ij is has 99 species and 533 reactions. Because the
generally one for most of the minor species but mechanism focuses on soot production, it in-
may vary for the major species. Because of this, cludes chemistry that is considerably different
the third body concentration is calculated in than the nitrogen/methane chemistry in GRI-
CHEMKIN as: Mech. The specific case examined for this paper
is an acetylene/air mixture with 7.75(mol/mol)%
冘C ⫹ 冘 C
N N
acetylene by volume at a temperature of 1,000 K
C M, j ⫽ (9)
i ij i and a pressure of one atmosphere. Again, the
i⫽1 i⫽1
simulations are started with a small concentra-
where ij ⫽ ␣ij ⫺ 1. In addition to these simple tion of O and H radicals.
third body reactions, CHEMKIN-II provides The final mechanism that we investigate is an
means for calculating pressure dependent third n-heptane mechanism of Curran et al. [31].
body reactions, which tend to be complex non- With 544 species and 2446 reactions, this mech-
linear functions whose descriptions are not re- anism represents the type of large mechanism
quired here. Please consult the CHEMKIN that will become more common in the future.
papers for a complete explanation and discus- The specific case examined for this paper is an
sion of them. n-heptane/air mixture with 0.14(mol/mol)% n-
The net molar production rate for any given heptane at a pressure of 12.5 atm and 800 K.
species is then described in terms of the indi- Mechanisms such as these typically rely on
vidual reaction rates and their associated stoi- both extensive databases of carefully measured
chiometric coefficients: reactions as well as the incorporation of reac-
tions based on generalized reaction families and
冘 共 ⬙ ⫺ ⬘ 兲 r
M
reaction rules. Extensive and careful analysis is
wi ⫽ ij ij j (10) required to determine the correctness and va-
j⫽1
lidity of large and complex mechanism such as
We investigate the constant-pressure batch re- these. Any enhancement to robustness and ef-
actor for three specific chemical kinetic mecha- ficiency that can be obtained with the current
UPGRADING COMBUSTION CHEMISTRY CODES 275
i⫽0
冊
␣ iZ 共n⫹1兲⫺i, Z n⫹1, t n⫹1, p ⫽ 0 (15)
variables, t is our independent variable (in this Using a Newton method to solve the above
case, time), and p are the parameters of the non-linear equation, we obtain the iterative
problem. This equation describes general differ- equation:
共k⫹1兲 共k兲
Z n⫹1 ⫽ Z n⫹1 ⫺ J⫺1 G 共Z n⫹1
共k兲
, Z n , Z n⫺1 , . . . , Z 共n⫹1兲⫺N , t n⫹1 , p兲 (16)
where G is the discretized form of F, and k is the obtained widespread acceptance. It uses up to a
iteration level. The Jacobian J is defined as: 5th-order BDF method with a variable time-
stepping procedure to obtain results within
⭸F ⭸F specified error bounds. For general DAE sys-
J ⫽ ␣0 ⫹ (17)
⭸Ż ⭸Z tems, DASSL [33] has gained widespread accep-
tance, and similarly uses up to a 5th-order BDF
Note that the above expression simplifies for
method with a variable time-stepping proce-
ODE systems to the following:
dure. For very large systems, even with the use
⭸f of defered Jacobians, the Jacobian calculation
J ⫽ ␣ 0I ⫺ ⫽ ␣ 0I ⫺ J⬘ (18) and LU factorization are still the most costly
⭸Z
parts of the simulation. Both of these solvers
Extensive research has gone into creating assume dense, meaning that most of the ele-
efficient, robust BDF solvers with strict error ments of J are non-zero, or banded linear
control. Most popular methods work by mini- systems. However, many of the large systems
mizing the number of Jacobian evaluations and encountered in combustion simulations are ex-
LU decompositions required, typically by reus- tremely sparse but lack any sort of regular
ing old Jacobians from previous time-steps and structure such as bands. For these systems,
carefully monitoring the convergence rate of the significant gains in efficiency can be made by
quasi-Newton iteration to ensure good conver- exploiting this sparsity in the Jacobian evalua-
gence. The heuristics for these programs are tions and in the linear algebra using direct
quite complex and require years of adjusting to sparse Gauss elimination. DSL48S [35], based
obtain optimum and robust performance. For on DASSL, was written to take advantage of
ODE systems, the VODE package [34] has this form of sparsity by using the Harwell MA48
276 D. A. SCHWER ET AL.
sparse linear algebra libraries [8]. For computa- ture of this system to obtain an efficient method
tions contained in this paper, we use VODE, for solving the sensitivity equations. The advan-
DASSL, and DSL48S for our simulations. tage of this method is that the Jacobian does not
Parametric sensitivities for the dynamic sys- need to be factored at every step.
tem described above can be found by solving The third method commonly used is the
auxiliary sensitivity equations along with the staggered corrector method, and is described in
original system. For the ith parameter, the Feehery, Tolsma, and Barton [35]. This method,
additional sensitivity equations are: as in the staggered direct method, separates the
solution procedure at each time step into two
⭸F ⭸F ⭸F phases, solving the original system and then
ṡ i ⫹ si ⫹ ⫽0 (19)
⭸Ż ⭸Z ⭸p i solving the sensitivity equations. Unlike the
subject to the initial conditions, staggered direct method, however, the stag-
gered corrector method solves the sensitivity
⭸ ⭸ ⭸ equations iteratively using the deferred Jaco-
ṡ i 共t 0兲 ⫹ s i 共t 0兲 ⫹ ⫽0 (20) bian. By using an iterative solution procedure,
⭸Ż ⭸Z ⭸p i
the Jacobian again is not required to be factored
⭸Z at every step, and can thus provide a substantial
where si ⬅ .
⭸pi increase in performance.
For each parameter pi, there are N ⫹ 1 The original SENKIN code uses the stag-
sensitivity variables for the system defined by gered direct method for computation, as imple-
Eqs. 1 and 2, where N is the number of species. mented in DASAC [37]. For the computations
There are two important observations to note reported in this paper, we use the DASPK3.0
about the above sensitivity equations. The first [39] and DSL48S [35] libraries for the simula-
observation is that clearly the original dynami- tions with sensitivities. All three solvers are
cal system is not coupled to the sensitivity based on the DAE-solver DASSL. DASPK in-
equations, and can be solved independently of corporates all three methods for solving sensi-
the sensitivity equations, although the sensitivity tivity systems, and provides an enhancement to
equations are dependent on the dynamical sys- the DASAC implementation for ill-conditioned
tem. The second observation is that the sensi- problems [39]. Like DASSL, it uses dense linear
tivity equations are linear in the sensitivity algebra for factorizations and back substitu-
variables with a Jacobian matrix identical to that tions. DSL48S uses the staggered corrector
employed for the state equations. method for computing sensitivities, and as men-
Unlike the simulations, there are several tioned previously uses the Harwell MA48 sparse
competing methods for solving the sensitivity linear algebra libraries.
equations. In this paper we investigate three All of these programs provide the ability to
different methods. The first method is the stag- calculate numerical Jacobians or use a user
gered direct method [36, 37]. It divides each supplied analytical Jacobian. For many sys-
time step into two computations, first comput- tems, a user provided analytical Jacobian can
ing the original system, and then computing the make the solution procedure more robust,
sensitivity equations. Because the sensitivity and can also increase the efficiency tremen-
equations are linear, this method directly in- dously. DAEPACK provides a method for gen-
verts the system to solve the sensitivity equa- erating the necessary analytical Jacobians easily
tions. By doing a direct inversion, however, the and integrating them with different solvers.
method must factor the Jacobian at every step,
which can become very expensive for large
systems. APPLICATION OF DAEPACK
The second method is called the simulta-
neous corrector method, described by Maly and For this paper, we use DAEPACK to upgrade
Petzold [38]. This solution procedure treats the two codes that come with the CHEMKIN-II
system as one large non-linear dynamical sys- library called CONP and SENKIN. CONP
tem, and takes advantage of the resultant struc- solves the constant pressure system described in
UPGRADING COMBUSTION CHEMISTRY CODES 277
Eqs. 1 and 2 using the VODE integration tion in CONP and two alternative formulations
package. The VODE package requires that the for the same constant-pressure problem. Sec-
user encapsulates the function f (Z, t, p) in Eq. ond, we examine the improvement in perfor-
13 as an external subroutine, and pass it along mance using analytical Jacobians with all three
with the dependent variables, time, and param- systems. Third, for the sparse systems, we exam-
eters to the VODE subroutine. For the CONP ine using both analytical Jacobians and sparse
program, the vector of dependent variables is linear algebra to improve performance using
simply Z ⫽ (Yi , T)T. The functional form of f is different solvers. Finally, we examine the effect
easily determined from Eqs. 1 and 2 and is of solution technique, sparsity, and analytical
encapsulated into the subroutine FUN. Using derivatives on the sensitivity calculations.
CHEMKIN-II, the actual length of the subrou-
tine FUN is quite small (20 lines), as most of the
real computational work is done within the calls EVALUATION OF ANALYTICAL
to CHEMKIN-II library subroutines (which re- JACOBIANS
mained unchanged throughout this work).
SENKIN solves the same system as CONP, plus The destruction and formation of most chemi-
the sensitivty of the system to the reaction cal species is usually dominated by only a hand-
A-factors using the DASAC solver [37]. ful of reactions. Reflecting this physical reality,
DASAC is based on the DASSL DAE solver most large chemical kinetic models in the liter-
and uses the staggered direct method for com- ature are extremely sparse in terms of interac-
puting sensitivities. To use DAE based solvers tions between different species. That is, physi-
we must compute the residual function F(Ż, Z, cally each species reacts with at most only a
t, p) as defined in Eq. 11, which is carried out in a small number of the total number of species
subroutine called RES. Constructing RES from which exist. Most solution methods in current
FUN is very simple. For this system, RES is use, however, rely on dense techniques and do
again quite small, as most of the work is carried not attempt to take advantage of this inherent
out in the CHEMKIN-II library subroutine. sparsity. For this section, we use DAEPACK
The authors of CONP and SENKIN opted to generated code to examine the sparsity of the
use the finite-difference Jacobian generation actual numerical simulations, and determine
subroutine that comes as part of VODE and ways to exploit this sparsity in numerical solvers.
DASSL to determine the Jacobian matrices J⬘ For numerical solvers, the sparsity of the
and J. To switch to analytical Jacobians, we first system is dependent on the non-zero entries in
run the source code through the DAEPACK the Jacobian J, as defined in Eq. 17. For the
code analyzer. DAEPACK requires all of the original formulation where Z ⫽ (Yi , T)T, inspec-
main subroutines, and the libraries that the tion of the original conservation Eqs. 1 and 2
main subroutines access (in this case, the reveals that the Jacobian J is totally dense. The
CHEMKIN-II libraries), be available as source reason for this is that every concentration found
code. DAEPACK then generates a subroutine in the rate Eq. 7 is dependent on every species
that computes the necessary derivatives for the mass fraction Yi through Eqs. 5 and 6. This
Jacobian using the sparse forward mode analyt- results in very poor performance for the current
ical Jacobian procedure, as well as the sparsity automatic analytical derivative techniques, and
information needed by the Harwell MA48 sub- also for sparse linear algebra. In the resulting
routine. The user then writes a small wrapper computations, we refer to this as the density
subroutine to interface the generated code with formulation.
the desired solver. Several examples of wrap- The choice of Z ⫽ (Yi , T)T is a common one,
pers for commonly used solvers are included but not the only one. An equivalent system can
within the DAEPACK distribution. be constructed for the constant pressure prob-
Using sparsity information returned from the lem by using the species moles ni and the system
automatically generated code, we first examine volume V as dependent variables instead of
the sparsity of the three chemical systems men- species mass fractions, where ni ⫽ CiV. The
tioned previously, given the original formula- species conservation equations are simply
278 D. A. SCHWER ET AL.
TABLE 1
Sparsity of the Chemical Kinetic Mechanisms. Dense Refers to the Original Density
Formulation, and Sparse Refers to the Mole Formulation and the Augmented Density
Formulation, Which Give Exactly the Same Sparsity Pattern
calculating the reaction rates, which is the same and dense as the GRI-Mechanism are only
regardless of the formulation. slightly more efficient with the current imple-
The CPU timings for the Jacobian evaluation mentation of analytic Jacobians. However, the
shown in Table 2 are more interesting. First, we acetylene soot mechanism shows a factor of two
point out that the current implementation of speedup in the Jacobian evaluation, and the
analytical derivatives performs poorly for the n-heptane mechanism has nearly a 12-fold
original density formulation. This is because of speedup in the Jacobian calculation, which
two reasons: the sparse forward mode analytical should improve the speed of the simulation
derivative computation becomes more efficient substantially.
as the sparsity of the system increases, whereas In addition to the Jacobian evaluation, Table
the density formulation is totally dense. Also, 2 also shows the LU factorization cost for the
the current implementation in DAEPACK em- entire Jacobian J in Eq. 17. The LU factoriza-
ploys sparse data structures, which creates ad- tion is only shown for the augmented density
ditional overhead and indirect references for formulation, although the other formulations
dense systems that are unnecessary. So, it is are similar for the dense calculations, and the
necessary to take advantage of sparsity to obtain mole formulation LU factorization is similar for
more efficient Jacobian calculations. Even with the sparse LU factorization. The sparse LU
the sparse formulations, mechanisms as small factorization is conducted using the MA48 li-
Fig. 1. Sparsity of GRI-Mech 3.0 mechanism. 54 dependent variables. With (right) and without (left) third-body sparse
formulation.
280 D. A. SCHWER ET AL.
Fig. 2. Sparsity of Wang’s acetylene-soot mechanism. 100 dependent variables. With (right) and without (left) third-body
sparse formulation.
braries. The results here show that there is a ods discussed above. Again, we use DAEPACK
high overhead cost to using sparse linear alge- generated code to do these calculations, al-
bra for small, relatively dense systems. Only though now the calculation of sparsity is not
when we get to large, sparse systems such as the required. The timing results for the ⭸F/⭸p cal-
n-heptane system, can we really take advantage culations are shown in Table 3. For the one
of sparse linear algebra, and improve the LU parameter calculation, one can see that the
factorization substantially. It is interesting to finite difference derivative is by far the most
note that for all cases considered in Table 2 the efficient means of calculating ⭸F/⭸p. This is
cost of a Jacobian evaluation is greater than the because DAEPACK has been optimized to do
cost of a Jacobian factorization, which is some- much more complex, sparse derivatives, which
what contrary to the assumptions made in the requires a high overhead cost for creating the
design of sensitivity algorithms. sparse structures to do the sparse forward mode
For the sensitivity calculations in SENKIN, analytical derivative calculation. For a single
we also examine evaluating ⭸F/⭸p analytically. parameter, we would expect a much better
This computation is required for all three meth- result by doing a regular forward mode calcula-
Fig. 3. Sparsity of Curran’s n-heptane mechanism. 545 dependent variables. With (right) and without (left) third-body sparse
formulation.
UPGRADING COMBUSTION CHEMISTRY CODES 281
TABLE 2
CPU Timings for Function and Jacobian Evaluations, and LU Factorizations, for Each
of the Three Mechanisms. Jacobians Calculated Analytically Using DAEPACK. Note
that the LU Factorization is Only Shown for the Augmented Density Formulation,
However all Three Formulations Behave Similarly for the Dense Solver, and the Mole
and Augmented Formulations Behave Similarly for the Sparse Solver. Timings are
Given in Seconds and Parenthetically as a Ratio to Function Evaluations
Function Evaluation
Density 5.46 ⫻ 10⫺4 8.33 ⫻ 10⫺4 7.94 ⫻ 10⫺3
Mole 5.23 ⫻ 10⫺4 7.97 ⫻ 10⫺4 7.2 ⫻ 10⫺3
Aug. Density 5.51 ⫻ 10⫺4 8.35 ⫻ 10⫺4 8.09 ⫻ 10⫺3
Jacobian Evaluation
Originala 0.0300 (55) 0.0841 (101) 4.34 (546)
Density 0.063 (115) 0.16 (192) 4.15 (523)
Mole 0.0283 (54) 0.0486 (61) 0.516 (72)
Aug. Density 0.022 (41) 0.040 (48) 0.338 (43)
LU Factorization
Dense 8.0 ⫻ 10⫺5 3.6 ⫻ 10⫺4 0.81
Sparse 7.8 ⫻ 10⫺4 2.9 ⫻ 10⫺3 0.25
a
Density formulation and numerical derivatives.
TABLE 3
CPU Timings for ⭸F/⭸p Calculation Using Analytical Derivatives Computed from
DAEPACK. Timings are Given in Seconds and Parenthetically as a Ratio to Function
Evaluations
Function Evaluation
Density 5.46 ⫻ 10⫺4 8.33 ⫻ 10⫺4 7.94 ⫻ 10⫺3
Aug. Density 5.51 ⫻ 10⫺4 8.35 ⫻ 10⫺4 8.09 ⫻ 10⫺3
⭸F/⭸p Evaluation, 1 parameter
Numerical 0.00109 (2) 0.0017 (2) 0.0159 (2)
Density 0.0055 (10) 0.0086 (10) 0.048 (6.0)
Aug. Density 0.0055 (10) 0.0086 (10) 0.049 (6.0)
⭸F/⭸p Evaluation, 100 parameters
Numerical 0.0551 (101) 0.0841 (101) 0.802 (101)
Density 0.010 (18) 0.015 (18) 0.07 (8.8)
Aug. Density 0.010 (18) 0.015 (18) 0.07 (8.8)
⭸F/⭸p Evaluation, M parameters
Numerical 0.178 (326) 0.416 (499) 19.4 (2447)
Density 0.020 (37) 0.039 (47) 0.49 (62)
Aug. Density 0.019 (37) 0.039 (47) 0.53 (65)
282 D. A. SCHWER ET AL.
TABLE 4
Number of
Failures
Total CPU Funct. Jac. LU
Solver Formulation Time (sec) Steps Eval. Eval. Fact. Conv. Error
ers, with all three formulations. We could not very aggressive time-step strategy, resulting in
use the augmented density formulation with many error test failures and subsequent LU
VODE because VODE is an ODE (not a DAE) factorizations. However, by separating the LU
solver, and we did not run the density formula- factorization from the Jacobian evaluation, the
tion with DSL48S because the sparse linear number of Jacobian evaluations still remains
algebra would be useless on a totally dense relatively small. This strategy works very well for
system. All of the calculations (except for the small systems (such as the GRI-Mech), where
original calculations) use analytical Jacobians. the cost of the LU factorization is much smaller
Relative and absolute tolerances of 10⫺6 and than the cost of the Jacobian evaluation. How-
10⫺15 were used, respectively, for the computa- ever, for larger systems, such as n-heptane, this
tions. Results showed no difference between the strategy becomes fairly costly.
three different formulations within the error As we would expect from Table 2, none of the
tolerances. improvements in analytical Jacobians or sparse
There are several interesting details observed linear algebra results in faster overall simula-
in these simulations. The first is the difference tions for the GRI-Mechanism (Table 4). Only a
between the VODE and DASSL (and thus small improvement can be seen with the larger
DSL48S) simulation strategies. VODE has a acetylene-soot mechanism using the new tech-
TABLE 5
Number of
Failures
Total CPU Funct. Jac. LU
Solver Formulation Time (sec) Steps Eval. Eval. Fact. Conv. Error
TABLE 6
Number of
Failures
Total CPU Funct. Jac. LU
Solver Formulation Time (sec) Steps Eval. Eval. Fact. Conv. Error
niques, and most of the simulations are compa- benefit for these systems is quite large, com-
rable in CPU cost. The only notable improve- pared to only a small penalty for smaller sys-
ment for the acetylene-soot case is found with tems.
using the VODE solver and the mole formula-
tion, because the system is still small enough to
take advantage of the VODE heuristics, and the SENSITIVITY RESULTS
analytical Jacobian calculation is less expensive
for the mole formulation. The final set of results are for simulations with
For the larger n-heptane system (Table 6) we the calculation of sensitivities. The SENKIN
see substantial improvements by changing solv- program that comes with CHEMKIN II speci-
ers, using analytical Jacobians, and exploiting fies all of the reaction rate A-factors as sensitiv-
sparsity. Just by switching to the DASSL solu- ity parameters, saving the results at each step
tion strategies, we see a small improvement into an unformatted file. The SENKIN program
because of the reduced number of LU factor- uses the density formulation of the constant-
izations. By using sparse derivative formulations pressure reactor, using the DASAC solver to
and the DASSL strategies, we obtain a greater compute the simulation and sensitivities with
speed up of around 2.5, because of the faster finite difference Jacobian and ⭸F/⭸p calcula-
analytical Jacobian calculation. By taking ad- tions. As metioned previously, we have opted to
vantage of sparse linear algebra, the speed replace the DASAC solver with the DASPK and
improves by a factor of 10 over the original DSL48S solvers because of their greater flexi-
solver, and brings the resultant simulation time bility.
down from 6 minutes to a little over half of a Solving for the sensitivities of all reactions for
minute. a given kinetic mechanism is not always desir-
From the above calculations, it is easily seen able, primarily because of the sheer size of the
that there is no best numerical strategy for all resulting data file. For instance, for the n-
cases. For kinetic systems, knowing the sparsity heptane mechanism, storing all of the sensitivity
pattern of the kinetic system is essential in results for all of the reactions results in a file
determining whether sparse linear algebra or that is 10.6 MB for each time-step (assuming
dense linear algebra is most appropriate, or double precision). A typical case such as the
even (for small mechanisms) whether analytical n-heptane simulations presented in Table 6
or numerical Jacobians are more appropriate. It would result in a file the size of about 8.5
currently appears that only the larger, sparse gigabytes. For such large mechanisms, typically
kinetic systems take full advantage of analytical one wants to examine a specific subset of reac-
derivatives and sparse linear algebra, but the tions, instead of the full reaction set. For this
284 D. A. SCHWER ET AL.
reason, in addition to running the cases for the calculations. The first observation is that the
full set of parameters (M parameters) as the Si.C. and the St.C. methods show a large advan-
original SENKIN, we also ran it for 1 parameter tage when solving one parameter systems over
and 100 parameters. We have disabled writing the St.D. method, and a smaller advantage
out the sensitivity results to a file, because of the when solving 100 parameters. This is because of
extreme file size and cost of I/O. For many of the much smaller number of factorizations re-
the smaller sensitivity calculations, we did com- quired for these methods compared to the
pare the results with the original sensitivity direct method. As the number of parameters
calculation to ensure that the newer implemen- increases, the percentage of time spent factor-
tations were correct. ing the Jacobian decreases and the advantage
The results we present use two different gets washed out. For a large set of parameters,
formulations, the original dense formulation the St.D. method becomes the most efficient.
and the sparse augmented density formulation. This is because it uses a current factored Jaco-
For the density formulation, we use numerical bian at every time-step, and thus can take larger
Jacobians because this calculation is faster time-steps than the other methods. By taking
than the analytical Jacobian calculation for all fewer total time-steps, this method does less
three kinetic mechanisms using the current computations for several hundred parameters,
DAEPACK package. For the augmented den- even though it factors the Jacobian at every
sity formulation, we look at using both finite step. These results have also been seen in
difference and analytical derivatives for Jacobi- previous studies [39].
ans and ⭸F/⭸p evaluations, and the effect of Another observation is the small difference
using sparse linear algebra instead of dense between the Si.C. and St.C. methods for many
linear algebra for the solvers. Finally, we com- of the cases. Although the DASPK results com-
pare the three main methods for calculating paring the two methods gives a slight advantage
sensitivities; the simultaneous corrector (Si.C.) to the simultaneous corrector method, this ap-
method, the staggered corrector (St.C.) pears to be caused by a problem with the
method, and the staggered direct (St.D.) current staggered corrector implementation in
method. Only the St.C. method is available for DASPK, which causes many more error test
DSL48S, so we only show those results. We failures for the St.C. method than the Si.C.
would like to pinpoint, for each kinetic mecha- method, resulting in more time-steps and Jaco-
nism given Np parameters, which method, Jaco- bian evaluations. Comparing these values with
bian evaluation, ⭸F/⭸p evaluation, and sparse/ the DSL48S St.C. implementation shows that
dense linear algebra provides the fastest the error test failures should more closely agree
solutions. We use DASPK to compute the sim- with the Si.C. method.
ulations with dense linear algebra, and DSL48S For all cases with one parameter, the finite
to compute the simulations with sparse linear difference ⭸F/⭸p provided the most efficient
algebra. results. This is because of the poor efficiency of
The full set of results are shown in Tables 7 the analytical derivative calculation for ⭸F/⭸p
through 9 for the GRI-Mechanism, Tables 10 with one parameter, shown in Table 3 and
through 12 for the acetylene-soot mechanism, discussed above. For 100 parameters or M pa-
and Tables 13 through 15 for the n-heptane rameters, however, analytical ⭸F/⭸p has a clear
mechanism. For each of the tables, we show the advantage for most of the calculations. The
effect of using the different formulations, sen- reason is twofold. First, computing analytical
sitivity calculation methods, analytical versus ⭸F/⭸p compared to finite difference ⭸F/⭸p is
finite difference Jacobians, and dense versus much more efficient for large numbers of pa-
sparse linear algebra. For each of the cases, we rameters, as shown in Table 3. Second, many of
use the same initial conditions that were used the cases have a considerable difference in the
for the original simulation runs from the previ- number of error test failures for the finite
ous section. difference ⭸F/⭸p compared with the analytical
Before discussing individual results, first we ⭸F/⭸p. All of the acetylene soot cases, in partic-
make some general observations about these ular, seem to require considerably more steps
UPGRADING COMBUSTION CHEMISTRY CODES 285
TABLE 7
when using finite difference ⭸F/⭸p than analyti- benefit of sparse linear algebra for the larger
cal ⭸F/⭸p. cases. In many cases the advantage of DSL48S
The final general observation is that for all of over the other methods was very slight, but for
the cases except the GRI-Mech and acetylene some cases it was very large (for instance, all of
soot cases with one parameter, DSL48S with the the n-heptane cases).
St.C. method showed the greatest speed in- The complete timing results are given in
crease of any of the methods. This is probably Tables 7 through 9 for the GRI-Mechanism for
due to the correct implementation of the St.C. 1, 100, and 325 parameters. For one parameter,
method, as mentioned above, coupled with the we see about a 10-fold increase by using the
TABLE 8
TABLE 9
Si.C. or St.C. methods with finite difference with 100 parameters is again DSL48S with
Jacobian and ⭸F/⭸p as opposed to the St.D. analytical Jacobian and ⭸F/⭸p, and is 3 times
method used in the original SENKIN code. For faster than the original solution procedure. For
100 parameters, no methods stand out as supe- the full set of parameters, DASPK with the
rior, although the St.C. method is consistently St.D. method and analytical derivatives is
better than the Si.C. method and St.D. methods slightly better than DSL48S with the St.C.
with analytical ⭸F/⭸p, and is 1.9 times faster than method, about 3.7 times faster than the original
the original formulation with the DASPK solution procedure.
solver. For the full set of parameters, the largest Finally, the complete results are given for the
improvement is obtained with using analytical n-heptane mechansims in Tables 13 through 15.
⭸F/⭸p with the staggered corrector method, This time, for one parameter, both the solution
although using the St.D. method with DASPK method (switching from the St.D. to the Si.C. or
and dense linear algebra is only slightly less the St.C. methods), plus exploiting sparsity with
efficient. Dense versus sparse linear algebra has analytical Jacobians, give signficant increases in
only a limited effect on the computational effi- efficiency. DSL48S with the St.C. method, ana-
ciency. lytical Jacobian, and finite difference ⭸F/⭸p is by
The complete timing results for the acety- far the most efficient method, and is approxi-
lene-soot model for 1, 100, and 498 parameters mately 55 times faster than the original solution
are given in Tables 10 through 12. With one procedure. The benefit of sparsity also domi-
parameter, the largest improvement in perfor- nates the efficiency for 100 parameters, and
mance is again achieved by switching the even 2446 parameters. For 100 parameters,
method from the St.D. method to either the DSL48S with analytical Jacobian and ⭸F/⭸p is
Si.C. or St.C. with finite difference ⭸F/⭸p. about five times faster than the original formu-
Smaller improvements are observed with the lation. For the full set of parameters, the num-
use of analytical Jacobians, giving an overall ber of steps taken by the St.C. method is much
improvement of over 26 times the original so- more than the St.D. method, and the cost of
lution procedure. For 100 parameters and 498 doing back substitutions for the additional steps
parameters, the largest improvements are found decreases the benefits of using the sparse linear
from applying analytical ⭸F/⭸p rather than finite algebra of DSL48S and the St.C. method. We
difference ⭸F/⭸p. The most efficient method have opted to present only a subset of cases for
UPGRADING COMBUSTION CHEMISTRY CODES 287
TABLE 10
the n-heptane problem with the full set of Like our earlier simulations without sensitiv-
parameters. The reason for this is the clear ities, there is no straight forward “best” solution
advantage of using analytical Jacobians, analyt- procedure for calculating sensitivities. It is inti-
ical ⭸F/⭸p, and sparse linear algebra. For this mately connected with the number of parame-
case, DSL48S and the St.C. method is the ters for which one wishes to calculate sensitivi-
fastest solution procedure, but only about two ties, and the general sparsity of the kinetic
times faster than the original problem solution, system. However, some clear guidelines can be
and only 1.4 times faster than the St.D. method given. For the larger mechanisms, one always
using analytical Jacobians and ⭸F/⭸p. gains a benefit by exploiting sparsity and analyt-
TABLE 11
TABLE 12
ical Jacobians. For the very large mechanisms, ters, the benefit of analytical Jacobians and
the benefit is quite impressive, especially for ⭸F/⭸p often gets washed out by the sheer num-
small numbers of parameters. For a small num- ber of back-substitutions required for the com-
ber of parameters, there is no benefit to using putation. In these cases, the St.D. method is the
analytical ⭸F/⭸p calculations; however, for me- best method, because it typically requires fewer
dium to large numbers of parameters, analytical time steps than the other methods. Otherwise,
⭸F/⭸p can help the sensitivity calculations sub- the other methods typically perform as well or
stantially. For very large numbers of parame- better than the St.D. method, and for one
TABLE 13
TABLE 14
parameter, the other methods are substantially sitivities. Using DAEPACK, we generated
better. These observations motivate an imple- FORTRAN code to compute analytical Jacobi-
mentation of the staggered direct method that is ans for these calculations, and also compute the
able to exploit sparsity in the linear algebra. sparsity pattern to use with sparse linear solvers
such as the Harwell MA48 libraries. Using these
CONCLUSIONS codes, several different solvers and solution
procedures were used with the older codes to
This paper has discussed the application of evaluate the benefit of using these newer solu-
DAEPACK to two simple codes included with tion techniques.
CHEMKIN-II that calculate homogeneous To evaluate these new techniques and dem-
batch reactor simulations with and without sen- onstrate the utility of DAEPACK, three differ-
TABLE 15
on Modelling and Computer Simulation, 6(2):137–165 29. Bennett, B.A.V., McEnally, C.S., Pfefferle, L.D., and
(1996). Smooke, M.D. Combust. Flame, 123:522–546 (2000).
22. Galán, Santos, Feehery, Willian F., and Barton, Paul I. 30. Wang, H., and Frenklach, M. Combust. Flame, 110:
Applied Numerical Mathematics, 31:17– 47 (1999). 173–221 (1997).
23. Tolsma, John E., and Barton, Paul I. SIAM Journal on 31. Curran, H. J., Gaffuri, P., Pitz, W. J., and Westbrook,
Scientific Computing, 2001 (in press). C. K. Combust. Flame, 114:149 –177 (1998).
24. Kee, R. J., Miller, J. A., and Jefferson, T. H. 32. Gear, C. W. Numerical initial value problems in ordi-
CHEMKIN: A general-purpose, problem-indepen- nary differential equations. Prentice-Hall series in auto-
dent, transportable, FORTRAN chemical kinetics matic computation. Prentice Hall, Englewood Cliffs,
code package. Technical Report SAND80 – 8003, San- NJ, 1971.
dia National Laboratories, 1980. 33. Brenan, K. E., Campbell, S. L., and Petzold, L. R.
Numerical Solution of Initial-Value Problems in Differ-
25. Kee, R. J., Rupley, F. M., and Miller, J. A.
ential-Algebraic Equations. SIAM, Philadelphia, PA,
CHEMKIN-II: A FORTRAN chemical kinetics pack-
2nd edition, 1995.
age for the analysis of gas-phas chemical kinetics.
34. Brown, P. N., Byrne, G. D., and Hindmarsh, A. C.
Technical Report SAND89 – 8009, Sandia National
SIAM J. Sci. Stat. Comput., 10:1038 –1051 (1989).
Laboratories, 1990.
35. Feehery, W. F., Tolsma, J. E., and Barton, P. I. Appl.
26. Lutz, A. E., Kee, R. J., and Miller, J. A. SENKIN: A
Numer. Math., 25:41–54 (1997).
FORTRAN program for predicting homogeneous gas 36. Rabitz, H., Kramer, M., and Dacol, D. Ann. Rev. Phys.
phase chemical kinetics with sensitivity analysis. Tech- Chem., 34:419 – 461 (1983).
nical Report SAND87– 8248 Revised, Sandia National 37. Caracotsios, M., and Stewart, W. E. Comput. Chem.
Laboratories, 1988. Engng., 9(4):359 –365 (1985).
27. Smith, G. P., Golden, D. M., Frenklach, M., Moriarty, 38. Maly, T., and Petzold, L. R. Appl. Numer. Math.,
N. W., Eiteneer, B., Goldenberg, M., Bowman, C. T., 20:57–79 (1997).
Hanson, R. K., Song, S., Gardiner, Jr., W. C., Lissian- 39. Li, S., Petzold, L., and Zhu, W. Appl. Numer. Math.,
ski, V.V., and Qin, Z. http://www.me.berkeley.edu/ 32:161–174 (2000).
gri_mech/.
28. Jessee, J.P., Gansman, R.F., and Fiveland, W.A. Com- Received 11 June 2001; revised 23 October 2001; accepted 8
bust. Sci. Technol. 129:113–140 (1997). November 2001