initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / chemistryModel / chemistrySolver / EulerImplicit / EulerImplicit.C
blob95cfc763881b4ae68bb1e1db21e0402501299a55
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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,
37     const word& modelName
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
59     scalarField &c,
60     const scalar T,
61     const scalar p,
62     const scalar t0,
63     const scalar dt
64 ) const
66     scalar pf, cf, pr, cr;
67     label lRef, rRef;
69     label nSpecie = this->model_.nSpecie();
70     simpleMatrix<scalar> RR(nSpecie);
72     for (label i=0; i<nSpecie; i++)
73     {
74         c[i] = max(0.0, c[i]);
75     }
77     for (label i=0; i<nSpecie; i++)
78     {
79         RR.source()[i] = c[i]/dt;
80     }
82     for (label i=0; i<this->model_.reactions().size(); i++)
83     {
84         const Reaction<ThermoType>& R = this->model_.reactions()[i];
86         scalar omegai = this->model_.omega
87         (
88             R, c, T, p, pf, cf, lRef, pr, cr, rRef
89         );
91         scalar corr = 1.0;
92         if (equil_)
93         {
94             if (omegai<0.0)
95             {
96                 corr = 1.0/(1.0 + pr*dt);
97             }
98             else
99             {
100                 corr = 1.0/(1.0 + pf*dt);
101             }
102         }
104         for (label s=0; s<R.lhs().size(); s++)
105         {
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;
110         }
112         for (label s=0; s<R.rhs().size(); s++)
113         {
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;
118         }
120     } // end for(label i...
123     for (label i=0; i<nSpecie; i++)
124     {
125         RR[i][i] += 1.0/dt;
126     }
128     c = RR.LUsolve();
129     for (label i=0; i<nSpecie; i++)
130     {
131         c[i] = max(0.0, c[i]);
132     }
134     // estimate the next time step
135     scalar tMin = GREAT;
136     label nEqns = this->model_.nEqns();
137     scalarField c1(nEqns, 0.0);
139     for (label i=0; i<nSpecie; i++)
140     {
141         c1[i] = c[i];
142     }
143     c1[nSpecie] = T;
144     c1[nSpecie+1] = p;
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++)
152     {
153         scalar d = dcdt[i];
154         if (d < -SMALL)
155         {
156             tMin = min(tMin, -(c[i] + SMALL)/d);
157         }
158         else
159         {
160             d = max(d, SMALL);
161             scalar cm = max(sumC - c[i], 1.0e-5);
162             tMin = min(tMin, cm/d);
163         }
164     }
166     return cTauChem_*tMin;
170 // ************************************************************************* //