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-2023 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
37 
39  (
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::functionObjects::specieReactionRates::writeFileHeader(const label i)
51 {
52  writeHeader(file(), "Specie reaction rates");
54  writeHeaderValue(file(), "nSpecie", chemistryModel_.nSpecie());
55  writeHeaderValue(file(), "nReaction", chemistryModel_.nReaction());
56 
57  writeCommented(file(), "Time");
58  writeTabbed(file(), "Reaction");
59 
60  const wordList& speciesNames =
61  chemistryModel_.thermo().species();
62 
63  forAll (speciesNames, si)
64  {
65  writeTabbed(file(), speciesNames[si]);
66  }
67 
68  file() << endl;
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
75 (
76  const word& name,
77  const Time& runTime,
78  const dictionary& dict
79 )
80 :
81  fvMeshFunctionObject(name, runTime, dict),
83  logFiles(obr_, name),
84  chemistryModel_
85  (
86  fvMeshFunctionObject::mesh_.lookupObject<basicChemistryModel>
87  (
88  "chemistryProperties"
89  )
90  )
91 {
92  read(dict);
93 }
94 
95 
96 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97 
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 {
107 
108  resetName("specieReactionRates");
109 
110  return true;
111 }
112 
113 
115 {
116  return true;
117 }
118 
119 
121 {
122  logFiles::write();
123 
124  const label nSpecie = chemistryModel_.nSpecie();
125  const label nReaction = chemistryModel_.nReaction();
126 
127  // Region volume
128  const scalar V = this->V();
129 
130  for (label reactioni=0; reactioni<nReaction; reactioni++)
131  {
132  if (Pstream::master())
133  {
134  writeTime(file());
135  file() << token::TAB << reactioni;
136  }
137 
139  (
140  chemistryModel_.reactionRR(reactioni)
141  );
142 
143  for (label speciei=0; speciei<nSpecie; speciei++)
144  {
145  scalar sumVRRi = 0;
146 
147  if (all())
148  {
149  sumVRRi = fvc::domainIntegrate(RR[speciei]).value();
150  }
151  else
152  {
153  sumVRRi =
154  gSum
155  (
157  (
158  fvMeshFunctionObject::mesh_.V()*RR[speciei],
159  cells()
160  )
161  );
162  }
163 
164  if (Pstream::master())
165  {
166  file() << token::TAB << sumVRRi/V;
167  }
168  }
169 
170  if (Pstream::master())
171  {
172  file() << nl;
173  }
174  }
175 
176  if (Pstream::master())
177  {
178  file() << nl << endl;
179  }
180 
181  return true;
182 }
183 
184 
185 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
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 keyword definitions, which are a keyword followed by any number of values (e....
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 the domain averaged reaction rates for each specie for each reaction into the file <timeDir>/s...
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
General run-time selected cell set selection class for fvMesh.
Definition: fvCellSet.H:88
void writeFileHeader(const functionObjects::writeFile &wf, Ostream &file)
Output file header information.
Definition: fvCellSet.C:55
virtual const speciesTable & species() const =0
The table of species.
A class for handling words, derived from string.
Definition: word.H:62
Volume integrate volField creating a volField.
const cellShapeList & cells
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const char nl
Definition: Ostream.H:266
const label nSpecie
dictionary dict