initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / thermophysicalModels / chemistryModel / chemistrySolver / EulerImplicit / EulerImplicit.C
blob0eb941331836c1c5298baff9c6641e6b24a81f69
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(EulerImplicit, 0);
36     addToRunTimeSelectionTable
37     (
38         chemistrySolver,
39         EulerImplicit,
40         dictionary
41     );
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
70     scalarField &c,
71     const scalar T,
72     const scalar p,
73     const scalar t0,
74     const scalar dt
75 ) const
78     scalar pf, cf, pr, cr;
79     label lRef, rRef;
81     label Ns = chemistry_.Ns();
82     simpleMatrix<scalar> RR(Ns);
83     
84     for(label i=0; i<Ns; i++)
85     {
86         c[i] = max(0.0, c[i]);
87     }
89     for(label i=0; i<Ns; i++)
90     {
91         RR.source()[i] = c[i]/dt;
92     }
94     for(label i=0; i<chemistry_.reactions().size(); i++)
95     {
96         const chemistryModel::reaction& R = chemistry_.reactions()[i];
98         scalar omegai = chemistry_.omega
99         (
100             R, c, T, p, pf, cf, lRef, pr, cr, rRef
101         );
103         scalar corr = 1.0;
104         if (equil_)
105         {
106             if (omegai<0.0)
107             {
108                 corr = 1.0/(1.0 + pr*dt);
109             }
110             else
111             {
112                 corr = 1.0/(1.0 + pf*dt);
113             }
114         }
116         for(label s=0; s<R.lhs().size(); s++)
117         {
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;
122         }
123             
124         for(label s=0; s<R.rhs().size(); s++)
125         {
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;
130         }
131         
132     } // end for(label i...
134     
135     for(label i=0; i<Ns; i++)
136     {
137         RR[i][i] += 1.0/dt;
138     }
140     c = RR.LUsolve();
141     for(label i=0; i<Ns; i++)
142     {
143         c[i] = max(0.0, c[i]);
144     }
146     // estimate the next time step
147     scalar tMin = GREAT;
148     label n = chemistry_.nEqns();
149     scalarField c1(n, 0.0);
151     for(label i=0; i<Ns; i++)
152     {
153         c1[i] = c[i];
154     }
155     c1[Ns] = T;
156     c1[Ns+1] = p;
158     scalarField dcdt(n, 0.0);
159     chemistry_.derivatives(0.0, c1, dcdt);
160     
161     scalar sumC = sum(c);
163     for(label i=0; i<Ns; i++)
164     {
165         scalar d = dcdt[i];
166         if (d < -SMALL)
167         {
168             tMin = min(tMin, -(c[i]+SMALL)/d);
169         }
170         else
171         {
172             d = max(d, SMALL);
173             scalar cm = max(sumC - c[i], 1.0e-5);
174             tMin = min(tMin, cm/d);
175         }
176     }    
178     return cTauChem_*tMin;
183 // ************************************************************************* //