OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

fvDOM.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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "fvDOM.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "fvm.H"
00030 
00031 #include "absorptionEmissionModel.H"
00032 #include "scatterModel.H"
00033 #include "mathematicalConstants.H"
00034 #include "radiationConstants.H"
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040     namespace radiation
00041     {
00042         defineTypeNameAndDebug(fvDOM, 0);
00043 
00044         addToRunTimeSelectionTable
00045         (
00046             radiationModel,
00047             fvDOM,
00048             dictionary
00049         );
00050     }
00051 }
00052 
00053 
00054 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00055 
00056 Foam::radiation::fvDOM::fvDOM(const volScalarField& T)
00057 :
00058     radiationModel(typeName, T),
00059     G_
00060     (
00061         IOobject
00062         (
00063             "G",
00064             mesh_.time().timeName(),
00065             mesh_,
00066             IOobject::NO_READ,
00067             IOobject::NO_WRITE
00068         ),
00069         mesh_,
00070         dimensionedScalar("G", dimMass/pow3(dimTime), 0.0)
00071     ),
00072     Qr_
00073     (
00074         IOobject
00075         (
00076             "Qr",
00077             mesh_.time().timeName(),
00078             mesh_,
00079             IOobject::NO_READ,
00080             IOobject::AUTO_WRITE
00081         ),
00082         mesh_,
00083         dimensionedScalar("Qr", dimMass/pow3(dimTime), 0.0)
00084     ),
00085     a_
00086     (
00087         IOobject
00088         (
00089             "a",
00090             mesh_.time().timeName(),
00091             mesh_,
00092             IOobject::NO_READ,
00093             IOobject::AUTO_WRITE
00094         ),
00095         mesh_,
00096         dimensionedScalar("a", dimless/dimLength, 0.0)
00097     ),
00098     e_
00099     (
00100         IOobject
00101         (
00102             "e",
00103             mesh_.time().timeName(),
00104             mesh_,
00105             IOobject::NO_READ,
00106             IOobject::NO_WRITE
00107         ),
00108         mesh_,
00109         dimensionedScalar("a", dimless/dimLength, 0.0)
00110     ),
00111     E_
00112     (
00113         IOobject
00114         (
00115             "E",
00116             mesh_.time().timeName(),
00117             mesh_,
00118             IOobject::NO_READ,
00119             IOobject::NO_WRITE
00120         ),
00121         mesh_,
00122         dimensionedScalar("E", dimMass/dimLength/pow3(dimTime), 0.0)
00123     ),
00124     nTheta_(readLabel(coeffs_.lookup("nTheta"))),
00125     nPhi_(readLabel(coeffs_.lookup("nPhi"))),
00126     nRay_(0),
00127     nLambda_(absorptionEmission_->nBands()),
00128     aLambda_(nLambda_),
00129     blackBody_(nLambda_, T),
00130     IRay_(0),
00131     convergence_(coeffs_.lookupOrDefault<scalar>("convergence", 0.0)),
00132     maxIter_(coeffs_.lookupOrDefault<label>("maxIter", 50))
00133 {
00134     if (mesh_.nSolutionD() == 3)    //3D
00135     {
00136         nRay_ = 4*nPhi_*nTheta_;
00137         IRay_.setSize(nRay_);
00138         scalar deltaPhi = mathematicalConstant::pi/(2.0*nPhi_);
00139         scalar deltaTheta = mathematicalConstant::pi/nTheta_;
00140         label i = 0;
00141         for (label n = 1; n <= nTheta_; n++)
00142         {
00143             for (label m = 1; m <= 4*nPhi_; m++)
00144             {
00145                 scalar thetai = (2.0*n - 1.0)*deltaTheta/2.0;
00146                 scalar phii = (2.0*m - 1.0)*deltaPhi/2.0;
00147                 IRay_.set
00148                 (
00149                     i,
00150                     new radiativeIntensityRay
00151                     (
00152                         *this,
00153                         mesh_,
00154                         phii,
00155                         thetai,
00156                         deltaPhi,
00157                         deltaTheta,
00158                         nLambda_,
00159                         absorptionEmission_,
00160                         blackBody_
00161                     )
00162                 );
00163                 i++;
00164             }
00165         }
00166     }
00167     else
00168     {
00169         if (mesh_.nSolutionD() == 2)    //2D (X & Y)
00170         {
00171             scalar thetai = mathematicalConstant::pi/2.0;
00172             scalar deltaTheta = mathematicalConstant::pi;
00173             nRay_ = 4*nPhi_;
00174             IRay_.setSize(nRay_);
00175             scalar deltaPhi = mathematicalConstant::pi/(2.0*nPhi_);
00176             label i = 0;
00177             for (label m = 1; m <= 4*nPhi_; m++)
00178             {
00179                 scalar phii = (2.0*m - 1.0)*deltaPhi/2.0;
00180                 IRay_.set
00181                 (
00182                     i,
00183                     new radiativeIntensityRay
00184                     (
00185                         *this,
00186                         mesh_,
00187                         phii,
00188                         thetai,
00189                         deltaPhi,
00190                         deltaTheta,
00191                         nLambda_,
00192                         absorptionEmission_,
00193                         blackBody_
00194                     )
00195                 );
00196                 i++;
00197             }
00198         }
00199         else    //1D (X)
00200         {
00201             scalar thetai = mathematicalConstant::pi/2.0;
00202             scalar deltaTheta = mathematicalConstant::pi;
00203             nRay_ = 2;
00204             IRay_.setSize(nRay_);
00205             scalar deltaPhi = mathematicalConstant::pi;
00206             label i = 0;
00207             for (label m = 1; m <= 2; m++)
00208             {
00209                 scalar phii = (2.0*m - 1.0)*deltaPhi/2.0;
00210                 IRay_.set
00211                 (
00212                     i,
00213                     new radiativeIntensityRay
00214                     (
00215                         *this,
00216                         mesh_,
00217                         phii,
00218                         thetai,
00219                         deltaPhi,
00220                         deltaTheta,
00221                         nLambda_,
00222                         absorptionEmission_,
00223                         blackBody_
00224                     )
00225                 );
00226                 i++;
00227             }
00228 
00229         }
00230     }
00231 
00232 
00233     // Construct absorption field for each wavelength
00234     forAll(aLambda_, lambdaI)
00235     {
00236         aLambda_.set
00237         (
00238             lambdaI,
00239             new volScalarField
00240             (
00241                 IOobject
00242                 (
00243                     "aLambda_" + Foam::name(lambdaI) ,
00244                     mesh_.time().timeName(),
00245                     mesh_,
00246                     IOobject::NO_READ,
00247                     IOobject::NO_WRITE
00248                 ),
00249                 a_
00250             )
00251         );
00252     }
00253 
00254     Info<< "fvDOM : Allocated " << IRay_.size()
00255         << " rays with average orientation:" << nl;
00256     forAll (IRay_, i)
00257     {
00258         Info<< '\t' << IRay_[i].I().name()
00259             << '\t' << IRay_[i].dAve() << nl;
00260     }
00261     Info<< endl;
00262 }
00263 
00264 
00265 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00266 
00267 Foam::radiation::fvDOM::~fvDOM()
00268 {}
00269 
00270 
00271 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00272 
00273 bool Foam::radiation::fvDOM::read()
00274 {
00275     if (radiationModel::read())
00276     {
00277 //      Only reading solution parameters - not changing ray geometry
00278 
00279         coeffs_.readIfPresent("convergence", convergence_);
00280         coeffs_.readIfPresent("maxIter", maxIter_);
00281 
00282         return true;
00283     }
00284     else
00285     {
00286         return false;
00287     }
00288 }
00289 
00290 
00291 void Foam::radiation::fvDOM::calculate()
00292 {
00293     absorptionEmission_->correct(a_, aLambda_);
00294 
00295     updateBlackBodyEmission();
00296 
00297     scalar maxResidual = 0.0;
00298     label radIter = 0;
00299     do
00300     {
00301         radIter++;
00302         forAll(IRay_, rayI)
00303         {
00304             maxResidual = 0.0;
00305             scalar maxBandResidual = IRay_[rayI].correct();
00306             maxResidual = max(maxBandResidual, maxResidual);
00307         }
00308 
00309         Info << "Radiation solver iter: " << radIter << endl;
00310 
00311     } while(maxResidual > convergence_ && radIter < maxIter_);
00312 
00313     updateG();
00314 }
00315 
00316 
00317 Foam::tmp<Foam::volScalarField> Foam::radiation::fvDOM::Rp() const
00318 {
00319     return tmp<volScalarField>
00320     (
00321         new volScalarField
00322         (
00323             IOobject
00324             (
00325                 "Rp",
00326                 mesh_.time().timeName(),
00327                 mesh_,
00328                 IOobject::NO_READ,
00329                 IOobject::NO_WRITE,
00330                 false
00331             ),
00332             4.0*a_*radiation::sigmaSB //absorptionEmission_->a()
00333         )
00334     );
00335 }
00336 
00337 
00338 Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> >
00339 Foam::radiation::fvDOM::Ru() const
00340 {
00341 
00342     const DimensionedField<scalar, volMesh>& G =
00343         G_.dimensionedInternalField();
00344     const DimensionedField<scalar, volMesh> E =
00345         absorptionEmission_->ECont()().dimensionedInternalField();
00346     const DimensionedField<scalar, volMesh> a =
00347         a_.dimensionedInternalField(); //absorptionEmission_->aCont()()
00348 
00349     return  a*G - 4.0*E;
00350 }
00351 
00352 
00353 void Foam::radiation::fvDOM::updateBlackBodyEmission()
00354 {
00355     for (label j=0; j < nLambda_; j++)
00356     {
00357         blackBody_.correct(j, absorptionEmission_->bands(j));
00358     }
00359 }
00360 
00361 
00362 void Foam::radiation::fvDOM::updateG()
00363 {
00364     G_ = dimensionedScalar("zero",dimMass/pow3(dimTime), 0.0);
00365     Qr_ = dimensionedScalar("zero",dimMass/pow3(dimTime), 0.0);
00366 
00367     forAll(IRay_, rayI)
00368     {
00369         IRay_[rayI].addIntensity();
00370         G_ += IRay_[rayI].I()*IRay_[rayI].omega();
00371         //Qr_ += IRay_[rayI].Qr();
00372         Qr_.boundaryField() += IRay_[rayI].Qr().boundaryField();
00373     }
00374 }
00375 
00376 
00377 void Foam::radiation::fvDOM::setRayIdLambdaId
00378 (
00379     const word& name,
00380     label& rayId,
00381     label& lambdaId
00382 ) const
00383 {
00384     // assuming name is in the form: CHARS_rayId_lambdaId
00385     size_type i1 = name.find_first_of("_");
00386     size_type i2 = name.find_last_of("_");
00387 
00388     rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))());
00389     lambdaId = readLabel(IStringStream(name.substr(i2+1, name.size()-1))());
00390 }
00391 
00392 
00393 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd