1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(EulerImplicit, 0);
36 addToRunTimeSelectionTable
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 Foam::EulerImplicit::EulerImplicit
49 const Foam::dictionary& dict,
50 Foam::chemistryModel& chemistry
53 chemistrySolver(dict, chemistry),
54 coeffsDict_(dict.subDict(typeName + "Coeffs")),
55 cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
56 equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
60 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 Foam::EulerImplicit::~EulerImplicit()
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 Foam::scalar Foam::EulerImplicit::solve
78 scalar pf, cf, pr, cr;
81 label Ns = chemistry_.Ns();
82 simpleMatrix<scalar> RR(Ns);
84 for(label i=0; i<Ns; i++)
86 c[i] = max(0.0, c[i]);
89 for(label i=0; i<Ns; i++)
91 RR.source()[i] = c[i]/dt;
94 for(label i=0; i<chemistry_.reactions().size(); i++)
96 const chemistryModel::reaction& R = chemistry_.reactions()[i];
98 scalar omegai = chemistry_.omega
100 R, c, T, p, pf, cf, lRef, pr, cr, rRef
108 corr = 1.0/(1.0 + pr*dt);
112 corr = 1.0/(1.0 + pf*dt);
116 for(label s=0; s<R.lhs().size(); s++)
118 label si = R.lhs()[s].index;
119 scalar sl = R.lhs()[s].stoichCoeff;
120 RR[si][rRef] -= sl*pr*corr;
121 RR[si][lRef] += sl*pf*corr;
124 for(label s=0; s<R.rhs().size(); s++)
126 label si = R.rhs()[s].index;
127 scalar sr = R.rhs()[s].stoichCoeff;
128 RR[si][lRef] -= sr*pf*corr;
129 RR[si][rRef] += sr*pr*corr;
132 } // end for(label i...
135 for(label i=0; i<Ns; i++)
141 for(label i=0; i<Ns; i++)
143 c[i] = max(0.0, c[i]);
146 // estimate the next time step
148 label n = chemistry_.nEqns();
149 scalarField c1(n, 0.0);
151 for(label i=0; i<Ns; i++)
158 scalarField dcdt(n, 0.0);
159 chemistry_.derivatives(0.0, c1, dcdt);
161 scalar sumC = sum(c);
163 for(label i=0; i<Ns; i++)
168 tMin = min(tMin, -(c[i]+SMALL)/d);
173 scalar cm = max(sumC - c[i], 1.0e-5);
174 tMin = min(tMin, cm/d);
178 return cTauChem_*tMin;
183 // ************************************************************************* //