ode.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ode.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class ChemistryModel>
31 Foam::ode<ChemistryModel>::ode(typename ChemistryModel::reactionThermo& thermo)
32 :
33  chemistrySolver<ChemistryModel>(thermo),
34  coeffsDict_(this->subDict("odeCoeffs")),
35  odeSolver_(ODESolver::New(*this, coeffsDict_)),
36  cTp_(this->nEqns())
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
41 
42 template<class ChemistryModel>
44 {}
45 
46 
47 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
48 
49 template<class ChemistryModel>
51 (
52  scalarField& c,
53  scalar& T,
54  scalar& p,
55  scalar& deltaT,
56  scalar& subDeltaT
57 ) const
58 {
59  // Reset the size of the ODE system to the simplified size when mechanism
60  // reduction is active
61  if (odeSolver_->resize())
62  {
63  odeSolver_->resizeField(cTp_);
64  }
65 
66  const label nSpecie = this->nSpecie();
67 
68  // Copy the concentration, T and P to the total solve-vector
69  for (int i=0; i<nSpecie; i++)
70  {
71  cTp_[i] = c[i];
72  }
73  cTp_[nSpecie] = T;
74  cTp_[nSpecie+1] = p;
75 
76  odeSolver_->solve(0, deltaT, cTp_, subDeltaT);
77 
78  for (int i=0; i<nSpecie; i++)
79  {
80  c[i] = max(0.0, cTp_[i]);
81  }
82  T = cTp_[nSpecie];
83  p = cTp_[nSpecie+1];
84 }
85 
86 
87 // ************************************************************************* //
An abstract base class for solving chemistry.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
rhoReactionThermo & thermo
Definition: createFields.H:28
const label nSpecie
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
virtual void solve(scalarField &c, scalar &T, scalar &p, scalar &deltaT, scalar &subDeltaT) const
Update the concentrations and return the chemical time.
Definition: ode.C:51
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
ode(typename ChemistryModel::reactionThermo &thermo)
Construct from thermo.
Definition: ode.C:31
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
volScalarField & p
virtual ~ode()
Destructor.
Definition: ode.C:43