ode.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "ode.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class ChemistryModel>
33 Foam::ode<ChemistryModel>::ode(typename ChemistryModel::reactionThermo& thermo)
34 :
35  chemistrySolver<ChemistryModel>(thermo),
36  coeffsDict_(this->subDict("odeCoeffs")),
37  odeSolver_(ODESolver::New(*this, coeffsDict_)),
38  cTp_(this->nEqns())
39 {}
40 
41 
42 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
43 
44 template<class ChemistryModel>
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
51 template<class ChemistryModel>
53 (
54  scalarField& c,
55  scalar& T,
56  scalar& p,
57  scalar& deltaT,
58  scalar& subDeltaT
59 ) const
60 {
61  // Reset the size of the ODE system to the simplified size when mechanism
62  // reduction is active
63  if (odeSolver_->resize())
64  {
65  odeSolver_->resizeField(cTp_);
66  }
67 
68  const label nSpecie = this->nSpecie();
69 
70  // Copy the concentration, T and P to the total solve-vector
71  for (int i=0; i<nSpecie; i++)
72  {
73  cTp_[i] = c[i];
74  }
75  cTp_[nSpecie] = T;
76  cTp_[nSpecie+1] = p;
77 
78  odeSolver_->solve(0, deltaT, cTp_, subDeltaT);
79 
80  for (int i=0; i<nSpecie; i++)
81  {
82  c[i] = max(0.0, cTp_[i]);
83  }
84  T = cTp_[nSpecie];
85  p = cTp_[nSpecie+1];
86 }
87 
88 
89 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::ODESolver
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:56
Foam::chemistrySolver
An abstract base class for solving chemistry.
Definition: chemistrySolver.H:52
nSpecie
label nSpecie
Definition: readInitialConditions.H:17
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::ode::~ode
virtual ~ode()
Destructor.
Definition: ode.C:45
ode.H
Foam::Field< scalar >
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::ode::ode
ode(typename ChemistryModel::reactionThermo &thermo)
Construct from thermo.
Definition: ode.C:33
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::ode::solve
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:53
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.