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-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 "reactionRates.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::reactionRates::writeFileHeader(const label i)
54 {
55  const label nReaction = chemistryModel_.nReaction();
56 
57  writeHeader(file(), "Reaction rates");
58 
59  zone_.writeFileHeader(*this, file());
60 
61  writeHeaderValue(file(), "nReaction", nReaction);
62  writeCommented(file(), "Time");
63 
64  for (label reactioni = 0; reactioni < nReaction; ++ reactioni)
65  {
66  writeTabbed(file(), chemistryModel_.reactionName(reactioni));
67  }
68 
69  file() << endl;
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
76 (
77  const word& name,
78  const Time& runTime,
79  const dictionary& dict
80 )
81 :
82  fvMeshFunctionObject(name, runTime, dict),
83  logFiles(obr_, name),
84  zone_(fvMeshFunctionObject::mesh_, dict),
85  phaseName_(dict.lookupOrDefault<word>("phase", word::null)),
86  chemistryModel_
87  (
88  fvMeshFunctionObject::mesh_.lookupObject<basicChemistryModel>
89  (
90  IOobject::groupName("chemistryProperties", phaseName_)
91  )
92  ),
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  logFiles::write();
128 
129  const label nReaction = chemistryModel_.nReaction();
130 
131  if (Pstream::master())
132  {
133  writeTime(file());
134  }
135 
136  for (label reactioni = 0; reactioni < nReaction; reactioni ++)
137  {
139  (
140  chemistryModel_.reactionRR(reactioni)
141  );
142 
143  // Compute the average rate and write it into the log file
144  const scalar sumVRR =
145  zone_.all()
146  ? fvc::domainIntegrate(RR).value()
147  : gSum
148  (
150  (
152  zone_.zone()
153  )
154  );
155 
156  if (Pstream::master())
157  {
158  file() << token::TAB << sumVRR/zone_.V();
159  }
160 
161  // Write the rate field, if necessary
162  if (writeFields_)
163  {
164  RR.write();
165  }
166  }
167 
168  if (Pstream::master())
169  {
170  file() << endl;
171  }
172 
173  return true;
174 }
175 
176 
178 (
179  const polyMesh& mesh
180 )
181 {
182  if (&mesh == &this->mesh())
183  {
184  zone_.movePoints();
185  }
186 }
187 
188 
190 (
191  const polyTopoChangeMap& map
192 )
193 {
194  if (&map.mesh() == &mesh())
195  {
196  zone_.topoChange(map);
197  }
198 }
199 
200 
202 (
203  const polyMeshMap& map
204 )
205 {
206  if (&map.mesh() == &mesh())
207  {
208  zone_.mapMesh(map);
209  }
210 }
211 
212 
214 (
215  const polyDistributionMap& map
216 )
217 {
218  if (&map.mesh() == &mesh())
219  {
220  zone_.distribute(map);
221  }
222 }
223 
224 
225 // ************************************************************************* //
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...
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
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.
virtual const word & reactionName(const label reactioni) const =0
Return the name of reactioni.
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 [kmol/m^3/s] for each reaction into the file <timeDir>/react...
Definition: reactionRates.H:79
reactionRates(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: reactionRates.C:76
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
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.
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.
dictionary dict