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 | Copyright (C) 2011-2016 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 #include "chemistryModel.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class ChemistryModel>
33 (
34  const fvMesh& mesh,
35  const word& phaseName
36 )
37 :
39  coeffsDict_(this->subDict("odeCoeffs")),
40  odeSolver_(ODESolver::New(*this, coeffsDict_)),
41  cTp_(this->nEqns())
42 {}
43 
44 
45 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
46 
47 template<class ChemistryModel>
49 {}
50 
51 
52 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
53 
54 template<class ChemistryModel>
56 (
57  scalarField& c,
58  scalar& T,
59  scalar& p,
60  scalar& deltaT,
61  scalar& subDeltaT
62 ) const
63 {
64  // Reset the size of the ODE system to the simplified size when mechanism
65  // reduction is active
66  if (odeSolver_->resize())
67  {
68  odeSolver_->resizeField(cTp_);
69  }
70 
71  const label nSpecie = this->nSpecie();
72 
73  // Copy the concentration, T and P to the total solve-vector
74  for (int i=0; i<nSpecie; i++)
75  {
76  cTp_[i] = c[i];
77  }
78  cTp_[nSpecie] = T;
79  cTp_[nSpecie+1] = p;
80 
81  odeSolver_->solve(0, deltaT, cTp_, subDeltaT);
82 
83  for (int i=0; i<nSpecie; i++)
84  {
85  c[i] = max(0.0, cTp_[i]);
86  }
87  T = cTp_[nSpecie];
88  p = cTp_[nSpecie+1];
89 }
90 
91 
92 // ************************************************************************* //
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 > &)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
ode(const fvMesh &mesh, const word &phaseName)
Construct from mesh and phase name.
Definition: ode.C:33
label nSpecie
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
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:56
const volScalarField & T
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
volScalarField & p
virtual ~ode()
Destructor.
Definition: ode.C:48