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-2021 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 {
36  defineTypeNameAndDebug(specieReactionRates, 0);
37 
39  (
40  functionObject,
41  specieReactionRates,
42  dictionary
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().composition().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 ri=0; ri<nReaction; ri++)
131  {
132  if (Pstream::master())
133  {
134  writeTime(file());
135  file() << token::TAB << ri;
136  }
137 
138  for (label si=0; si<nSpecie; si++)
139  {
141  (
142  chemistryModel_.calculateRR(ri, si)
143  );
144 
145  scalar sumVRRi = 0;
146 
147  if (isNull(cellIDs()))
148  {
149  sumVRRi = fvc::domainIntegrate(RR).value();
150  }
151  else
152  {
153  sumVRRi = gSum
154  (
156  );
157  }
158 
159  if (Pstream::master())
160  {
161  file() << token::TAB << sumVRRi/V;
162  }
163  }
164 
165  if (Pstream::master())
166  {
167  file() << nl;
168  }
169  }
170 
171  if (Pstream::master())
172  {
173  file() << nl << endl;
174  }
175 
176  return true;
177 }
178 
179 
180 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:167
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
virtual bool write()
Write the specie reaction rates.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
dimensioned< Type > domainIntegrate(const GeometricField< Type, fvPatchField, volMesh > &vf)
const label nSpecie
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual bool read(const dictionary &)
Read the specieReactionRates data.
Macros for easy insertion into run-time selection tables.
const dimensionedScalar RR
Universal gas constant: default SI units: [J/kmol/K].
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:46
Type gSum(const FieldField< Field, Type > &f)
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Volume integrate volField creating a volField.
static const char nl
Definition: Ostream.H:260
Volume (cell) region selection class.
Definition: volRegion.H:102
defineTypeNameAndDebug(Qdot, 0)
void writeFileHeader(const writeFile &wf, Ostream &file)
Output file header information.
Definition: volRegion.C:58
List< word > wordList
A List of words.
Definition: fileName.H:54
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
specieReactionRates(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
const fvMesh & mesh_
Reference to the fvMesh.
Namespace for OpenFOAM.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57