FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

IFCLookUpTableGen.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     IFC (infinitely-fast chemistry) look-up table generator
00026 
00027 Description
00028     Calculate the the infinitely-fast chemistry relationships in function of ft.
00029     for a given fuel.
00030 
00031     The output is given in moles. i.e. dictionary:
00032 
00033     @verbatim
00034     fileName "SpeciesTable";
00035 
00036 
00037     fuel CH4(ANHARMONIC);
00038     n    1;
00039     m    4;
00040 
00041 
00042     fields
00043     (
00044         {
00045             name   ft;
00046             min    0.;
00047             max    1.;
00048             N      100;
00049         }
00050     );
00051 
00052     output
00053     (
00054         {
00055             name    CH4;
00056         }
00057         {
00058             name    CO2;
00059         }
00060         {
00061             name    H2O;
00062         }
00063     );
00064     @endverbatim
00065 
00066 Usage
00067     - IFCLookUpTableGen <controlFile> [OPTION]
00068 
00069     @param <controlFile>
00070     Control-dictionary file for the lookup table generation
00071 
00072     @param -parallel \n
00073     Run the case in parallel
00074 
00075     @param -help \n
00076     Display short usage message
00077 
00078     @param -doc \n
00079     Display Doxygen documentation page
00080 
00081     @param -srcDoc \n
00082     Display source code
00083 
00084 \*---------------------------------------------------------------------------*/
00085 
00086 #include <OpenFOAM/argList.H>
00087 
00088 #include <OpenFOAM/IFstream.H>
00089 #include <OpenFOAM/OFstream.H>
00090 
00091 #include <specie/specieThermo.H>
00092 #include <specie/janafThermo.H>
00093 #include <specie/perfectGas.H>
00094 
00095 #include <OpenFOAM/IOdictionary.H>
00096 
00097 #include <radiation/interpolationLookUpTable.H>
00098 
00099 using namespace Foam;
00100 
00101 typedef specieThermo<janafThermo<perfectGas> > thermo;
00102 
00103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00104 
00105 int main(int argc, char *argv[])
00106 {
00107     argList::validArgs.clear();
00108     argList::validArgs.append("controlFile");
00109     argList args(argc, argv);
00110 
00111     fileName controlFileName(args.additionalArgs()[0]);
00112 
00113     enum varinput
00114     {
00115         fti,
00116         CH4i,
00117         CO2i,
00118         H2Oi
00119     };
00120 
00121     // Construct control dictionary
00122     IFstream controlFile(controlFileName);
00123 
00124     // Check controlFile stream is OK
00125     if (!controlFile.good())
00126     {
00127         FatalErrorIn(args.executable())
00128             << "Cannot read file " << controlFileName
00129             << exit(FatalError);
00130     }
00131 
00132     dictionary control(controlFile);
00133 
00134     //  fuel-air mix
00135     fileName BurcatCpDataFileName(findEtcFile("thermoData/BurcatCpData"));
00136 
00137     // Construct control dictionary
00138     IFstream BurcatCpDataFile(BurcatCpDataFileName);
00139 
00140     // Check BurcatCpData stream is OK
00141     if (!BurcatCpDataFile.good())
00142     {
00143         FatalErrorIn(args.executable())
00144         << "Cannot read file " << BurcatCpDataFileName
00145         << exit(FatalError);
00146     }
00147 
00148     dictionary CpData(BurcatCpDataFile);
00149 
00150     word fuelName(control.lookup("fuel"));
00151     scalar n(readScalar(control.lookup("n")));
00152     scalar m(readScalar(control.lookup("m")));
00153 
00154     scalar stoicO2 = n + m/4.0;
00155     scalar stoicN2 = (0.79/0.21)*(n + m/4.0);
00156     scalar stoicCO2 = n;
00157     scalar stoicH2O = m/2.0;
00158 
00159     thermo fuel
00160     (
00161         "fuel",
00162         thermo(CpData.lookup(fuelName))
00163     );
00164 
00165     thermo oxidant
00166     (
00167         "oxidant",
00168         stoicO2*thermo(CpData.lookup("O2"))
00169       + stoicN2*thermo(CpData.lookup("N2"))
00170     );
00171 
00172     dimensionedScalar stoicRatio
00173     (
00174         "stoichiometricAirFuelMassRatio",
00175         dimless,
00176         (oxidant.W()*oxidant.nMoles())/(fuel.W()*fuel.nMoles())
00177     );
00178 
00179 
00180     // Open File for Look Up Table
00181     fileName LookUpTableFile(control.lookup("fileName"));
00182 
00183     OFstream controlFileOutput(LookUpTableFile);
00184 
00185     if (!controlFileOutput.good())
00186     {
00187         FatalErrorIn(args.executable())
00188             << "Cannot open file " << LookUpTableFile
00189             << exit(FatalError);
00190     }
00191 
00192     // Create Look Up Table
00193     interpolationLookUpTable<scalar> LookUpTable(control);
00194 
00195     const List<label>& dim = LookUpTable.dim();
00196 
00197     const List<scalar>& min = LookUpTable.min();
00198 
00199     const List<scalar>& delta = LookUpTable.delta();
00200 
00201     label count = 0;
00202 
00203     for (label i=0; i <= dim[fti]; i++)
00204     {
00205         scalar ft = Foam::min(scalar(i)*delta[fti] + min[fti] + 0.001, 0.999);
00206 
00207         scalar equiv = Foam::pow(((1.0 / ft) - 1.0), -1.0)*stoicRatio.value();
00208 
00209         scalar o2 = (1.0/equiv)*stoicO2;
00210         scalar n2 = (0.79/0.21)*o2;
00211         scalar fres = max(1.0 - 1.0/equiv, 0.0);
00212         scalar ores = max(1.0/equiv - 1.0, 0.0);
00213         scalar fburnt = 1.0 - fres;
00214 
00215 
00216         thermo fuel
00217         (
00218             "fuel",
00219             fres*thermo(CpData.lookup(fuelName))
00220         );
00221 
00222         thermo N2
00223         (
00224             "N2",
00225             n2*thermo(CpData.lookup("N2"))
00226         );
00227 
00228         thermo O2
00229         (
00230             "O2",
00231             ores*thermo(CpData.lookup("O2"))
00232         );
00233 
00234         thermo CO2
00235         (
00236             "CO2",
00237             fburnt*stoicCO2*thermo(CpData.lookup("CO2"))
00238         );
00239 
00240         thermo H2O
00241         (
00242             "H2O",
00243             fburnt*stoicH2O*thermo(CpData.lookup("H2O"))
00244         );
00245 
00246 
00247         scalar ToTalMoles = fuel.nMoles() + CO2.nMoles() + H2O.nMoles() +
00248                 N2.nMoles() + O2.nMoles();
00249 
00250         LookUpTable[fti][count] = ft;
00251         LookUpTable[CH4i][count] = fuel.nMoles()/ToTalMoles;
00252         LookUpTable[CO2i][count] = CO2.nMoles()/ToTalMoles;
00253         LookUpTable[H2Oi][count] = H2O.nMoles()/ToTalMoles;
00254         count++;
00255     }
00256 
00257     IOobject::writeBanner(controlFileOutput);
00258     controlFileOutput << "\n" << nl;
00259     controlFileOutput.writeKeyword("fields");
00260     controlFileOutput << LookUpTable.entries() << token::END_STATEMENT << nl;
00261 
00262     controlFileOutput.writeKeyword("output");
00263     controlFileOutput << LookUpTable.output() << token::END_STATEMENT << nl;
00264 
00265     if (LookUpTable.size() == 0)
00266     {
00267         FatalErrorIn
00268         (
00269             "Foam::IFCLookUpTableGen"
00270         )   << "table is empty" << nl
00271             << exit(FatalError);
00272     }
00273 
00274     controlFileOutput.writeKeyword("values");
00275     controlFileOutput << LookUpTable << token::END_STATEMENT << nl;
00276 
00277     return(0);
00278 }
00279 
00280 
00281 // ************************************************************************* //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines