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 | Copyright (C) 2011-2016 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 Application
25  adiabaticFlameT
26 
27 Description
28  Calculates the adiabatic flame temperature for a given fuel over a
29  range of unburnt temperatures and equivalence ratios.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "Time.H"
35 #include "dictionary.H"
36 #include "IFstream.H"
37 #include "OSspecific.H"
38 #include "etcFiles.H"
39 
40 #include "specie.H"
41 #include "perfectGas.H"
42 #include "thermo.H"
43 #include "janafThermo.H"
44 #include "absoluteEnthalpy.H"
45 
46 using namespace Foam;
47 
49  thermo;
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 int main(int argc, char *argv[])
54 {
55  argList::validArgs.append("controlFile");
56  argList args(argc, argv);
57 
58  const fileName controlFileName = args[1];
59 
60  // Construct control dictionary
61  IFstream controlFile(controlFileName);
62 
63  // Check controlFile stream is OK
64  if (!controlFile.good())
65  {
67  << "Cannot read file " << controlFileName
68  << exit(FatalError);
69  }
70 
71  dictionary control(controlFile);
72 
73 
74  scalar P(readScalar(control.lookup("P")));
75  scalar T0(readScalar(control.lookup("T0")));
76  const word fuelName(control.lookup("fuel"));
77  scalar n(readScalar(control.lookup("n")));
78  scalar m(readScalar(control.lookup("m")));
79 
80 
81  Info<< nl << "Reading thermodynamic data dictionary" << endl;
82 
83  fileName thermoDataFileName(findEtcFile("thermoData/thermoData"));
84 
85  // Construct control dictionary
86  IFstream thermoDataFile(thermoDataFileName);
87 
88  // Check thermoData stream is OK
89  if (!thermoDataFile.good())
90  {
92  << "Cannot read file " << thermoDataFileName
93  << exit(FatalError);
94  }
95 
96  dictionary thermoData(thermoDataFile);
97 
98 
99  scalar stoicO2 = n + m/4.0;
100  scalar stoicN2 = (0.79/0.21)*(n + m/4.0);
101  scalar stoicCO2 = n;
102  scalar stoicH2O = m/2.0;
103 
104  thermo fuel
105  (
106  "fuel",
107  thermo(thermoData.subDict(fuelName))
108  );
109 
110  thermo oxidant
111  (
112  "oxidant",
113  stoicO2*thermo(thermoData.subDict("O2"))
114  + stoicN2*thermo(thermoData.subDict("N2"))
115  );
116 
117  dimensionedScalar stoichiometricAirFuelMassRatio
118  (
119  "stoichiometricAirFuelMassRatio",
120  dimless,
121  (oxidant.W()*oxidant.nMoles())/fuel.W()
122  );
123 
124  Info<< "stoichiometricAirFuelMassRatio "
125  << stoichiometricAirFuelMassRatio << ';' << endl;
126 
127  for (int i=0; i<300; i++)
128  {
129  scalar equiv = (i + 1)*0.01;
130  scalar ft = 1/(1 + stoichiometricAirFuelMassRatio.value()/equiv);
131 
132  Info<< "phi = " << equiv << nl
133  << "ft = " << ft << endl;
134 
135  scalar o2 = (1.0/equiv)*stoicO2;
136  scalar n2 = (0.79/0.21)*o2;
137  scalar fres = max(1.0 - 1.0/equiv, 0.0);
138  scalar ores = max(1.0/equiv - 1.0, 0.0);
139  scalar fburnt = 1.0 - fres;
140 
141  thermo fuel
142  (
143  "fuel",
144  thermo(thermoData.subDict(fuelName))
145  );
146  Info<< "fuel " << fuel << ';' << endl;
147 
148  thermo oxidant
149  (
150  "oxidant",
151  o2*thermo(thermoData.subDict("O2"))
152  + n2*thermo(thermoData.subDict("N2"))
153  );
154  Info<< "oxidant " << (1/oxidant.nMoles())*oxidant << ';' << endl;
155 
156  thermo reactants
157  (
158  "reactants",
159  fuel + oxidant
160  );
161  Info<< "reactants " << (1/reactants.nMoles())*reactants << ';' << endl;
162 
163  thermo burntProducts
164  (
165  "burntProducts",
166  + (n2 - (0.79/0.21)*ores*stoicO2)*thermo(thermoData.subDict("N2"))
167  + fburnt*stoicCO2*thermo(thermoData.subDict("CO2"))
168  + fburnt*stoicH2O*thermo(thermoData.subDict("H2O"))
169  );
170  Info<< "burntProducts "
171  << (1/burntProducts.nMoles())*burntProducts << ';' << endl;
172 
173  thermo products
174  (
175  "products",
176  fres*fuel
177  + n2*thermo(thermoData.subDict("N2"))
178  + fburnt*stoicCO2*thermo(thermoData.subDict("CO2"))
179  + fburnt*stoicH2O*thermo(thermoData.subDict("H2O"))
180  + ores*stoicO2*thermo(thermoData.subDict("O2"))
181  );
182 
183  Info<< "products " << (1/products.nMoles())*products << ';' << endl;
184 
185  scalar Tad = products.THa(reactants.Ha(P, T0), P, 1000.0);
186  Info<< "Tad = " << Tad << nl << endl;
187  }
188 
189  Info<< nl << "end" << endl;
190 
191  return 0;
192 }
193 
194 
195 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:69
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
Thermodynamics mapping class to expose the absolute enthalpy function as the standard enthalpy functi...
psiReactionThermo & thermo
Definition: createFields.H:31
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling words, derived from string.
Definition: word.H:59
Functions to search &#39;etc&#39; directories for configuration files etc.
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
fileName findEtcFile(const fileName &, bool mandatory=false)
Search for a file using findEtcFiles.
Definition: etcFiles.C:252
static const char nl
Definition: Ostream.H:262
Input from file stream.
Definition: IFstream.H:81
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
messageStream Info
label n
Foam::argList args(argc, argv)
Namespace for OpenFOAM.