1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "EulerImplicit.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "simpleMatrix.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 template<class CompType, class ThermoType>
34 Foam::EulerImplicit<CompType, ThermoType>::EulerImplicit
36 ODEChemistryModel<CompType, ThermoType>& model,
40 chemistrySolver<CompType, ThermoType>(model, modelName),
41 coeffsDict_(model.subDict(modelName + "Coeffs")),
42 cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
43 equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
47 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
49 template<class CompType, class ThermoType>
50 Foam::EulerImplicit<CompType, ThermoType>::~EulerImplicit()
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 template<class CompType, class ThermoType>
57 Foam::scalar Foam::EulerImplicit<CompType, ThermoType>::solve
66 scalar pf, cf, pr, cr;
69 label nSpecie = this->model_.nSpecie();
70 simpleMatrix<scalar> RR(nSpecie);
72 for (label i=0; i<nSpecie; i++)
74 c[i] = max(0.0, c[i]);
77 for (label i=0; i<nSpecie; i++)
79 RR.source()[i] = c[i]/dt;
82 for (label i=0; i<this->model_.reactions().size(); i++)
84 const Reaction<ThermoType>& R = this->model_.reactions()[i];
86 scalar omegai = this->model_.omega
88 R, c, T, p, pf, cf, lRef, pr, cr, rRef
96 corr = 1.0/(1.0 + pr*dt);
100 corr = 1.0/(1.0 + pf*dt);
104 for (label s=0; s<R.lhs().size(); s++)
106 label si = R.lhs()[s].index;
107 scalar sl = R.lhs()[s].stoichCoeff;
108 RR[si][rRef] -= sl*pr*corr;
109 RR[si][lRef] += sl*pf*corr;
112 for (label s=0; s<R.rhs().size(); s++)
114 label si = R.rhs()[s].index;
115 scalar sr = R.rhs()[s].stoichCoeff;
116 RR[si][lRef] -= sr*pf*corr;
117 RR[si][rRef] += sr*pr*corr;
120 } // end for(label i...
123 for (label i=0; i<nSpecie; i++)
129 for (label i=0; i<nSpecie; i++)
131 c[i] = max(0.0, c[i]);
134 // estimate the next time step
136 label nEqns = this->model_.nEqns();
137 scalarField c1(nEqns, 0.0);
139 for (label i=0; i<nSpecie; i++)
146 scalarField dcdt(nEqns, 0.0);
147 this->model_.derivatives(0.0, c1, dcdt);
149 scalar sumC = sum(c);
151 for (label i=0; i<nSpecie; i++)
156 tMin = min(tMin, -(c[i] + SMALL)/d);
161 scalar cm = max(sumC - c[i], 1.0e-5);
162 tMin = min(tMin, cm/d);
166 return cTauChem_*tMin;
170 // ************************************************************************* //