specieReactionRates.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) 2016-2025 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 "specieReactionRates.H"
27 #include "fvcVolumeIntegrate.H"
28 #include "polyTopoChangeMap.H"
29 #include "polyMeshMap.H"
30 #include "polyDistributionMap.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
40 
42  (
46  );
47 }
48 }
49 
50 
51 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 
53 void Foam::functionObjects::specieReactionRates::writeFileHeader(const label i)
54 {
55  writeHeader(file(), "Specie reaction rates");
56 
57  zone_.writeFileHeader(*this, file());
58 
59  writeHeaderValue(file(), "nSpecie", chemistryModel_.nSpecie());
60  writeHeaderValue(file(), "nReaction", chemistryModel_.nReaction());
61 
62  writeCommented(file(), "Time");
63  writeTabbed(file(), "Reaction");
64 
65  const wordList& speciesNames =
66  chemistryModel_.thermo().species();
67 
68  forAll (speciesNames, si)
69  {
70  writeTabbed(file(), speciesNames[si]);
71  }
72 
73  file() << endl;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
80 (
81  const word& name,
82  const Time& runTime,
83  const dictionary& dict
84 )
85 :
86  fvMeshFunctionObject(name, runTime, dict),
87  logFiles(obr_, name),
88  zone_(fvMeshFunctionObject::mesh_, dict),
89  phaseName_(dict.lookupOrDefault<word>("phase", word::null)),
90  chemistryModel_
91  (
92  fvMeshFunctionObject::mesh_.lookupObject<basicChemistryModel>
93  (
94  IOobject::groupName("chemistryProperties", phaseName_)
95  )
96  ),
97  writeFields_(false)
98 {
99  read(dict);
100 }
101 
102 
103 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
104 
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 {
114 
115  writeFields_ = dict.lookupOrDefault<bool>("writeFields", false);
116 
117  resetName("specieReactionRates");
118 
119  return true;
120 }
121 
122 
124 {
125  return true;
126 }
127 
128 
130 {
131  logFiles::write();
132 
133  const label nSpecie = chemistryModel_.nSpecie();
134  const label nReaction = chemistryModel_.nReaction();
135 
136  // Region volume
137  const scalar V = zone_.V();
138 
139  for (label reactioni=0; reactioni<nReaction; reactioni++)
140  {
141  if (Pstream::master())
142  {
143  writeTime(file());
144  file() << token::TAB << reactioni;
145  }
146 
148  (
149  chemistryModel_.specieReactionRR(reactioni)
150  );
151 
152  // Compute the average rates and write them into the log file
153  for (label speciei=0; speciei<nSpecie; speciei++)
154  {
155  scalar sumVRRi = 0;
156 
157  if (zone_.all())
158  {
159  sumVRRi = fvc::domainIntegrate(RR[speciei]).value();
160  }
161  else
162  {
163  sumVRRi =
164  gSum
165  (
167  (
168  fvMeshFunctionObject::mesh_.V()*RR[speciei],
169  zone_.zone()
170  )
171  );
172  }
173 
174  if (Pstream::master())
175  {
176  file() << token::TAB << sumVRRi/V;
177  }
178  }
179 
180  if (Pstream::master())
181  {
182  file() << nl;
183  }
184 
185  // Write the rate fields, if necessary
186  if (writeFields_)
187  {
188  for (label speciei=0; speciei<nSpecie; speciei++)
189  {
190  RR[speciei].write();
191  }
192  }
193  }
194 
195  if (Pstream::master())
196  {
197  file() << endl;
198  }
199 
200  return true;
201 }
202 
203 
205 (
206  const polyMesh& mesh
207 )
208 {
209  if (&mesh == &this->mesh())
210  {
211  zone_.movePoints();
212  }
213 }
214 
215 
217 (
218  const polyTopoChangeMap& map
219 )
220 {
221  if (&map.mesh() == &mesh())
222  {
223  zone_.topoChange(map);
224  }
225 }
226 
227 
229 (
230  const polyMeshMap& map
231 )
232 {
233  if (&map.mesh() == &mesh())
234  {
235  zone_.mapMesh(map);
236  }
237 }
238 
239 
241 (
242  const polyDistributionMap& map
243 )
244 {
245  if (&map.mesh() == &mesh())
246  {
247  zone_.distribute(map);
248  }
249 }
250 
251 
252 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Base class for chemistry models.
const fluidMulticomponentThermo & thermo() const
Return const access to the thermo.
virtual label nSpecie() const =0
The number of species.
virtual label nReaction() const =0
The number of reactions.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
OFstream & file()
Return access to the file (if only 1)
Definition: logFiles.C:113
virtual bool write()
Write function.
Definition: logFiles.C:173
virtual bool read(const dictionary &)
Read optional controls.
Writes volume averaged reaction rates in [kg/m^3/s] for each specie and each reaction into the file <...
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void movePoints(const polyMesh &)
Update for mesh motion.
virtual bool write()
Write the specie reaction rates.
specieReactionRates(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool read(const dictionary &)
Read the specieReactionRates data.
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:121
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:131
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
void writeFileHeader(const functionObjects::writeFile &wf, Ostream &file)
Output file header information.
Definition: fvCellZone.C:78
virtual const speciesTable & species() const =0
The table of species.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const polyMesh & mesh() const
Return polyMesh.
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
const polyMesh & mesh() const
Return polyMesh.
Definition: polyMeshMap.H:75
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const polyMesh & mesh() const
Return polyMesh.
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
Volume integrate volField creating a volField.
const dimensionedScalar RR
Universal gas constant: default SI units: [J/kmol/K].
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
dimensioned< Type > domainIntegrate(const VolField< Type > &vf)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
Type gSum(const FieldField< Field, Type > &f)
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const char nl
Definition: Ostream.H:267
const label nSpecie
dictionary dict