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-2026 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 "chemistryModel.H"
28 #include "fvcVolumeIntegrate.H"
29 #include "polyTopoChangeMap.H"
30 #include "polyMeshMap.H"
31 #include "polyDistributionMap.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
41 
43  (
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
54 void Foam::functionObjects::specieReactionRates::writeFileHeader(const label i)
55 {
56  const chemistryModel& chemistry =
57  mesh().lookupObject<chemistryModel>
58  (
59  IOobject::groupName("chemistryProperties", phaseName_)
60  );
61 
62  writeHeader(file(), "Specie reaction rates");
63 
64  zone_.writeFileHeader(*this, file());
65 
66  writeHeaderValue(file(), "nSpecie", chemistry.nSpecie());
67  writeHeaderValue(file(), "nReaction", chemistry.nReaction());
68 
69  writeCommented(file(), "Time");
70  writeTabbed(file(), "Reaction");
71 
72  const wordList& speciesNames =
73  chemistry.thermo().species();
74 
75  forAll (speciesNames, si)
76  {
77  writeTabbed(file(), speciesNames[si]);
78  }
79 
80  file() << endl;
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 
87 (
88  const word& name,
89  const Time& runTime,
90  const dictionary& dict
91 )
92 :
93  fvMeshFunctionObject(name, runTime, dict),
94  logFiles(obr_, name),
95  zone_(fvMeshFunctionObject::mesh_, dict),
96  phaseName_(dict.lookupOrDefault<word>("phase", word::null)),
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  zone_.regenerate();
132 
133  logFiles::write();
134 
135  const chemistryModel& chemistry =
137  (
138  IOobject::groupName("chemistryProperties", phaseName_)
139  );
140 
141  const label nSpecie = chemistry.nSpecie();
142  const label nReaction = chemistry.nReaction();
143 
144  // Region volume
145  const scalar V = zone_.V();
146 
147  for (label reactioni=0; reactioni<nReaction; reactioni++)
148  {
149  if (Pstream::master())
150  {
151  writeTime(file());
152  file() << token::TAB << reactioni;
153  }
154 
156  (
157  chemistry.specieReactionRR(reactioni)
158  );
159 
160  // Compute the average rates and write them into the log file
161  for (label speciei=0; speciei<nSpecie; speciei++)
162  {
163  scalar sumVRRi = 0;
164 
165  if (zone_.all())
166  {
167  sumVRRi = fvc::domainIntegrate(RR[speciei]).value();
168  }
169  else
170  {
171  sumVRRi =
172  gSum
173  (
175  (
176  fvMeshFunctionObject::mesh_.V()*RR[speciei],
177  zone_.zone()
178  )
179  );
180  }
181 
182  if (Pstream::master())
183  {
184  file() << token::TAB << sumVRRi/V;
185  }
186  }
187 
188  if (Pstream::master())
189  {
190  file() << nl;
191  }
192 
193  // Write the rate fields, if necessary
194  if (writeFields_)
195  {
196  for (label speciei=0; speciei<nSpecie; speciei++)
197  {
198  RR[speciei].write();
199  }
200  }
201  }
202 
203  if (Pstream::master())
204  {
205  file() << endl;
206  }
207 
208  return true;
209 }
210 
211 
213 (
214  const polyMesh& mesh
215 )
216 {
217  if (&mesh == &this->mesh())
218  {
219  zone_.movePoints();
220  }
221 }
222 
223 
225 (
226  const polyTopoChangeMap& map
227 )
228 {
229  if (&map.mesh() == &mesh())
230  {
231  zone_.topoChange(map);
232  }
233 }
234 
235 
237 (
238  const polyMeshMap& map
239 )
240 {
241  if (&map.mesh() == &mesh())
242  {
243  zone_.mapMesh(map);
244  }
245 }
246 
247 
249 (
250  const polyDistributionMap& map
251 )
252 {
253  if (&map.mesh() == &mesh())
254  {
255  zone_.distribute(map);
256  }
257 }
258 
259 
260 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
static word groupName(Name name, const word &group)
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.
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.
const fvMesh & mesh() const
Return a reference to the mesh.
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
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
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:78
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:63
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(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
dimensioned< Type > domainIntegrate(const VolField< Type > &vf)
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
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:288
Type gSum(const UList< Type > &f, const label comm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const char nl
Definition: Ostream.H:297
dictionary dict
chemistryModel & chemistry
const label nSpecie