initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / thermophysicalModels / chemistryModel / chemistrySolver / sequential / sequential.C
blob0cfc959348e0ddd1689d2d086f3fc13ba6e6fece
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 "sequential.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTypeNameAndDebug(sequential, 0);
35     addToRunTimeSelectionTable
36     (
37         chemistrySolver,
38         sequential,
39         dictionary
40     );
44 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
46 // Construct from components
47 Foam::sequential::sequential
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::sequential::~sequential()
66 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
68 Foam::scalar Foam::sequential::solve
70     scalarField &c,
71     const scalar T,
72     const scalar p,
73     const scalar t0,
74     const scalar dt
75 ) const
77     scalar tChemInv = SMALL;
79     scalar pf, cf, pb, cb;
80     label lRef, rRef;
82     for(label i=0; i<chemistry_.reactions().size(); i++)
83     {
84         const chemistryModel::reaction& R = chemistry_.reactions()[i];
86         scalar om0 = chemistry_.omega
87         (
88             R, c, T, p, pf, cf, lRef, pb, cb, rRef
89         );
91         scalar omeg = 0.0;
92         if (!equil_)
93         {
94             omeg = om0;
95         }
96         else
97         {
98             if (om0<0.0)
99             {
100                 omeg = om0/(1.0 + pb*dt);
101             }
102             else
103             {
104                 omeg = om0/(1.0 + pf*dt);
105             }
106         }
107         tChemInv = max(tChemInv, mag(omeg));
110         // update species
111         for(label s=0; s<R.lhs().size(); s++)
112         {
113             label si = R.lhs()[s].index;
114             scalar sl = R.lhs()[s].stoichCoeff;
115             c[si] -= dt*sl*omeg;
116             c[si] = max(0.0, c[si]);
117         }        
119         for(label s=0; s<R.rhs().size(); s++)
120         {
121             label si = R.rhs()[s].index;
122             scalar sr = R.rhs()[s].stoichCoeff;
123             c[si] += dt*sr*omeg;
124             c[si] = max(0.0, c[si]);
125         }        
127     } // end for(label i...
129     return cTauChem_/tChemInv;
133 // ************************************************************************* //