adiabaticFlameT.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 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 Application
28  adiabaticFlameT
29 
30 Group
31  grpThermophysicalUtilities
32 
33 Description
34  Calculate adiabatic flame temperature for a given fuel over a
35  range of unburnt temperatures and equivalence ratios.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "argList.H"
40 #include "Time.H"
41 #include "dictionary.H"
42 #include "IFstream.H"
43 #include "OSspecific.H"
44 #include "etcFiles.H"
45 
46 #include "specie.H"
47 #include "perfectGas.H"
48 #include "thermo.H"
49 #include "janafThermo.H"
50 #include "absoluteEnthalpy.H"
51 
52 using namespace Foam;
53 
55  thermo;
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 int main(int argc, char *argv[])
60 {
62  (
63  "Calculate the adiabatic flame temperature for a given fuel over a "
64  " range of unburnt temperatures and equivalence ratios."
65  );
66 
68  argList::noFunctionObjects(); // Never use function objects
69 
70  argList::addArgument("controlFile");
71 
72  argList args(argc, argv);
73 
74  const auto controlFileName = args.get<fileName>(1);
75 
76  // Construct control dictionary
77  IFstream controlFile(controlFileName);
78 
79  // Check controlFile stream is OK
80  if (!controlFile.good())
81  {
83  << "Cannot read file " << controlFileName
84  << exit(FatalError);
85  }
86 
87  dictionary control(controlFile);
88 
89 
90  const scalar P(control.get<scalar>("P"));
91  const scalar T0(control.get<scalar>("T0"));
92  const word fuelName(control.get<word>("fuel"));
93  const scalar n(control.get<scalar>("n"));
94  const scalar m(control.get<scalar>("m"));
95 
96  Info<< nl << "Reading thermodynamic data dictionary" << endl;
97 
98  fileName thermoDataFileName(findEtcFile("thermoData/thermoData"));
99 
100  // Construct control dictionary
101  IFstream thermoDataFile(thermoDataFileName);
102 
103  // Check thermoData stream is OK
104  if (!thermoDataFile.good())
105  {
107  << "Cannot read file " << thermoDataFileName
108  << exit(FatalError);
109  }
110 
111  dictionary thermoData(thermoDataFile);
112 
113 
114  scalar stoicO2 = n + m/4.0;
115  scalar stoicN2 = (0.79/0.21)*stoicO2;
116  scalar stoicCO2 = n;
117  scalar stoicH2O = m/2.0;
118 
119  thermo FUEL
120  (
121  "fuel",
122  thermo(thermoData.subDict(fuelName))
123  );
124  Info<< "fuel " << FUEL << ';' << endl;
125  FUEL *= FUEL.W();
126 
127  thermo O2
128  (
129  "O2",
130  thermo(thermoData.subDict("O2"))
131  );
132  O2 *= O2.W();
133 
134  thermo N2
135  (
136  "N2",
137  thermo(thermoData.subDict("N2"))
138  );
139  N2 *= N2.W();
140 
141  thermo CO2
142  (
143  "CO2",
144  thermo(thermoData.subDict("CO2"))
145  );
146  CO2 *= CO2.W();
147 
148  thermo H2O
149  (
150  "H2O",
151  thermo(thermoData.subDict("H2O"))
152  );
153  H2O *= H2O.W();
154 
155  thermo oxidant
156  (
157  "oxidant",
158  stoicO2*O2
159  + stoicN2*N2
160  );
161  Info<< "oxidant " << (1/oxidant.Y())*oxidant << ';' << endl;
162 
163  dimensionedScalar stoichiometricAirFuelMassRatio
164  (
165  "stoichiometricAirFuelMassRatio",
166  dimless,
167  oxidant.Y()/FUEL.W()
168  );
169 
170  Info<< "stoichiometricAirFuelMassRatio "
171  << stoichiometricAirFuelMassRatio << ';' << endl;
172 
173  for (int i=0; i<300; i++)
174  {
175  scalar equiv = (i + 1)*0.01;
176  scalar ft = 1/(1 + stoichiometricAirFuelMassRatio.value()/equiv);
177 
178  Info<< "phi = " << equiv << nl
179  << "ft = " << ft << endl;
180 
181  scalar o2 = (1.0/equiv)*stoicO2;
182  scalar n2 = (0.79/0.21)*o2;
183  scalar fres = max(1.0 - 1.0/equiv, 0.0);
184  scalar ores = max(1.0/equiv - 1.0, 0.0);
185  scalar fburnt = 1.0 - fres;
186 
187  thermo reactants
188  (
189  "reactants",
190  FUEL + (1.0/equiv)*oxidant
191  );
192  Info<< "reactants " << (1/reactants.Y())*reactants << ';' << endl;
193 
194  thermo burntProducts
195  (
196  "burntProducts",
197  + (n2 - (0.79/0.21)*ores*stoicO2)*N2
198  + fburnt*stoicCO2*CO2
199  + fburnt*stoicH2O*H2O
200  );
201  Info<< "burntProducts "
202  << (1/burntProducts.Y())*burntProducts << ';' << endl;
203 
204  thermo products
205  (
206  "products",
207  fres*FUEL
208  + n2*N2
209  + fburnt*stoicCO2*CO2
210  + fburnt*stoicH2O*H2O
211  + ores*stoicO2*O2
212  );
213 
214  Info<< "products " << (1/products.Y())*products << ';' << endl;
215 
216  scalar Tad = products.THa(reactants.Ha(P, T0), P, 1000.0);
217  Info<< "Tad = " << Tad << nl << endl;
218  }
219 
220  Info<< nl << "End" << endl;
221 
222  return 0;
223 }
224 
225 
226 // ************************************************************************* //
static void noFunctionObjects(bool addWithOption=false)
Remove &#39;-noFunctionObjects&#39; option and ignore any occurrences.
Definition: argList.C:514
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:453
A class for handling file names.
Definition: fileName.H:71
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
water
Definition: H2O.H:55
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static void noParallel()
Remove the parallel options.
Definition: argList.C:551
Thermodynamics mapping class to expose the absolute enthalpy functions.
const dimensionSet dimless
Dimensionless.
psiReactionThermo & thermo
Definition: createFields.H:28
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling words, derived from Foam::string.
Definition: word.H:63
Functions to search &#39;etc&#39; directories for configuration files etc.
scalar W() const
Molecular weight [kg/kmol].
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Liquid N2.
Definition: N2.H:56
Input from file stream, using an ISstream.
Definition: IFstream.H:49
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
fileName findEtcFile(const fileName &name, const bool mandatory=false, unsigned short location=0777)
Search for a single FILE within the etc directories.
Definition: etcFiles.C:439
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:342
messageStream Info
Information stream (stdout output on master, null elsewhere)
label n
Foam::argList args(argc, argv)
Namespace for OpenFOAM.
scalar T0
Definition: createFields.H:22