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

wideBandAbsorptionEmission.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) 2008-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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "wideBandAbsorptionEmission.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     namespace radiation
00034     {
00035         defineTypeNameAndDebug(wideBandAbsorptionEmission, 0);
00036 
00037         addToRunTimeSelectionTable
00038         (
00039             absorptionEmissionModel,
00040             wideBandAbsorptionEmission,
00041             dictionary
00042         );
00043     }
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 Foam::radiation::wideBandAbsorptionEmission::wideBandAbsorptionEmission
00050 (
00051     const dictionary& dict,
00052     const fvMesh& mesh
00053 )
00054 :
00055     absorptionEmissionModel(dict, mesh),
00056     coeffsDict_((dict.subDict(typeName + "Coeffs"))),
00057     speciesNames_(0),
00058     specieIndex_(0),
00059     lookUpTable_
00060     (
00061         fileName(coeffsDict_.lookup("lookUpTableFileName")),
00062         mesh.time().constant(),
00063         mesh
00064     ),
00065     thermo_(mesh.lookupObject<basicThermo>("thermophysicalProperties")),
00066     Yj_(nSpecies_),
00067     totalWaveLength_(0)
00068 {
00069     label nBand = 0;
00070     const dictionary& functionDicts = dict.subDict(typeName +"Coeffs");
00071     forAllConstIter(dictionary, functionDicts, iter)
00072     {
00073         // safety:
00074         if (!iter().isDict())
00075         {
00076             continue;
00077         }
00078 
00079         const dictionary& dict = iter().dict();
00080         dict.lookup("bandLimits") >> iBands_[nBand];
00081         dict.lookup("EhrrCoeff") >> iEhrrCoeffs_[nBand];
00082         totalWaveLength_ += iBands_[nBand][1] - iBands_[nBand][0];
00083 
00084         label nSpec = 0;
00085         const dictionary& specDicts = dict.subDict("species");
00086         forAllConstIter(dictionary, specDicts, iter)
00087         {
00088             const word& key = iter().keyword();
00089             if (nBand == 0)
00090             {
00091                 speciesNames_.insert(key, nSpec);
00092             }
00093             else
00094             {
00095                 if (!speciesNames_.found(key))
00096                 {
00097                     FatalErrorIn
00098                     (
00099                         "Foam::radiation::wideBandAbsorptionEmission(const"
00100                         "dictionary& dict, const fvMesh& mesh)"
00101                     )   << "specie: " << key << "is not in all the bands"
00102                         << nl << exit(FatalError);
00103                 }
00104             }
00105             coeffs_[nSpec][nBand].initialise(specDicts.subDict(key));
00106             nSpec++;
00107         }
00108         nBand++;
00109     }
00110     nBands_ = nBand;
00111 
00112     // Check that all the species on the dictionary are present in the
00113     // look-up table  and save the corresponding indices of the look-up table
00114 
00115     label j = 0;
00116     forAllConstIter(HashTable<label>, speciesNames_, iter)
00117     {
00118         if (lookUpTable_.found(iter.key()))
00119         {
00120             label index = lookUpTable_.findFieldIndex(iter.key());
00121             Info<< "specie: " << iter.key() << " found in look-up table "
00122                 << " with index: " << index << endl;
00123             specieIndex_[iter()] = index;
00124         }
00125         else if (mesh.foundObject<volScalarField>(iter.key()))
00126         {
00127             volScalarField& Y = const_cast<volScalarField&>
00128                 (mesh.lookupObject<volScalarField>(iter.key()));
00129 
00130             Yj_.set(j, &Y);
00131 
00132             specieIndex_[iter()] = 0.0;
00133             j++;
00134             Info<< "species: " << iter.key() << " is being solved" << endl;
00135         }
00136         else
00137         {
00138             FatalErrorIn
00139             (
00140                 "radiation::wideBandAbsorptionEmission(const"
00141                 "dictionary& dict, const fvMesh& mesh)"
00142             )   << "specie: " << iter.key()
00143                 << " is neither in look-up table : "
00144                 << lookUpTable_.tableName() << " nor is being solved"
00145                 << exit(FatalError);
00146         }
00147     }
00148 }
00149 
00150 
00151 
00152 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00153 
00154 Foam::radiation::wideBandAbsorptionEmission::~wideBandAbsorptionEmission()
00155 {}
00156 
00157 
00158 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00159 
00160 Foam::tmp<Foam::volScalarField>
00161 Foam::radiation::wideBandAbsorptionEmission::aCont(const label bandI) const
00162 {
00163     const volScalarField& T = thermo_.T();
00164     const volScalarField& p = thermo_.p();
00165     const volScalarField& ft = mesh_.lookupObject<volScalarField>("ft");
00166 
00167     label nSpecies = speciesNames_.size();
00168 
00169     tmp<volScalarField> ta
00170     (
00171         new volScalarField
00172         (
00173             IOobject
00174             (
00175                 "a",
00176                 mesh().time().timeName(),
00177                 mesh(),
00178                 IOobject::NO_READ,
00179                 IOobject::NO_WRITE
00180             ),
00181             mesh(),
00182             dimensionedScalar("a", dimless/dimLength, 0.0)
00183         )
00184     );
00185 
00186     scalarField& a = ta().internalField();
00187 
00188     forAll(a, i)
00189     {
00190         const List<scalar>& species = lookUpTable_.lookUp(ft[i]);
00191 
00192         for (label n=0; n<nSpecies; n++)
00193         {
00194             label l = 0;
00195             scalar Yipi = 0.0;
00196             if (specieIndex_[n] != 0)
00197             {
00198                 // moles x pressure [atm]
00199                 Yipi = species[specieIndex_[n]]*p[i]*9.869231e-6;
00200             }
00201             else
00202             {
00203                 // mass fraction from species being solved
00204                 Yipi = Yj_[l][i];
00205                 l++;
00206             }
00207 
00208             scalar Ti = T[i];
00209 
00210             const absorptionCoeffs::coeffArray& b =
00211                 coeffs_[n][bandI].coeffs(T[i]);
00212 
00213             if (coeffs_[n][bandI].invTemp())
00214             {
00215                 Ti = 1.0/T[i];
00216             }
00217 
00218             a[i]+=
00219                 Yipi
00220                *(
00221                     ((((b[5]*Ti + b[4])*Ti + b[3])*Ti + b[2])*Ti + b[1])*Ti
00222                   + b[0]
00223                 );
00224         }
00225     }
00226 
00227     return ta;
00228 }
00229 
00230 
00231 Foam::tmp<Foam::volScalarField>
00232 Foam::radiation::wideBandAbsorptionEmission::eCont(const label bandI) const
00233 {
00234     tmp<volScalarField> e
00235     (
00236         new volScalarField
00237         (
00238             IOobject
00239             (
00240                 "e",
00241                 mesh().time().timeName(),
00242                 mesh(),
00243                 IOobject::NO_READ,
00244                 IOobject::NO_WRITE
00245             ),
00246             mesh(),
00247             dimensionedScalar("e", dimless/dimLength, 0.0)
00248         )
00249     );
00250 
00251     return e;
00252 }
00253 
00254 
00255 Foam::tmp<Foam::volScalarField>
00256 Foam::radiation::wideBandAbsorptionEmission::ECont(const label bandI) const
00257 {
00258     tmp<volScalarField> E
00259     (
00260         new volScalarField
00261         (
00262             IOobject
00263             (
00264                 "E",
00265                 mesh().time().timeName(),
00266                 mesh(),
00267                 IOobject::NO_READ,
00268                 IOobject::NO_WRITE
00269             ),
00270             mesh(),
00271             dimensionedScalar("E", dimMass/dimLength/pow3(dimTime), 0.0)
00272         )
00273     );
00274 
00275     if (mesh().foundObject<volScalarField>("hrr"))
00276     {
00277         const volScalarField& hrr = mesh().lookupObject<volScalarField>("hrr");
00278         E().internalField() =
00279             iEhrrCoeffs_[bandI]
00280            *hrr.internalField()
00281            *(iBands_[bandI][1] - iBands_[bandI][0])
00282            /totalWaveLength_;
00283     }
00284 
00285     return E;
00286 }
00287 
00288 Foam::tmp<Foam::volScalarField>
00289 Foam::radiation::wideBandAbsorptionEmission::addIntensity
00290 (
00291     const label i,
00292     const volScalarField& ILambda
00293 ) const
00294 {
00295     return ILambda*(iBands_[i][1] - iBands_[i][0])/totalWaveLength_;
00296 }
00297 
00298 
00299 void Foam::radiation::wideBandAbsorptionEmission::correct
00300 (
00301     volScalarField& a,
00302     PtrList<volScalarField>& aLambda
00303 ) const
00304 {
00305     a = dimensionedScalar("zero", dimless/dimLength, 0.0);
00306 
00307     for (label j=0; j<nBands_; j++)
00308     {
00309         Info<< "Calculating absorption in band: " << j << endl;
00310         aLambda[j].internalField() = this->a(j);
00311         Info<< "Calculated absorption in band: " << j << endl;
00312         a.internalField() +=
00313             aLambda[j].internalField()
00314            *(iBands_[j][1] - iBands_[j][0])
00315            /totalWaveLength_;
00316     }
00317 
00318 }
00319 
00320 
00321 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines