1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "EulerImplicit.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "simpleMatrix.H"
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 template<class CompType, class ThermoType>
33 Foam::EulerImplicit<CompType, ThermoType>::EulerImplicit
35 ODEChemistryModel<CompType, ThermoType>& model,
39 chemistrySolver<CompType, ThermoType>(model, modelName),
40 coeffsDict_(model.subDict(modelName + "Coeffs")),
41 cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
42 equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
46 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
48 template<class CompType, class ThermoType>
49 Foam::EulerImplicit<CompType, ThermoType>::~EulerImplicit()
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 template<class CompType, class ThermoType>
56 Foam::scalar Foam::EulerImplicit<CompType, ThermoType>::solve
65 scalar pf, cf, pr, cr;
68 label nSpecie = this->model_.nSpecie();
69 simpleMatrix<scalar> RR(nSpecie);
71 for (label i=0; i<nSpecie; i++)
73 c[i] = max(0.0, c[i]);
76 for (label i=0; i<nSpecie; i++)
78 RR.source()[i] = c[i]/dt;
81 for (label i=0; i<this->model_.reactions().size(); i++)
83 const Reaction<ThermoType>& R = this->model_.reactions()[i];
85 scalar omegai = this->model_.omega
87 R, c, T, p, pf, cf, lRef, pr, cr, rRef
95 corr = 1.0/(1.0 + pr*dt);
99 corr = 1.0/(1.0 + pf*dt);
103 for (label s=0; s<R.lhs().size(); s++)
105 label si = R.lhs()[s].index;
106 scalar sl = R.lhs()[s].stoichCoeff;
107 RR[si][rRef] -= sl*pr*corr;
108 RR[si][lRef] += sl*pf*corr;
111 for (label s=0; s<R.rhs().size(); s++)
113 label si = R.rhs()[s].index;
114 scalar sr = R.rhs()[s].stoichCoeff;
115 RR[si][lRef] -= sr*pf*corr;
116 RR[si][rRef] += sr*pr*corr;
119 } // end for(label i...
122 for (label i=0; i<nSpecie; i++)
128 for (label i=0; i<nSpecie; i++)
130 c[i] = max(0.0, c[i]);
133 // estimate the next time step
135 label nEqns = this->model_.nEqns();
136 scalarField c1(nEqns, 0.0);
138 for (label i=0; i<nSpecie; i++)
145 scalarField dcdt(nEqns, 0.0);
146 this->model_.derivatives(0.0, c1, dcdt);
148 scalar sumC = sum(c);
150 for (label i=0; i<nSpecie; i++)
155 tMin = min(tMin, -(c[i] + SMALL)/d);
160 scalar cm = max(sumC - c[i], 1.0e-5);
161 tMin = min(tMin, cm/d);
165 return cTauChem_*tMin;
169 // ************************************************************************* //