specieReactionRates.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) 2016-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "specieReactionRates.H"
30 #include "volFields.H"
31 #include "fvcVolumeIntegrate.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class ChemistryModelType>
38 (
39  Ostream& os
40 ) const
41 {
42  writeHeader(os, "Specie reaction rates");
43  volRegion::writeFileHeader(*this, os);
44  writeHeaderValue(os, "nSpecie", chemistryModel_.nSpecie());
45  writeHeaderValue(os, "nReaction", chemistryModel_.nReaction());
46 
47  writeCommented(os, "Time");
48  writeTabbed(os, "Reaction");
49 
50  const wordList& speciesNames =
51  chemistryModel_.thermo().composition().species();
52 
53  for (const word& speciesName : speciesNames)
54  {
55  writeTabbed(os, speciesName);
56  }
57 
58  os << endl;
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 template<class ChemistryModelType>
67 (
68  const word& name,
69  const Time& runTime,
70  const dictionary& dict
71 )
72 :
75  writeFile(obr_, name, typeName, dict),
76  chemistryModel_
77  (
78  fvMeshFunctionObject::mesh_.lookupObject<ChemistryModelType>
79  (
80  "chemistryProperties"
81  )
82  )
83 {
84  writeFileHeader(file());
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 template<class ChemistryModelType>
92 (
93  const dictionary& dict
94 )
95 {
97 
98  return true;
99 }
100 
101 
102 template<class ChemistryModelType>
104 {
105  return true;
106 }
107 
108 
109 template<class ChemistryModelType>
111 {
112  const label nSpecie = chemistryModel_.nSpecie();
113  const label nReaction = chemistryModel_.nReaction();
114 
115  volRegion::update(); // Ensure cached values are valid
116 
117  const scalar volTotal = this->volRegion::V();
118 
119  const bool useAll = this->volRegion::useAllCells();
120 
121  for (label ri=0; ri<nReaction; ri++)
122  {
123  writeCurrentTime(file());
124  file() << token::TAB << ri;
125 
126  for (label si=0; si<nSpecie; si++)
127  {
129  (
130  chemistryModel_.calculateRR(ri, si)
131  );
132 
133  scalar sumVRRi = 0;
134 
135  if (useAll)
136  {
137  sumVRRi = fvc::domainIntegrate(RR).value();
138  }
139  else
140  {
141  sumVRRi = gSum
142  (
144  );
145  }
146 
147  file() << token::TAB << sumVRRi / volTotal;
148  }
149 
150  file() << nl;
151  }
152 
153  file() << nl << endl;
154 
155  return true;
156 }
157 
158 
159 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
160 
162 #include "BasicChemistryModel.H"
163 #include "psiReactionThermo.H"
164 #include "rhoReactionThermo.H"
165 
166 namespace Foam
167 {
168  typedef
170  <
172  <
174  >
175  >
177 
179  (
181  "psiSpecieReactionRates",
182  0
183  );
184 
186  (
189  dictionary
190  );
191 
192 
193  typedef
195  <
197  <
199  >
200  >
202 
204  (
206  "rhoSpecieReactionRates",
207  0
208  );
209 
211  (
214  dictionary
215  );
216 }
217 
218 
219 // ************************************************************************* //
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:264
dictionary dict
Basic chemistry model templated on thermodynamics.
static void writeHeader(Ostream &os, const word &fieldName)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Tab [isspace].
Definition: token.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual bool write()
Write the specie reaction rates.
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
dimensioned< Type > domainIntegrate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Abstract base-class for Time/database function objects.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
bool useAllCells() const noexcept
Use all cells, not the cellIDs.
Definition: volRegionI.H:24
Macros for easy insertion into run-time selection tables.
label nSpecie
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Foam::rhoReactionThermo.
Volume integrate volField creating a volField.
scalar V() const
Return total volume of the selected region.
Definition: volRegionI.H:52
Foam::psiReactionThermo.
Volume (cell) region selection class.
Definition: volRegion.H:111
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
List< word > wordList
List of word.
Definition: fileName.H:59
Writes the domain averaged reaction rates for each specie for each reaction into the file <timeDir>/s...
bool update()
Update the cached values as required.
Definition: volRegion.C:243
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual bool read(const dictionary &dict)
Read optional controls.
const scalar RR
Universal gas constant: default in [J/(kmol K)].
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool read(const dictionary &dict)
Read the specieReactionRates data.
functionObjects::specieReactionRates< BasicChemistryModel< psiReactionThermo > > psiSpecieReactionRates
functionObjects::specieReactionRates< BasicChemistryModel< rhoReactionThermo > > rhoSpecieReactionRates
Base class for writing single files from the function objects.
Definition: writeFile.H:112
labelList cellIDs
defineTemplateTypeNameAndDebugWithName(psiReactionsSensitivityAnalysisFunctionObject, "psiReactionsSensitivityAnalysis", 0)
const fvMesh & mesh_
Reference to the fvMesh.
Namespace for OpenFOAM.