reactionRates.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) 2024-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 "reactionRates.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::reactionRates::writeFileHeader(const label i)
55 {
56  const chemistryModel& chemistry =
57  mesh().lookupObject<chemistryModel>
58  (
59  IOobject::groupName("chemistryProperties", phaseName_)
60  );
61 
62  const label nReaction = chemistry.nReaction();
63 
64  writeHeader(file(), "Reaction rates");
65 
66  zone_.writeFileHeader(*this, file());
67 
68  writeHeaderValue(file(), "nReaction", nReaction);
69  writeCommented(file(), "Time");
70 
71  for (label reactioni = 0; reactioni < nReaction; ++ reactioni)
72  {
73  writeTabbed(file(), chemistry.reactionName(reactioni));
74  }
75 
76  file() << endl;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 (
84  const word& name,
85  const Time& runTime,
86  const dictionary& dict
87 )
88 :
89  fvMeshFunctionObject(name, runTime, dict),
90  logFiles(obr_, name),
91  zone_(fvMeshFunctionObject::mesh_, dict),
92  phaseName_(dict.lookupOrDefault<word>("phase", word::null)),
93  writeFields_(false)
94 {
95  read(dict);
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
100 
102 {}
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
108 {
110 
111  writeFields_ = dict.lookupOrDefault<bool>("writeFields", false);
112 
113  resetName("reactionRates");
114 
115  return true;
116 }
117 
118 
120 {
121  return true;
122 }
123 
124 
126 {
127  zone_.regenerate();
128 
129  logFiles::write();
130 
131  const chemistryModel& chemistry =
133  (
134  IOobject::groupName("chemistryProperties", phaseName_)
135  );
136 
137  const label nReaction = chemistry.nReaction();
138 
139  if (Pstream::master())
140  {
141  writeTime(file());
142  }
143 
144  for (label reactioni = 0; reactioni < nReaction; reactioni ++)
145  {
147  (
148  chemistry.reactionRR(reactioni)
149  );
150 
151  // Compute the average rate and write it into the log file
152  const scalar sumVRR =
153  zone_.all()
154  ? fvc::domainIntegrate(RR).value()
155  : gSum
156  (
158  (
160  zone_.zone()
161  )
162  );
163 
164  if (Pstream::master())
165  {
166  file() << token::TAB << sumVRR/zone_.V();
167  }
168 
169  // Write the rate field, if necessary
170  if (writeFields_)
171  {
172  RR.write();
173  }
174  }
175 
176  if (Pstream::master())
177  {
178  file() << endl;
179  }
180 
181  return true;
182 }
183 
184 
186 (
187  const polyMesh& mesh
188 )
189 {
190  if (&mesh == &this->mesh())
191  {
192  zone_.movePoints();
193  }
194 }
195 
196 
198 (
199  const polyTopoChangeMap& map
200 )
201 {
202  if (&map.mesh() == &mesh())
203  {
204  zone_.topoChange(map);
205  }
206 }
207 
208 
210 (
211  const polyMeshMap& map
212 )
213 {
214  if (&map.mesh() == &mesh())
215  {
216  zone_.mapMesh(map);
217  }
218 }
219 
220 
222 (
223  const polyDistributionMap& map
224 )
225 {
226  if (&map.mesh() == &mesh())
227  {
228  zone_.distribute(map);
229  }
230 }
231 
232 
233 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static word groupName(Name name, const word &group)
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 [kmol/m^3/s] for each reaction into the file <timeDir>/react...
Definition: reactionRates.H:78
reactionRates(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: reactionRates.C:83
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 execute()
Do nothing.
virtual bool write()
Write the reaction rates.
virtual bool read(const dictionary &)
Read the reactionRates 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.
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.
dictionary dict
chemistryModel & chemistry