specieReactionRates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "specieReactionRates.H"
30 #include "volFields.H"
31 #include "fvcVolumeIntegrate.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class ChemistryModelType>
38 (
39  Ostream& os
40 ) const
41 {
42  writeHeader(os, "Specie reaction rates");
43  volRegion::writeFileHeader(*this, os);
44  writeHeaderValue(os, "nSpecie", chemistryModel_.nSpecie());
45  writeHeaderValue(os, "nReaction", chemistryModel_.nReaction());
46 
47  writeCommented(os, "Time");
48  writeTabbed(os, "Reaction");
49 
50  const wordList& speciesNames =
51  chemistryModel_.thermo().composition().species();
52 
53  for (const word& speciesName : speciesNames)
54  {
55  writeTabbed(os, speciesName);
56  }
57 
58  os << endl;
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 template<class ChemistryModelType>
67 (
68  const word& name,
69  const Time& runTime,
70  const dictionary& dict
71 )
72 :
74  volRegion(fvMeshFunctionObject::mesh_, dict),
75  writeFile(obr_, name, typeName, dict),
76  chemistryModel_
77  (
78  fvMeshFunctionObject::mesh_.lookupObject<ChemistryModelType>
79  (
80  "chemistryProperties"
81  )
82  )
83 {
84  writeFileHeader(file());
85 }
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
90 template<class ChemistryModelType>
92 (
93  const dictionary& dict
94 )
95 {
97 
98  return true;
99 }
100 
101 
102 template<class ChemistryModelType>
104 {
105  return true;
106 }
107 
108 
109 template<class ChemistryModelType>
111 {
112  const label nSpecie = chemistryModel_.nSpecie();
113  const label nReaction = chemistryModel_.nReaction();
114 
115  volRegion::update(); // Ensure cached values are valid
116 
117  const scalar volTotal = this->volRegion::V();
118 
119  const bool useAll = this->volRegion::useAllCells();
120 
121  for (label ri=0; ri<nReaction; ri++)
122  {
123  writeCurrentTime(file());
124  file() << token::TAB << ri;
125 
126  for (label si=0; si<nSpecie; si++)
127  {
129  (
130  chemistryModel_.calculateRR(ri, si)
131  );
132 
133  scalar sumVRRi = 0;
134 
135  if (useAll)
136  {
137  sumVRRi = fvc::domainIntegrate(RR).value();
138  }
139  else
140  {
141  sumVRRi = gSum
142  (
143  scalarField(fvMeshFunctionObject::mesh_.V()*RR, cellIDs())
144  );
145  }
146 
147  file() << token::TAB << sumVRRi / volTotal;
148  }
149 
150  file() << nl;
151  }
152 
153  file() << nl << endl;
154 
155  return true;
156 }
157 
158 
159 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
160 
162 #include "BasicChemistryModel.H"
163 #include "psiReactionThermo.H"
164 #include "rhoReactionThermo.H"
165 
166 namespace Foam
167 {
168  typedef
170  <
172  <
174  >
175  >
177 
179  (
181  "psiSpecieReactionRates",
182  0
183  );
184 
186  (
189  dictionary
190  );
191 
192 
193  typedef
195  <
197  <
199  >
200  >
202 
204  (
206  "rhoSpecieReactionRates",
207  0
208  );
209 
211  (
214  dictionary
215  );
216 }
217 
218 
219 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::constant::thermodynamic::RR
const scalar RR
Universal gas constant: default in [J/(kmol K)].
Definition: thermodynamicConstants.C:46
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
specieReactionRates.H
update
mesh update()
Foam::functionObjects::volRegion
Volume (cell) region selection class.
Definition: volRegion.H:115
Foam::fvc::domainIntegrate
dimensioned< Type > domainIntegrate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: fvcVolumeIntegrate.C:88
Foam::functionObjects::specieReactionRates
Writes the domain averaged reaction rates for each specie for each reaction into the file <timeDir>/s...
Definition: specieReactionRates.H:65
BasicChemistryModel.H
nSpecie
label nSpecie
Definition: readInitialConditions.H:17
Foam::rhoReactionThermo
Foam::rhoReactionThermo.
Definition: rhoReactionThermo.H:60
Foam::BasicChemistryModel
Basic chemistry model templated on thermodynamics.
Definition: BasicChemistryModel.H:57
Foam::functionObjects::specieReactionRates::execute
virtual bool execute()
Do nothing.
Definition: specieReactionRates.C:103
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::writeHeader
static void writeHeader(Ostream &os, const word &fieldName)
Definition: rawSurfaceWriterImpl.C:66
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObject
Abstract base-class for Time/database function objects.
Definition: functionObject.H:332
Foam::psiReactionThermo
Foam::psiReactionThermo.
Definition: psiReactionThermo.H:60
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::functionObjects::specieReactionRates::write
virtual bool write()
Write the specie reaction rates.
Definition: specieReactionRates.C:110
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
rhoReactionThermo.H
Foam::psiSpecieReactionRates
functionObjects::specieReactionRates< BasicChemistryModel< psiReactionThermo > > psiSpecieReactionRates
Definition: specieReactionRates.C:176
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::rhoSpecieReactionRates
functionObjects::specieReactionRates< BasicChemistryModel< rhoReactionThermo > > rhoSpecieReactionRates
Definition: specieReactionRates.C:201
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
psiReactionThermo.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
fvcVolumeIntegrate.H
Volume integrate volField creating a volField.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::functionObjects::specieReactionRates::read
virtual bool read(const dictionary &dict)
Read the specieReactionRates data.
Definition: specieReactionRates.C:92
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::defineTemplateTypeNameAndDebugWithName
defineTemplateTypeNameAndDebugWithName(psiReactionsSensitivityAnalysisFunctionObject, "psiReactionsSensitivityAnalysis", 0)