1-d Ic Engine Model With Python PDF
1-d Ic Engine Model With Python PDF
Abstract— A code for computational simu- models, the engine is represented as a network of pipes
lation of internal combustion engines is pre- (intake and exhaust manifolds) interconnected among
sented. One-dimensional gas dynamics equa- them with “devices” that simulate different parts of
tions are used for model the flow through the machine (valves, cylinders, pipe junctions, etc.).
pipes and manifolds, and the remaining com- One-dimensional CFD models are used for pipes and
ponents in the engine (cylinders, valves, etc.) thermodynamic (or zero-dimensional) models for the
are modeled by using thermodynamic or 0D above mentioned “devices”.
models. The numerical code developed is able For 0D models, most properties are averaged over
to simulate spark-ignition and compression- the total volume and no spatial information is avail-
ignition, two-stroke and four-stroke, multi- able. A survey of thermodynamic models for cylin-
cylinder and multi-valve engines, naturally as- ders are presented by Blumberg et al. (1979), Mattavi
pirated or turbo-charged, and different geome- et al. (1980), Heywood (1980), among others. These
tries of the combustion chamber. The code was models rely on some understanding of the physics in-
implemented in the scripting language Python, volved and try to capture the main features of the
which is a dynamic object-oriented program- processes. By including the description of the most
ming language that offers strong support for in- important aspects, the models have performed sur-
tegration with other languages and tools. The prisingly well and are ideally suited for parametric
numerical methods used in the discretization of studies. A zero-dimensional single-zone model is ca-
the equations and implementation details are pable of predicting engine performance and fuel econ-
presented. Several test cases are included in omy accurately with a high computational efficiency
order to show the performance of the code. (Krieger and Borman, 1966; Foster, 1985; Assanis and
Heywood, 1986). The major drawback of single-zone
Keywords— Internal combustion engine
models is their inability to simulate the wave propaga-
modeling, 0D/1D internal combustion engine
tion into pipes and manifolds that strongly influence
simulation, Python.
on volumetric efficiency. Also, these models are unable
to account for fuel spray evolution and the spatial vari-
I. INTRODUCTION ation in mixture composition and temperature, both
The modeling of reciprocating and rotary internal of which are essential in predicting harmful species
combustion (IC) engines is a multidisciplinary subject formed during the combustion process.
that involves thermodynamics, fluid mechanics, turbu- On the other hand, multi-dimensional models, such
lence, heat transfer, combustion, chemical reactions, as KIVA (Oran and Boris, 1981; Bracco, 1985; Ams-
mathematical analysis, and numerical methods. His- den et al., 1985; Amsden et al., 1987; Varnavas and
torically, different levels of approximation have been Assanis, 1996), resolve the cylinder space into fine
used to predict the performance of IC engines, from grids, thus providing a considerable amount of spa-
simple air standard cycles to complex 3D models in- tial information. However, multi-dimensional mod-
cluding turbulence, chemical reactions, spray dynam- els still employ phenomenological submodels describ-
ics, etc. IC engine simulation can be classified into ing fuel spray processes, and their simulation re-
four categories, namely zero-dimensional single zone, sults may vary with assumed initial or boundary
0D/1D single zone models, quasi-dimensional multi- conditions. Consequently, the accuracy of the re-
zone models and multidimensional models. In 0D/1D sults cannot always be guaranteed. Furthermore,
computational time and storage constraints still pre- coupled with the KIVA-3V (Amsden et al., 1993) code.
clude these models from routine use for design pur- The coupling was done applying a boundary condi-
poses. Currently an intermediate step between zero- tion for the 3D code based on the mass flow rate and
dimensional and multi-dimensional models has arisen, the pressure obtained from the 0D/1D code, for which
called quasi-dimensional. Multi-zone models (Hiroy- was adopted an absorbing boundary condition strat-
asu and Kadota, 1976; Hiroyasu and Kadota, 1983; egy to compute the flow state at the coupling interface
Kyriakides et al., 1986; Yoshizaki et al., 1993; Koure- (Bella et al., 2003). Generally, CFD-3D codes employ
menos et al., 1997; Rakopoulos and Hountalas, 1998; an implicit scheme of integration in time, therefore, the
Jung and Assanis, 2005) can be effectively used to sim- availability of a version of the 0D/1D simulator with
ulate new technology engine combustion systems, by implicit integration gives greater generality to the code
combining the advantages of zero-dimensional mod- as a generator of boundary conditions.
els and multi-dimensional models. These models are The new code was written using the language
able to provide the spatial information required to pre- Python (van Rossum, 1990-2007) because it offers
dict emission products with significantly less require- strong support for integration with other languages,
ment on computing resources than for multidimen- such as C++, Fortran, etc. Also, Python offers
sional models. the advantages of the object-oriented programming
In this work we start to use 0D/1D models in order and has a clear and simple syntax. The numeri-
to obtain a computational tool that can predict with cal code developed is able to simulate spark-ignition
sufficient precision the performance of an IC engine and compression-ignition, two-stroke and four-stroke,
at a relatively low computational cost, with the tar- multi-cylinder and multi-valve engines, naturally aspi-
get of arriving to more sophisticated quasi-dimensional rated or turbo-charged. Also, different geometries of
models in the future. Usually, the 0D/1D engine simu- the combustion chamber are available.
lators employ explicit schemes for integration in time. As future work we will use this software tool as the
Hence, the 0D models are generally formulated accord- simulation stage of an optimization package that al-
ing to an explicit scheme. Because most of these 0D low to setup the engine for performance improvement.
models are non-linear and also the need to reduce the Moreover, our interest would be to use this kind of
time step of the simulation for stability reasons when approximation in real time simulation software.
explicit schemes are applied, choosing an implicit inte- The paper is organized as follows. The next sec-
gration can provide more robustness to 0D/1D codes. tion presents the mathematical models used for each
This project began with the development of a sin- component. Next, the numerical methods applied and
gle cylinder four-stroke spark-ignition engine simula- some details about the implementation are included.
tor. The mathematical model was based on a thermo- Finally, numerical results for different kind of engines
dynamic model for the cylinder and a one-dimensional are shown and some conclusions are presented.
gas dynamics description of the intake and exhaust
systems (Nigro et al., 1999). Then, with the target fo- II. MATHEMATICAL MODEL
cused on the prediction of more real situations, mod- A. Pipe model
els for pipe junctions in multi-cylinder configurations
One-dimensional unsteady flow equations are used for
were added. In order to check the suitability and relia-
modeling pipes and manifolds. In order to include ef-
bility of this computational tool in industrial applica-
fects like variable cross-section, viscous friction, and
tions, this code was rewritten in the compiled language
wall heat transfer, some source terms are added to the
Fortran 90/95 and several test cases were solved val-
inviscid gas dynamic model represented by the system
idating the results with measurements (Alianak and
of Euler equations. The resultant system of equations
Nigro, 2003). In the same reference cite an interest-
can be written as (Heywood, 1988)
ing optimization work was done, where the coupling
between the 0D/1D code and other mechanical design
∂ρ ∂(ρu) 1 dF
tools for sizing camshafts are shown. This optimiza- + =− ρu
∂t ∂x F dx
tion task demanded an extensive usage of our IC en- 2
∂(ρu) ∂(ρu + p) 1 dF 2
gine simulator showing as a by-side product its inher- + =− ρu − ρG
ent robustness. In addition of the overall performance ∂t ∂x F dx (1)
prediction of IC engines, our goal is also to be able ∂(ρE) ∂[(ρE + p)u] 1 dF
+ =− u(ρE + p) +
to make 3D simulations of in-cylinder flows. Due to ∂t ∂x F dx
the impossibility to simulate an IC engine completely D
+ q̇π
with 3D models, it is common to use 0D/1D codes to F
simulate the whole engine except the component that
where ρ is the density; p is the pressure; u is the fluid
will be studied in detail. Thus, in this application,
velocity; F is the pipe cross-section area;
the 0D/1D engine simulator could be used as a gen-
erator of dynamic boundary conditions. In this line u|u| D
of work, the Fortran 90/95 version of the code was G=f π
2 F
is the specific friction force, with the friction coeffi- transfer coefficient hc with expressions like the follow-
cient given by f = 2τw /ρu2 , τw being the viscous shear ing
stress at the pipe wall and D the equivalent diameter
hc L
of the pipe; E is the total specific energy of the fluid; Nu = = CReα Prβ (3)
and q̇ is the heat transfer per unit mass of fluid per λ
unit time. The total specific energy is related to the where L is a characteristic length; λ is the gas thermal
internal energy per unit mass e and specific kinetic conductivity; and C, α and β are constants.
energy as Then, the heat transfer rate to the walls is
1
E = e + u2
2 Q˙ht = Ahc (T − Twall ) (4)
The equation of state used here corresponds to the
where T is the temperature of gas into the cylinder,
ideal gas assumption with particular gas constant
and Twall is the temperature of the cylinder wall.
Rgas .
B.3. Heat release model
B. Cylinder model
In order to modeling combustion we use several ap-
A single-zone model is used to model the cylinder. In proaches and mathematical models, which have the
this model the charge is assumed to be a homogeneous goal to describe the actual heat release via combus-
mixture of ideal gases at all times. The equations of tion as exactly as possible by means of the so-called
the model are the conservation of mass and the first substitute heat release rates.
law of thermodynamics For spark-ignition engines, the mass fraction of
burnt gases (xb ) is computed by using a Wiebe func-
dm X
= ṁj tion (Heywood, 1988)
dt j "
(2) s+1 #
d mb θ − θig
xb = = 1 − exp −c (5)
X
(me) = −pV̇ + Q˙ch − Q˙ht + hj ṁj m ∆θ
dt j
0.15
0.1
experimental data available. The engine was tested at
speeds ranging from 1600 rpm to 6000 rpm. 0.05
1500 2000 2500 3000 3500 4000 4500 5000 5500 6000
Figures 1 to 3 show the computed indicated power, engine speed [rpm]
the torque and the average mass flow rate of air versus
the real curves obtained experimentally. Figure 3: Average mass flow rate of air at intake port
as a function of rpm.
800
calculated
700 experimental valve lift was defined in such a way to make the pas-
600 sage area computed by the code the same as the in-
indicated power [hp]
200
100
1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 transfer exhaust
engine speed [rpm] transfer port port exhaust
duct tank
750 gine.
700
the crankcase, the transfer duct, and the intake and
650 exhaust ports as a function of the crank angle during
600 a cycle. Mass flows through transfer and exhaust ports
are shown in Fig. 6, where positives values represent
550
incoming flow to cylinder.
500
1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 TDC IPC EPO TPO BDC TPC EPC IPO TDC
engine speed [rpm] 200000
cylinder
180000 crankcase
Figure 2: Torque as a function of rpm. exhaust port
transfer port
160000
intake port
pressure [Pa]
140000
B. Two-stroke spark-ignition engine test
This test case was taken from the literature (Blair, 120000
0.1
– Diameter: 38 mm.
0.05
– Length: 400 mm.
0
– Wall temperature: 743 K.
−0.05
integration in time. The code was written in the lan- Assanis, D.N., A computer simulation of the tur-
guage Python in order to take advantage of the object- bocharged turbocompounded diesel engine system
oriented programming and the possibility of integra- for studies of low heat rejection engine perfor-
tion with other languages. Some test cases were solved, mance, Ph. D. Thesis, Massachusetts Institute of
including spark- and compression-ignition, two- and Technology (1985).
four-stroke IC engines. After code calibration, results
were in good agreement with experimental data. Assanis, D.N. and Heywood, J.B., “Development and
As future works we propose to use the code pre- use of a computer simulation of the turbocom-
sented as a generator of boundary conditions for CFD- pounded diesel system for engine performance and
3D codes through an appropriate strategy of coupling. component heat transfer studies,” SAE Interna-
In addition, we intend to incorporate the 0D/1D sim- tional Congress and Exposition, Detroit, Mich.,
ulator within a code of parametric optimization for IC USA, SAE Paper N◦ 860329 (1986).
engines.
Balay, S., Buschelman, K., Gropp, W.D., Kaushik,
ACKNOWLEDGMENTS D., Knepley, M.G., McInnes, L.C., Smith, B.F.
This work has received financial support from Con- and Zhang, H., PETSc: Portable, extensi-
sejo Nacional de Investigaciones Cientı́ficas y Técnicas ble toolkit for scientific computation (1995-2007),
(CONICET, Argentina, grants PIP 5271/05), Univer- http://www.mcs.anl.gov/petsc/.
sidad Nacional del Litoral (UNL, Argentina, grant
CAI+D 2005-10-64) and Agencia Nacional de Pro- Behnel, S., Bradshaw, R. and Sverre Seljebotn, D.,
moción Cientı́fica y Tecnológica (ANPCyT, Argentina, Cython: C-Extensions for Python (2007-2009),
grants PICT 12-14573/2003, PME 209/2003). Au- http://www.cython.org/.
thors made extensive use of freely distributed software
Bella, G., Rotondi, R., Defranco, G. and Nigro, N.,
as GNU/Linux OS, Python, G95 compiler, Octave,
“Code coupling tho enhance CFD analysis of IC
among many others. Special thanks are due to Lisan-
engines,” Mecánica Computacional, Vol. XXII, 26-
dro Dalcı́n for his support with the Python language,
40 (2003).
and also to Mario Storti for his contribution into the
discussion of the ideas. Benson, R., The Thermodynamics and Gas Dynamics
REFERENCES of Internal Combustion Engines, Vol. I, Clarendon
Press, Oxford (1982).
Alianak, J. and Nigro, N., “Intake and exhaust sys-
tem optimization of internal combustion engines,” Blair, G.P., The Basic Design of Two-Stroke Engines,
Technical Report, RT-ID-012, Departamento de In- Society of Automotive Engineers, Inc. (1990).
genierı́a, Facultad de Ciencias Exactas, Ingenierı́a
Blumberg, P.N., Lavoie, G.A. and Tabaczynsli, R.J.,
y Agrimensura, Universidad Nacional de Rosario
“Phenomenological models for reciprocating inter-
(2003).
nal combustion engines,” Prog. in Energy and
Amsden, A.A., Ramshaw, J.D., O’Rourke, P.J. and Comb. Sci., 23 (1979).
Dukowicz, J.K., KIVA: A Computer Program for
two and three Dimensional Fluid Flows with Chem- Bracco, F.V., “Modeling of engine sprays,” SAE Inter-
ical Reaction and Fuel Spray, Los Alamos Labs., LS national Congress and Exposition, Detroit, Mich.,
10245 MS (1985). USA, SAE Paper N◦ 850394 (1985).
Amsden, A.A., Butler, T.D. and O’Rourke, P.J., Corberan, J.M., “A new constant pressure model for
“KIVA-II computer program for transient multidi- N-branch junctions,” Proc. Inst. Mech. Eng., D
mensional chemically reactive flows with sprays,” J. automob. eng., 206, 117-123 (1992).
Dalcı́n, L., Paz, R. and Storti, M., “MPI for python,” and Exposition, Detroit, Mich., USA, SAE Paper
Journal of Parallel and Distributed Computing, N◦ 970635 (1997).
65(9), 1108-1115 (2005).
Krieger, R.B. and Borman, G.L., “The computation
Dalcı́n, L.D., PETSc for Python: Python of apparent heat release from internal combustion
bindings for PETSc libraries (2005-2007), engines,” ASME paper 66-WA/DGP-4 (1966).
http://code.google.com/p/petsc4py/.
Kyriakides, S.C., Dent, J.C. and Mehta, P.S., “Phe-
Foster, D.E., “An overview of zero-dimensional ther- nomenological diesel combustion model includ-
modynamic models for IC engine data analysis,” ing smoke and NO emission,” SAE International
SAE International Congress and Exposition, De- Congress and Exposition, Detroit, Mich., USA,
troit, Mich., USA, SAE Paper N◦ 852070 (1982). SAE Paper N◦ 860330 (1986).
Hardenberg, H.O. and Hase, F.W., “An empirical for- Mattavi, J.N., Groff, E.G., Lienesch, Matekunas, F.A.
mula for computing the pressure rise delay of a and Noyes, R.N., “Engine improvements through
fuel from its cetane number and from the rele- combustion modelling,” in Combustion Modeling
vant parameters of direct-injection diesel engines,” in Reciprocating Engines, Mattavi and Amann,
SAE International Congress and Exposition, De- Plenum Pres (1980).
troit, Mich., USA, SAE Paper N◦ 790493 (1979).
Message Passing Interface Forum,
Heywood, J.B., “Engine combustion modeling - An http://www.mpi-forum.org/ (1994-2008).
overview,” in Combustion Modeling in Reciprocat- Miyamoto, N., Chikahisa, T., Murayama, T. and
ing Engines, Mattavi and Amann, Plenum Pres Sawyer, R., “Description and analysis of diesel en-
(1980). gine rate of combustion and performance using
Heywood, J., Internal Combustion Engine Fundamen- Wiebe’s functions,” SAE International Congress
tals, McGraw-Hill, New York (1988). and Exposition, Detroit, Mich., USA, SAE Paper
N◦ 850107 (1985).
Hiroyasu, H. and Kadota, T., “Models for combus-
tion and formation of nitric oxide and soot in di- Murayama, T., Miyamoto, N., Yamada, T.,
rect injection diesel engines,” SAE International Kawashima, J.-I. and Itow, K., “A method to im-
Congress and Exposition, Detroit, Mich., USA, prove the solubility and combustion characteristics
SAE Paper N◦ 760129 (1976). of alcohol-diesel fuel blends,” SAE International
Congress and Exposition, Detroit, Mich., USA,
Hiroyasu, H., Kadota, T. and Arai, M., “Development SAE Paper N◦ 821113 (1982).
and use of a spray combustion modeling to pre-
dict diesel engine efficiency and pollutant emissions Nigro, N., Storti, M. and Ambroggi, L., “Modeliza-
(Part 1 combustion modeling),” Bull. Jap. Soc. ción numérica de un motor de combustión interna
Mech. Engrs., 26(214), 569-575 (1983). monocilı́ndrico,” Revista Internacional de Métodos
Numéricos para cálculo y diseño en Ingenierı́a,
Hiroyasu, H., Kadota, T. and Arai, M., “Development 15(1), 21-54 (1999).
and use of a spray combustion modeling to pre-
Oliphant, T.E., Guide to NumPy (2006),
dict diesel engine efficiency and pollutant emissions
http://numpy.scipy.org/.
(Part 2 computational procedure and parametric
study),” Bull. Jap. Soc. Mech. Engrs., 26(214), Oran, E.S. and Boris, J.P., “Detailed modeling of com-
576-583 (1983). bustion systems,” Prog. Energy Combust. Sci., 7,
1-72 (1981).
Hughes, T. and Mallet, M., “A new finite element
method for CFD: the generalized streamline oper- Rakopoulos, C.D. and Hountalas, D.T., “Develop-
ator for multidimensional advection-diffusion sys- ment and validation of a 3-D multi-zone combus-
tems,” Comp. Meth. Applied Mech. Eng., 58, tion model for the prediction of DI diesel engines
305-328 (1986). performance and pollutants emissions,” SAE Inter-
national Congress and Exposition, Detroit, Mich.,
Jung, D. and Assanis, D.N., “Modeling of direct injec-
USA, SAE Paper N◦ 981021 (1998).
tion diesel engine emissions for a quasi-dimensional
multi-zone spray model,” Int. J. Automot. Tech., Ramos, J.I., Internal Combustion Engine Modeling,
5(3), 165-172 (2005). Hemisphere Publishing Corporation (1989).
Kouremenos, D.A., Rakopoulos, C.D. and Hounta- Tezduyar, T. and Hughes, T., “Finite element formula-
las, D.T., “Multi-zone combustion modeling for the tions for convection dominated flows with particu-
prediction of pollutants emissions and performance lar emphasis on the compressible Euler equations,”
of DI diesel engines,” SAE International Congress AIAA, 83-0125 (1983).
Toth, J., Di Nezio, J., Staniscia, C. and López,
E., “Ventajas mecánicas y termodinámicas de un
nuevo motor rotativo,” 9 ◦ Congreso Chileno de In-
genierı́a Mecánica, Valparaı́so, Chile (2000).