Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / thermophysical / IFCLookUpTableGen / IFCLookUpTableGen.C
blob88231486d8beca10b015c23d8568ada7eecfef39
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Application
25     IFC (infinitely-fast chemistry) look-up table generator
27 Description
28     Calculate the the infinitely-fast chemistry relationships in function of ft.
29     for a given fuel.
30     The output is given in moles.
32     i.e. dictionary:
34     fileName "SpeciesTable";
37     fuel CH4(ANHARMONIC);
38     n    1;
39     m    4;
42     fields
43     (
44         {
45             name   ft;
46             min    0.;
47             max    1.;
48             N      100;
49         }
50     );
52     output
53     (
54         {
55             name    CH4;
56         }
57         {
58             name    CO2;
59         }
60         {
61             name    H2O;
62         }
65 \*---------------------------------------------------------------------------*/
67 #include "argList.H"
69 #include "IFstream.H"
70 #include "OFstream.H"
72 #include "specieThermo.H"
73 #include "janafThermo.H"
74 #include "perfectGas.H"
76 #include "IOdictionary.H"
78 #include "interpolationLookUpTable.H"
80 using namespace Foam;
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]);
94     enum varinput
95     {
96         fti,
97         CH4i,
98         CO2i,
99         H2Oi
100     };
102     // Construct control dictionary
103     IFstream controlFile(controlFileName);
105     // Check controlFile stream is OK
106     if (!controlFile.good())
107     {
108         FatalErrorIn(args.executable())
109             << "Cannot read file " << controlFileName
110             << exit(FatalError);
111     }
113     dictionary control(controlFile);
115     //  fuel-air mix
116     fileName BurcatCpDataFileName(findEtcFile("thermoData/BurcatCpData"));
118     // Construct control dictionary
119     IFstream BurcatCpDataFile(BurcatCpDataFileName);
121     // Check BurcatCpData stream is OK
122     if (!BurcatCpDataFile.good())
123     {
124         FatalErrorIn(args.executable())
125         << "Cannot read file " << BurcatCpDataFileName
126         << exit(FatalError);
127     }
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);
137     scalar stoicCO2 = n;
138     scalar stoicH2O = m/2.0;
140     thermo fuel
141     (
142         "fuel",
143         thermo(CpData.lookup(fuelName))
144     );
146     thermo oxidant
147     (
148         "oxidant",
149         stoicO2*thermo(CpData.lookup("O2"))
150       + stoicN2*thermo(CpData.lookup("N2"))
151     );
153     dimensionedScalar stoicRatio
154     (
155         "stoichiometricAirFuelMassRatio",
156         dimless,
157         (oxidant.W()*oxidant.nMoles())/(fuel.W()*fuel.nMoles())
158     );
161     // Open File for Look Up Table
162     fileName LookUpTableFile(control.lookup("fileName"));
164     OFstream controlFileOutput(LookUpTableFile);
166     if (!controlFileOutput.good())
167     {
168         FatalErrorIn(args.executable())
169             << "Cannot open file " << LookUpTableFile
170             << exit(FatalError);
171     }
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();
182     label count = 0;
184     for (label i=0; i <= dim[fti]; i++)
185     {
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;
197         thermo fuel
198         (
199             "fuel",
200             fres*thermo(CpData.lookup(fuelName))
201         );
203         thermo N2
204         (
205             "N2",
206             n2*thermo(CpData.lookup("N2"))
207         );
209         thermo O2
210         (
211             "O2",
212             ores*thermo(CpData.lookup("O2"))
213         );
215         thermo CO2
216         (
217             "CO2",
218             fburnt*stoicCO2*thermo(CpData.lookup("CO2"))
219         );
221         thermo H2O
222         (
223             "H2O",
224             fburnt*stoicH2O*thermo(CpData.lookup("H2O"))
225         );
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;
235         count++;
236     }
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)
247     {
248         FatalErrorIn
249         (
250             "Foam::IFCLookUpTableGen"
251         )   << "table is empty" << nl
252             << exit(FatalError);
253     }
255     controlFileOutput.writeKeyword("values");
256     controlFileOutput << LookUpTable << token::END_STATEMENT << nl;
258     return(0);
262 // ************************************************************************* //