1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 IFC (infinitely-fast chemistry) look-up table generator
28 Calculate the the infinitely-fast chemistry relationships in function of ft.
30 The output is given in moles.
34 fileName "SpeciesTable";
65 \*---------------------------------------------------------------------------*/
72 #include "specieThermo.H"
73 #include "janafThermo.H"
74 #include "perfectGas.H"
76 #include "IOdictionary.H"
78 #include "interpolationLookUpTable.H"
82 typedef specieThermo<janafThermo<perfectGas> > thermo;
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 int main(int argc, char *argv[])
88 argList::validArgs.clear();
89 argList::validArgs.append("controlFile");
90 argList args(argc, argv);
92 fileName controlFileName(args.additionalArgs()[0]);
102 // Construct control dictionary
103 IFstream controlFile(controlFileName);
105 // Check controlFile stream is OK
106 if (!controlFile.good())
108 FatalErrorIn(args.executable())
109 << "Cannot read file " << controlFileName
113 dictionary control(controlFile);
116 fileName BurcatCpDataFileName(findEtcFile("thermoData/BurcatCpData"));
118 // Construct control dictionary
119 IFstream BurcatCpDataFile(BurcatCpDataFileName);
121 // Check BurcatCpData stream is OK
122 if (!BurcatCpDataFile.good())
124 FatalErrorIn(args.executable())
125 << "Cannot read file " << BurcatCpDataFileName
129 dictionary CpData(BurcatCpDataFile);
131 word fuelName(control.lookup("fuel"));
132 scalar n(readScalar(control.lookup("n")));
133 scalar m(readScalar(control.lookup("m")));
135 scalar stoicO2 = n + m/4.0;
136 scalar stoicN2 = (0.79/0.21)*(n + m/4.0);
138 scalar stoicH2O = m/2.0;
143 thermo(CpData.lookup(fuelName))
149 stoicO2*thermo(CpData.lookup("O2"))
150 + stoicN2*thermo(CpData.lookup("N2"))
153 dimensionedScalar stoicRatio
155 "stoichiometricAirFuelMassRatio",
157 (oxidant.W()*oxidant.nMoles())/(fuel.W()*fuel.nMoles())
161 // Open File for Look Up Table
162 fileName LookUpTableFile(control.lookup("fileName"));
164 OFstream controlFileOutput(LookUpTableFile);
166 if (!controlFileOutput.good())
168 FatalErrorIn(args.executable())
169 << "Cannot open file " << LookUpTableFile
173 // Create Look Up Table
174 interpolationLookUpTable<scalar> LookUpTable(control);
176 const List<label>& dim = LookUpTable.dim();
178 const List<scalar>& min = LookUpTable.min();
180 const List<scalar>& delta = LookUpTable.delta();
184 for (label i=0; i <= dim[fti]; i++)
186 scalar ft = Foam::min(scalar(i)*delta[fti] + min[fti] + 0.001, 0.999);
188 scalar equiv = Foam::pow(((1.0 / ft) - 1.0), -1.0)*stoicRatio.value();
190 scalar o2 = (1.0/equiv)*stoicO2;
191 scalar n2 = (0.79/0.21)*o2;
192 scalar fres = max(1.0 - 1.0/equiv, 0.0);
193 scalar ores = max(1.0/equiv - 1.0, 0.0);
194 scalar fburnt = 1.0 - fres;
200 fres*thermo(CpData.lookup(fuelName))
206 n2*thermo(CpData.lookup("N2"))
212 ores*thermo(CpData.lookup("O2"))
218 fburnt*stoicCO2*thermo(CpData.lookup("CO2"))
224 fburnt*stoicH2O*thermo(CpData.lookup("H2O"))
228 scalar ToTalMoles = fuel.nMoles() + CO2.nMoles() + H2O.nMoles() +
229 N2.nMoles() + O2.nMoles();
231 LookUpTable[fti][count] = ft;
232 LookUpTable[CH4i][count] = fuel.nMoles()/ToTalMoles;
233 LookUpTable[CO2i][count] = CO2.nMoles()/ToTalMoles;
234 LookUpTable[H2Oi][count] = H2O.nMoles()/ToTalMoles;
238 IOobject::writeBanner(controlFileOutput);
239 controlFileOutput << "\n" << nl;
240 controlFileOutput.writeKeyword("fields");
241 controlFileOutput << LookUpTable.entries() << token::END_STATEMENT << nl;
243 controlFileOutput.writeKeyword("output");
244 controlFileOutput << LookUpTable.output() << token::END_STATEMENT << nl;
246 if (LookUpTable.size() == 0)
250 "Foam::IFCLookUpTableGen"
251 ) << "table is empty" << nl
255 controlFileOutput.writeKeyword("values");
256 controlFileOutput << LookUpTable << token::END_STATEMENT << nl;
262 // ************************************************************************* //