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-2021 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>
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  scalar& p,
53  scalar& T,
54  scalarField& c,
55  const label li,
56  scalar& deltaT,
57  scalar& subDeltaT
58 ) const
59 {
60  // Reset the size of the ODE system to the simplified size when mechanism
61  // reduction is active
62  if (odeSolver_->resize())
63  {
64  odeSolver_->resizeField(cTp_);
65  }
66 
67  const label nSpecie = this->nSpecie();
68 
69  // Copy the concentration, T and P to the total solve-vector
70  for (int i=0; i<nSpecie; i++)
71  {
72  cTp_[i] = c[i];
73  }
74  cTp_[nSpecie] = T;
75  cTp_[nSpecie+1] = p;
76 
77  if (debug)
78  {
79  scalarField dcTp(this->nEqns(), rootSmall);
80  dcTp[nSpecie] = T*rootSmall;
81  dcTp[nSpecie+1] = p*rootSmall;
82  this->check(0, cTp_, dcTp, li);
83  }
84 
85  odeSolver_->solve(0, deltaT, cTp_, li, subDeltaT);
86 
87  for (int i=0; i<nSpecie; i++)
88  {
89  c[i] = max(0.0, cTp_[i]);
90  }
91  T = cTp_[nSpecie];
92  p = cTp_[nSpecie+1];
93 }
94 
95 
96 // ************************************************************************* //
An abstract base class for solving chemistry.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
fluidReactionThermo & thermo
Definition: createFields.H:28
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
virtual void solve(scalar &p, scalar &T, scalarField &c, const label li, scalar &deltaT, scalar &subDeltaT) const
Update the concentrations and return the chemical time.
Definition: ode.C:51
Base-class for multi-component fluid thermodynamic properties.
const label nSpecie
ode(const fluidReactionThermo &thermo)
Construct from thermo.
Definition: ode.C:31
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
volScalarField & p
virtual ~ode()
Destructor.
Definition: ode.C:43