TDACChemistryModel.H
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) 2016-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 Class
25  Foam::TDACChemistryModel
26 
27 Description
28  Extends standardChemistryModel by adding the TDAC method.
29 
30  References:
31  \verbatim
32  Contino, F., Jeanmart, H., Lucchini, T., & D’Errico, G. (2011).
33  Coupling of in situ adaptive tabulation and dynamic adaptive chemistry:
34  An effective method for solving combustion in engine simulations.
35  Proceedings of the Combustion Institute, 33(2), 3057-3064.
36 
37  Contino, F., Lucchini, T., D'Errico, G., Duynslaegher, C.,
38  Dias, V., & Jeanmart, H. (2012).
39  Simulations of advanced combustion modes using detailed chemistry
40  combined with tabulation and mechanism reduction techniques.
41  SAE International Journal of Engines,
42  5(2012-01-0145), 185-196.
43 
44  Contino, F., Foucher, F., Dagaut, P., Lucchini, T., D’Errico, G., &
45  Mounaïm-Rousselle, C. (2013).
46  Experimental and numerical analysis of nitric oxide effect on the
47  ignition of iso-octane in a single cylinder HCCI engine.
48  Combustion and Flame, 160(8), 1476-1483.
49 
50  Contino, F., Masurier, J. B., Foucher, F., Lucchini, T., D’Errico, G., &
51  Dagaut, P. (2014).
52  CFD simulations using the TDAC method to model iso-octane combustion
53  for a large range of ozone seeding and temperature conditions
54  in a single cylinder HCCI engine.
55  Fuel, 137, 179-184.
56  \endverbatim
57 
58 SourceFiles
59  TDACChemistryModelI.H
60  TDACChemistryModel.C
61 
62 \*---------------------------------------------------------------------------*/
63 
64 #ifndef TDACChemistryModel_H
65 #define TDACChemistryModel_H
66 
67 #include "standardChemistryModel.H"
70 #include "OFstream.H"
71 
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74 namespace Foam
75 {
76 
77 /*---------------------------------------------------------------------------*\
78  Class TDACChemistryModel Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class ThermoType>
82 class TDACChemistryModel
83 :
84  public standardChemistryModel<ThermoType>
85 {
86  // Private member data
87 
88  label timeSteps_;
89 
90  // Mechanism reduction
91  label NsDAC_;
92  scalarField completeC_;
93  scalarField simplifiedC_;
94  Field<bool> reactionsDisabled_;
95  Field<label> completeToSimplifiedIndex_;
96  DynamicList<label> simplifiedToCompleteIndex_;
97  autoPtr<chemistryReductionMethod<ThermoType>> mechRed_;
98 
99  // Tabulation
100  autoPtr<chemistryTabulationMethod<ThermoType>> tabulation_;
101 
102  // Log file for the average time spent reducing the chemistry
103  autoPtr<OFstream> cpuReduceFile_;
104 
105  // Write average number of species
106  autoPtr<OFstream> nActiveSpeciesFile_;
107 
108  //- Log file for the average time spent adding tabulated data
109  autoPtr<OFstream> cpuAddFile_;
110 
111  //- Log file for the average time spent growing tabulated data
112  autoPtr<OFstream> cpuGrowFile_;
113 
114  //- Log file for the average time spent retrieving tabulated data
115  autoPtr<OFstream> cpuRetrieveFile_;
116 
117  //- Log file for average time spent solving the chemistry
118  autoPtr<OFstream> cpuSolveFile_;
119 
120  // Field containing information about tabulation:
121  // 0 -> add (direct integration)
122  // 1 -> grow
123  // 2 -> retrieve
124  volScalarField tabulationResults_;
125 
126 
127  // Private Member Functions
128 
129  //- Solve the reaction system for the given time step
130  // of given type and return the characteristic time
131  // Variable number of species added
132  template<class DeltaTType>
133  scalar solve(const DeltaTType& deltaT);
134 
135 
136 public:
137 
138  //- Runtime type information
139  TypeName("TDAC");
140 
141 
142  // Constructors
143 
144  //- Construct from thermo
145  TDACChemistryModel(const fluidReactionThermo& thermo);
146 
147  //- Disallow default bitwise copy construction
148  TDACChemistryModel(const TDACChemistryModel&) = delete;
149 
150 
151  //- Destructor
152  virtual ~TDACChemistryModel();
153 
154 
155  // Member Functions
156 
157  //- Return the number of chemistry evaluations (used by ISAT)
158  inline label timeSteps() const;
159 
160  //- Create and return a TDAC log file of the given name
161  inline autoPtr<OFstream> logFile(const word& name) const;
162 
163  //- Return a reference to the list of mass fraction fields
164  inline const PtrList<volScalarField>& Y();
165 
166  //- dc/dt = omega, rate of change in concentration, for each species
167  virtual void omega
168  (
169  const scalar p,
170  const scalar T,
171  const scalarField& c,
172  const label li,
173  scalarField& dcdt
174  ) const;
175 
176 
177  // Chemistry model functions (overriding functions in
178  // standardChemistryModel to use the private solve function)
179 
180  //- Solve the reaction system for the given time step
181  // and return the characteristic time
182  virtual scalar solve(const scalar deltaT);
183 
184  //- Solve the reaction system for the given time step
185  // and return the characteristic time
186  virtual scalar solve(const scalarField& deltaT);
187 
188 
189  // ODE functions (overriding functions in standardChemistryModel to take
190  // into account the variable number of species)
191 
192  virtual void derivatives
193  (
194  const scalar t,
195  const scalarField& c,
196  const label li,
197  scalarField& dcdt
198  ) const;
199 
200  virtual void jacobian
201  (
202  const scalar t,
203  const scalarField& c,
204  const label li,
205  scalarField& dcdt,
207  ) const;
208 
209  virtual void solve
210  (
211  scalar& p,
212  scalar& T,
213  scalarField& c,
214  const label li,
215  scalar& deltaT,
216  scalar& subDeltaT
217  ) const = 0;
218 
219 
220  // Mechanism reduction access functions
221 
222  inline void setNsDAC(const label newNsDAC);
223 
224  inline void setNSpecie(const label newNs);
225 
226  inline scalarField& completeC();
227 
228  inline scalarField& simplifiedC();
229 
230  inline Field<bool>& reactionsDisabled();
231 
232  inline bool active(const label i) const;
233 
234  inline void setActive(const label i);
235 
236  inline DynamicList<label>& simplifiedToCompleteIndex();
237 
238  inline Field<label>& completeToSimplifiedIndex();
239 
240  inline const Field<label>& completeToSimplifiedIndex() const;
241 
242  inline autoPtr<chemistryReductionMethod<ThermoType>>& mechRed();
243 
244  inline tmp<volScalarField> tabulationResults() const;
245 
246  void setTabulationResultsAdd(const label celli);
247 
248  void setTabulationResultsGrow(const label celli);
249 
250  void setTabulationResultsRetrieve(const label celli);
251 
252  inline void resetTabulationResults();
253 
254 
255  // Member Operators
256 
257  //- Disallow default bitwise assignment
258  void operator=(const TDACChemistryModel&) = delete;
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #include "TDACChemistryModelI.H"
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #ifdef NoRepository
273  #include "TDACChemistryModel.C"
274 #endif
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #endif
279 
280 // ************************************************************************* //
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
void setTabulationResultsGrow(const label celli)
void setTabulationResultsRetrieve(const label celli)
Field< label > & completeToSimplifiedIndex()
const PtrList< volScalarField > & Y()
Return a reference to the list of mass fraction fields.
virtual ~TDACChemistryModel()
Destructor.
const dimensionedScalar c
Speed of light in a vacuum.
TypeName("TDAC")
Runtime type information.
autoPtr< chemistryReductionMethod< ThermoType > > & mechRed()
DynamicList< label > & simplifiedToCompleteIndex()
Field< bool > & reactionsDisabled()
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
void setNsDAC(const label newNsDAC)
tmp< volScalarField > tabulationResults() const
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:109
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
label timeSteps() const
Return the number of chemistry evaluations (used by ISAT)
virtual void omega(const scalar p, const scalar T, const scalarField &c, const label li, scalarField &dcdt) const
dc/dt = omega, rate of change in concentration, for each species
TDACChemistryModel(const fluidReactionThermo &thermo)
Construct from thermo.
void setTabulationResultsAdd(const label celli)
void setNSpecie(const label newNs)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const fluidReactionThermo & thermo() const
Return const access to the thermo.
bool active(const label i) const
virtual void derivatives(const scalar t, const scalarField &c, const label li, scalarField &dcdt) const
Calculate the derivatives in dydx.
autoPtr< OFstream > logFile(const word &name) const
Create and return a TDAC log file of the given name.
volScalarField & p
void setActive(const label i)
virtual void jacobian(const scalar t, const scalarField &c, const label li, scalarField &dcdt, scalarSquareMatrix &J) const
Calculate the Jacobian of the system.
SquareMatrix< scalar > scalarSquareMatrix
void operator=(const TDACChemistryModel &)=delete
Disallow default bitwise assignment.
Namespace for OpenFOAM.