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

ePsiThermo.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-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 "ePsiThermo.H"
00028 #include "fvMesh.H"
00029 #include "fixedValueFvPatchFields.H"
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 template<class MixtureType>
00034 void Foam::ePsiThermo<MixtureType>::calculate()
00035 {
00036     const scalarField& eCells = e_.internalField();
00037     const scalarField& pCells = this->p_.internalField();
00038 
00039     scalarField& TCells = this->T_.internalField();
00040     scalarField& psiCells = this->psi_.internalField();
00041     scalarField& muCells = this->mu_.internalField();
00042     scalarField& alphaCells = this->alpha_.internalField();
00043 
00044     forAll(TCells, celli)
00045     {
00046         const typename MixtureType::thermoType& mixture_ =
00047             this->cellMixture(celli);
00048 
00049         TCells[celli] = mixture_.TE(eCells[celli], TCells[celli]);
00050         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
00051 
00052         muCells[celli] = mixture_.mu(TCells[celli]);
00053         alphaCells[celli] = mixture_.alpha(TCells[celli]);
00054     }
00055 
00056     forAll(this->T_.boundaryField(), patchi)
00057     {
00058         fvPatchScalarField& pp = this->p_.boundaryField()[patchi];
00059         fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
00060         fvPatchScalarField& ppsi = this->psi_.boundaryField()[patchi];
00061 
00062         fvPatchScalarField& pe = e_.boundaryField()[patchi];
00063 
00064         fvPatchScalarField& pmu = this->mu_.boundaryField()[patchi];
00065         fvPatchScalarField& palpha = this->alpha_.boundaryField()[patchi];
00066 
00067         if (pT.fixesValue())
00068         {
00069             forAll(pT, facei)
00070             {
00071                 const typename MixtureType::thermoType& mixture_ =
00072                     this->patchFaceMixture(patchi, facei);
00073 
00074                 pe[facei] = mixture_.E(pT[facei]);
00075 
00076                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
00077                 pmu[facei] = mixture_.mu(pT[facei]);
00078                 palpha[facei] = mixture_.alpha(pT[facei]);
00079             }
00080         }
00081         else
00082         {
00083             forAll(pT, facei)
00084             {
00085                 const typename MixtureType::thermoType& mixture_ =
00086                     this->patchFaceMixture(patchi, facei);
00087 
00088                 pT[facei] = mixture_.TE(pe[facei], pT[facei]);
00089 
00090                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
00091                 pmu[facei] = mixture_.mu(pT[facei]);
00092                 palpha[facei] = mixture_.alpha(pT[facei]);
00093             }
00094         }
00095     }
00096 }
00097 
00098 
00099 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00100 
00101 template<class MixtureType>
00102 Foam::ePsiThermo<MixtureType>::ePsiThermo(const fvMesh& mesh)
00103 :
00104     basicPsiThermo(mesh),
00105     MixtureType(*this, mesh),
00106 
00107     e_
00108     (
00109         IOobject
00110         (
00111             "e",
00112             mesh.time().timeName(),
00113             mesh,
00114             IOobject::NO_READ,
00115             IOobject::NO_WRITE
00116         ),
00117         mesh,
00118         dimensionSet(0, 2, -2, 0, 0),
00119         this->eBoundaryTypes()
00120     )
00121 {
00122     scalarField& eCells = e_.internalField();
00123     const scalarField& TCells = this->T_.internalField();
00124 
00125     forAll(eCells, celli)
00126     {
00127         eCells[celli] = this->cellMixture(celli).E(TCells[celli]);
00128     }
00129 
00130     forAll(e_.boundaryField(), patchi)
00131     {
00132         e_.boundaryField()[patchi] ==
00133             e(this->T_.boundaryField()[patchi], patchi);
00134     }
00135 
00136     this->eBoundaryCorrection(e_);
00137 
00138     calculate();
00139 
00140     // Switch on saving old time
00141     this->psi_.oldTime();
00142 }
00143 
00144 
00145 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00146 
00147 template<class MixtureType>
00148 Foam::ePsiThermo<MixtureType>::~ePsiThermo()
00149 {}
00150 
00151 
00152 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00153 
00154 template<class MixtureType>
00155 void Foam::ePsiThermo<MixtureType>::correct()
00156 {
00157     if (debug)
00158     {
00159         Info<< "entering ePsiThermo<MixtureType>::correct()" << endl;
00160     }
00161 
00162     // force the saving of the old-time values
00163     this->psi_.oldTime();
00164 
00165     calculate();
00166 
00167     if (debug)
00168     {
00169         Info<< "exiting ePsiThermo<MixtureType>::correct()" << endl;
00170     }
00171 }
00172 
00173 
00174 template<class MixtureType>
00175 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::e
00176 (
00177     const scalarField& T,
00178     const labelList& cells
00179 ) const
00180 {
00181     tmp<scalarField> te(new scalarField(T.size()));
00182     scalarField& h = te();
00183 
00184     forAll(T, celli)
00185     {
00186         h[celli] = this->cellMixture(cells[celli]).E(T[celli]);
00187     }
00188 
00189     return te;
00190 }
00191 
00192 
00193 template<class MixtureType>
00194 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::e
00195 (
00196     const scalarField& T,
00197     const label patchi
00198 ) const
00199 {
00200     tmp<scalarField> te(new scalarField(T.size()));
00201     scalarField& h = te();
00202 
00203     forAll(T, facei)
00204     {
00205         h[facei] = this->patchFaceMixture(patchi, facei).E(T[facei]);
00206     }
00207 
00208     return te;
00209 }
00210 
00211 
00212 template<class MixtureType>
00213 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::Cp
00214 (
00215     const scalarField& T,
00216     const label patchi
00217 ) const
00218 {
00219     tmp<scalarField> tCp(new scalarField(T.size()));
00220     scalarField& cp = tCp();
00221 
00222     forAll(T, facei)
00223     {
00224         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
00225     }
00226 
00227     return tCp;
00228 }
00229 
00230 
00231 template<class MixtureType>
00232 Foam::tmp<Foam::volScalarField> Foam::ePsiThermo<MixtureType>::Cp() const
00233 {
00234     const fvMesh& mesh = this->T_.mesh();
00235 
00236     tmp<volScalarField> tCp
00237     (
00238         new volScalarField
00239         (
00240             IOobject
00241             (
00242                 "Cp",
00243                 mesh.time().timeName(),
00244                 mesh,
00245                 IOobject::NO_READ,
00246                 IOobject::NO_WRITE
00247             ),
00248             mesh,
00249             dimensionSet(0, 2, -2, -1, 0),
00250             this->T_.boundaryField().types()
00251         )
00252     );
00253 
00254     volScalarField& cp = tCp();
00255 
00256     forAll(this->T_, celli)
00257     {
00258         cp[celli] = this->cellMixture(celli).Cp(this->T_[celli]);
00259     }
00260 
00261     forAll(this->T_.boundaryField(), patchi)
00262     {
00263         const fvPatchScalarField& pT = this->T_.boundaryField()[patchi];
00264         fvPatchScalarField& pCp = cp.boundaryField()[patchi];
00265 
00266         forAll(pT, facei)
00267         {
00268             pCp[facei] = this->patchFaceMixture(patchi, facei).Cp(pT[facei]);
00269         }
00270     }
00271 
00272     return tCp;
00273 }
00274 
00275 
00276 template<class MixtureType>
00277 Foam::tmp<Foam::scalarField> Foam::ePsiThermo<MixtureType>::Cv
00278 (
00279     const scalarField& T,
00280     const label patchi
00281 ) const
00282 {
00283     tmp<scalarField> tCv(new scalarField(T.size()));
00284     scalarField& cv = tCv();
00285 
00286     forAll(T, facei)
00287     {
00288         cv[facei] = this->patchFaceMixture(patchi, facei).Cv(T[facei]);
00289     }
00290 
00291     return tCv;
00292 }
00293 
00294 
00295 template<class MixtureType>
00296 Foam::tmp<Foam::volScalarField> Foam::ePsiThermo<MixtureType>::Cv() const
00297 {
00298     const fvMesh& mesh = this->T_.mesh();
00299 
00300     tmp<volScalarField> tCv
00301     (
00302         new volScalarField
00303         (
00304             IOobject
00305             (
00306                 "Cv",
00307                 mesh.time().timeName(),
00308                 mesh,
00309                 IOobject::NO_READ,
00310                 IOobject::NO_WRITE
00311             ),
00312             mesh,
00313             dimensionSet(0, 2, -2, -1, 0)
00314         )
00315     );
00316 
00317     volScalarField& cv = tCv();
00318 
00319     forAll(this->T_, celli)
00320     {
00321         cv[celli] = this->cellMixture(celli).Cv(this->T_[celli]);
00322     }
00323 
00324     forAll(this->T_.boundaryField(), patchi)
00325     {
00326         cv.boundaryField()[patchi] =
00327             Cv(this->T_.boundaryField()[patchi], patchi);
00328     }
00329 
00330     return tCv;
00331 }
00332 
00333 
00334 template<class MixtureType>
00335 bool Foam::ePsiThermo<MixtureType>::read()
00336 {
00337     if (basicPsiThermo::read())
00338     {
00339         MixtureType::read(*this);
00340         return true;
00341     }
00342     else
00343     {
00344         return false;
00345     }
00346 }
00347 
00348 
00349 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd