Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / thermophysicalModels / chemistryModel / chemistrySolver / sequential / sequential.C
blobf0367f078c69056f20f91f96895914df04970086
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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 "sequential.H"
27 #include "addToRunTimeSelectionTable.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 template<class CompType, class ThermoType>
32 Foam::sequential<CompType, ThermoType>::sequential
34     ODEChemistryModel<CompType, ThermoType>& model,
35     const word& modelName
38     chemistrySolver<CompType, ThermoType>(model, modelName),
39     coeffsDict_(model.subDict(modelName + "Coeffs")),
40     cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
41     equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
45 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
47 template<class CompType, class ThermoType>
48 Foam::sequential<CompType, ThermoType>::~sequential()
52 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
54 template<class CompType, class ThermoType>
55 Foam::scalar Foam::sequential<CompType, ThermoType>::solve
57     scalarField &c,
58     const scalar T,
59     const scalar p,
60     const scalar t0,
61     const scalar dt
62 ) const
64     scalar tChemInv = SMALL;
66     scalar pf, cf, pb, cb;
67     label lRef, rRef;
69     for (label i=0; i<this->model_.reactions().size(); i++)
70     {
71         const Reaction<ThermoType>& R = this->model_.reactions()[i];
73         scalar om0 = this->model_.omega
74         (
75             R, c, T, p, pf, cf, lRef, pb, cb, rRef
76         );
78         scalar omeg = 0.0;
79         if (!equil_)
80         {
81             omeg = om0;
82         }
83         else
84         {
85             if (om0<0.0)
86             {
87                 omeg = om0/(1.0 + pb*dt);
88             }
89             else
90             {
91                 omeg = om0/(1.0 + pf*dt);
92             }
93         }
94         tChemInv = max(tChemInv, mag(omeg));
97         // update species
98         for (label s=0; s<R.lhs().size(); s++)
99         {
100             label si = R.lhs()[s].index;
101             scalar sl = R.lhs()[s].stoichCoeff;
102             c[si] -= dt*sl*omeg;
103             c[si] = max(0.0, c[si]);
104         }
106         for (label s=0; s<R.rhs().size(); s++)
107         {
108             label si = R.rhs()[s].index;
109             scalar sr = R.rhs()[s].stoichCoeff;
110             c[si] += dt*sr*omeg;
111             c[si] = max(0.0, c[si]);
112         }
114     } // end for (label i...
116     return cTauChem_/tChemInv;
120 // ************************************************************************* //