initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / chemistryModel / chemistrySolver / sequential / sequential.C
blobd929c5aea2e12a3d426441418db6319ffead318c
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 "sequential.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 template<class CompType, class ThermoType>
33 Foam::sequential<CompType, ThermoType>::sequential
35     ODEChemistryModel<CompType, ThermoType>& model,
36     const word& modelName
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::sequential<CompType, ThermoType>::~sequential()
53 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
55 template<class CompType, class ThermoType>
56 Foam::scalar Foam::sequential<CompType, ThermoType>::solve
58     scalarField &c,
59     const scalar T,
60     const scalar p,
61     const scalar t0,
62     const scalar dt
63 ) const
65     scalar tChemInv = SMALL;
67     scalar pf, cf, pb, cb;
68     label lRef, rRef;
70     for (label i=0; i<this->model_.reactions().size(); i++)
71     {
72         const Reaction<ThermoType>& R = this->model_.reactions()[i];
74         scalar om0 = this->model_.omega
75         (
76             R, c, T, p, pf, cf, lRef, pb, cb, rRef
77         );
79         scalar omeg = 0.0;
80         if (!equil_)
81         {
82             omeg = om0;
83         }
84         else
85         {
86             if (om0<0.0)
87             {
88                 omeg = om0/(1.0 + pb*dt);
89             }
90             else
91             {
92                 omeg = om0/(1.0 + pf*dt);
93             }
94         }
95         tChemInv = max(tChemInv, mag(omeg));
98         // update species
99         for (label s=0; s<R.lhs().size(); s++)
100         {
101             label si = R.lhs()[s].index;
102             scalar sl = R.lhs()[s].stoichCoeff;
103             c[si] -= dt*sl*omeg;
104             c[si] = max(0.0, c[si]);
105         }
107         for (label s=0; s<R.rhs().size(); s++)
108         {
109             label si = R.rhs()[s].index;
110             scalar sr = R.rhs()[s].stoichCoeff;
111             c[si] += dt*sr*omeg;
112             c[si] = max(0.0, c[si]);
113         }
115     } // end for (label i...
117     return cTauChem_/tChemInv;
121 // ************************************************************************* //