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

hhuMixtureThermo.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "hhuMixtureThermo.H"
00027 #include <finiteVolume/fvMesh.H>
00028 #include <finiteVolume/fixedValueFvPatchFields.H>
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 template<class MixtureType>
00033 Foam::hhuMixtureThermo<MixtureType>::hhuMixtureThermo(const fvMesh& mesh)
00034 :
00035     hhuCombustionThermo(mesh),
00036     MixtureType(*this, mesh)
00037 {
00038     scalarField& hCells = h_.internalField();
00039     scalarField& huCells = hu_.internalField();
00040     const scalarField& TCells = T_.internalField();
00041     const scalarField& TuCells = Tu_.internalField();
00042 
00043     forAll(hCells, celli)
00044     {
00045         hCells[celli] = this->cellMixture(celli).H(TCells[celli]);
00046         huCells[celli] = this->cellReactants(celli).H(TuCells[celli]);
00047     }
00048 
00049     forAll(h_.boundaryField(), patchi)
00050     {
00051         h_.boundaryField()[patchi] == h(T_.boundaryField()[patchi], patchi);
00052 
00053         fvPatchScalarField& phu = hu_.boundaryField()[patchi];
00054         const fvPatchScalarField& pTu = Tu_.boundaryField()[patchi];
00055 
00056         forAll(phu, facei)
00057         {
00058             phu[facei] = this->patchFaceReactants(patchi, facei).H(pTu[facei]);
00059         }
00060     }
00061 
00062     hBoundaryCorrection(h_);
00063     huBoundaryCorrection(hu_);
00064 
00065     calculate();
00066     psi_.oldTime();   // Switch on saving old time
00067 }
00068 
00069 
00070 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00071 
00072 template<class MixtureType>
00073 Foam::hhuMixtureThermo<MixtureType>::~hhuMixtureThermo()
00074 {}
00075 
00076 
00077 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00078 
00079 template<class MixtureType>
00080 void Foam::hhuMixtureThermo<MixtureType>::calculate()
00081 {
00082     const scalarField& hCells = h_.internalField();
00083     const scalarField& huCells = hu_.internalField();
00084     const scalarField& pCells = p_.internalField();
00085 
00086     scalarField& TCells = T_.internalField();
00087     scalarField& TuCells = Tu_.internalField();
00088     scalarField& psiCells = psi_.internalField();
00089     scalarField& muCells = mu_.internalField();
00090     scalarField& alphaCells = alpha_.internalField();
00091 
00092     forAll(TCells, celli)
00093     {
00094         const typename MixtureType::thermoType& mixture_ =
00095             this->cellMixture(celli);
00096 
00097         TCells[celli] = mixture_.TH(hCells[celli], TCells[celli]);
00098         psiCells[celli] = mixture_.psi(pCells[celli], TCells[celli]);
00099 
00100         muCells[celli] = mixture_.mu(TCells[celli]);
00101         alphaCells[celli] = mixture_.alpha(TCells[celli]);
00102 
00103         TuCells[celli] =
00104             this->cellReactants(celli).TH(huCells[celli], TuCells[celli]);
00105     }
00106 
00107     forAll(T_.boundaryField(), patchi)
00108     {
00109         fvPatchScalarField& pp = p_.boundaryField()[patchi];
00110         fvPatchScalarField& pT = T_.boundaryField()[patchi];
00111         fvPatchScalarField& pTu = Tu_.boundaryField()[patchi];
00112         fvPatchScalarField& ppsi = psi_.boundaryField()[patchi];
00113 
00114         fvPatchScalarField& ph = h_.boundaryField()[patchi];
00115         fvPatchScalarField& phu = hu_.boundaryField()[patchi];
00116 
00117         fvPatchScalarField& pmu_ = mu_.boundaryField()[patchi];
00118         fvPatchScalarField& palpha_ = alpha_.boundaryField()[patchi];
00119 
00120         if (pT.fixesValue())
00121         {
00122             forAll(pT, facei)
00123             {
00124                 const typename MixtureType::thermoType& mixture_ =
00125                     this->patchFaceMixture(patchi, facei);
00126 
00127                 ph[facei] = mixture_.H(pT[facei]);
00128 
00129                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
00130                 pmu_[facei] = mixture_.mu(pT[facei]);
00131                 palpha_[facei] = mixture_.alpha(pT[facei]);
00132             }
00133         }
00134         else
00135         {
00136             forAll(pT, facei)
00137             {
00138                 const typename MixtureType::thermoType& mixture_ =
00139                     this->patchFaceMixture(patchi, facei);
00140 
00141                 pT[facei] = mixture_.TH(ph[facei], pT[facei]);
00142 
00143                 ppsi[facei] = mixture_.psi(pp[facei], pT[facei]);
00144                 pmu_[facei] = mixture_.mu(pT[facei]);
00145                 palpha_[facei] = mixture_.alpha(pT[facei]);
00146 
00147                 pTu[facei] =
00148                     this->patchFaceReactants(patchi, facei)
00149                    .TH(phu[facei], pTu[facei]);
00150             }
00151         }
00152     }
00153 }
00154 
00155 
00156 template<class MixtureType>
00157 void Foam::hhuMixtureThermo<MixtureType>::correct()
00158 {
00159     if (debug)
00160     {
00161         Info<< "entering hhuMixtureThermo<MixtureType>::correct()" << endl;
00162     }
00163 
00164     // force the saving of the old-time values
00165     psi_.oldTime();
00166 
00167     calculate();
00168 
00169     if (debug)
00170     {
00171         Info<< "exiting hhuMixtureThermo<MixtureType>::correct()" << endl;
00172     }
00173 }
00174 
00175 
00176 template<class MixtureType>
00177 Foam::tmp<Foam::volScalarField>
00178 Foam::hhuMixtureThermo<MixtureType>::hc() const
00179 {
00180     const fvMesh& mesh = T_.mesh();
00181 
00182     tmp<volScalarField> thc
00183     (
00184         new volScalarField
00185         (
00186             IOobject
00187             (
00188                 "hc",
00189                 mesh.time().timeName(),
00190                 mesh,
00191                 IOobject::NO_READ,
00192                 IOobject::NO_WRITE
00193             ),
00194             mesh,
00195             h_.dimensions()
00196         )
00197     );
00198 
00199     volScalarField& hcf = thc();
00200     scalarField& hcCells = hcf.internalField();
00201 
00202     forAll(hcCells, celli)
00203     {
00204         hcCells[celli] = this->cellMixture(celli).Hc();
00205     }
00206 
00207     forAll(hcf.boundaryField(), patchi)
00208     {
00209         scalarField& hcp = hcf.boundaryField()[patchi];
00210 
00211         forAll(hcp, facei)
00212         {
00213             hcp[facei] = this->patchFaceMixture(patchi, facei).Hc();
00214         }
00215     }
00216 
00217     return thc;
00218 }
00219 
00220 
00221 template<class MixtureType>
00222 Foam::tmp<Foam::scalarField> Foam::hhuMixtureThermo<MixtureType>::h
00223 (
00224     const scalarField& T,
00225     const labelList& cells
00226 ) const
00227 {
00228     tmp<scalarField> th(new scalarField(T.size()));
00229     scalarField& h = th();
00230 
00231     forAll(T, celli)
00232     {
00233         h[celli] = this->cellMixture(cells[celli]).H(T[celli]);
00234     }
00235 
00236     return th;
00237 }
00238 
00239 
00240 template<class MixtureType>
00241 Foam::tmp<Foam::scalarField> Foam::hhuMixtureThermo<MixtureType>::h
00242 (
00243     const scalarField& T,
00244     const label patchi
00245 ) const
00246 {
00247     tmp<scalarField> th(new scalarField(T.size()));
00248     scalarField& h = th();
00249 
00250     forAll(T, facei)
00251     {
00252         h[facei] = this->patchFaceMixture(patchi, facei).H(T[facei]);
00253     }
00254 
00255     return th;
00256 }
00257 
00258 
00259 template<class MixtureType>
00260 Foam::tmp<Foam::scalarField> Foam::hhuMixtureThermo<MixtureType>::Cp
00261 (
00262     const scalarField& T,
00263     const label patchi
00264 ) const
00265 {
00266     tmp<scalarField> tCp(new scalarField(T.size()));
00267 
00268     scalarField& cp = tCp();
00269 
00270     forAll(T, facei)
00271     {
00272         cp[facei] = this->patchFaceMixture(patchi, facei).Cp(T[facei]);
00273     }
00274 
00275     return tCp;
00276 }
00277 
00278 
00279 template<class MixtureType>
00280 Foam::tmp<Foam::volScalarField>
00281 Foam::hhuMixtureThermo<MixtureType>::Cp() const
00282 {
00283     const fvMesh& mesh = T_.mesh();
00284 
00285     tmp<volScalarField> tCp
00286     (
00287         new volScalarField
00288         (
00289             IOobject
00290             (
00291                 "Cp",
00292                 mesh.time().timeName(),
00293                 mesh,
00294                 IOobject::NO_READ,
00295                 IOobject::NO_WRITE
00296             ),
00297             mesh,
00298             dimensionSet(0, 2, -2, -1, 0)
00299         )
00300     );
00301 
00302     volScalarField& cp = tCp();
00303     scalarField& cpCells = cp.internalField();
00304     const scalarField& TCells = T_.internalField();
00305 
00306     forAll(TCells, celli)
00307     {
00308         cpCells[celli] = this->cellMixture(celli).Cp(TCells[celli]);
00309     }
00310 
00311     forAll(T_.boundaryField(), patchi)
00312     {
00313         cp.boundaryField()[patchi] = Cp(T_.boundaryField()[patchi], patchi);
00314     }
00315 
00316     return tCp;
00317 }
00318 
00319 
00320 template<class MixtureType>
00321 Foam::tmp<Foam::scalarField>
00322 Foam::hhuMixtureThermo<MixtureType>::hu
00323 (
00324     const scalarField& Tu,
00325     const labelList& cells
00326 ) const
00327 {
00328     tmp<scalarField> thu(new scalarField(Tu.size()));
00329     scalarField& hu = thu();
00330 
00331     forAll(Tu, celli)
00332     {
00333         hu[celli] = this->cellReactants(cells[celli]).H(Tu[celli]);
00334     }
00335 
00336     return thu;
00337 }
00338 
00339 
00340 template<class MixtureType>
00341 Foam::tmp<Foam::scalarField>
00342 Foam::hhuMixtureThermo<MixtureType>::hu
00343 (
00344     const scalarField& Tu,
00345     const label patchi
00346 ) const
00347 {
00348     tmp<scalarField> thu(new scalarField(Tu.size()));
00349     scalarField& hu = thu();
00350 
00351     forAll(Tu, facei)
00352     {
00353         hu[facei] = this->patchFaceReactants(patchi, facei).H(Tu[facei]);
00354     }
00355 
00356     return thu;
00357 }
00358 
00359 
00360 template<class MixtureType>
00361 Foam::tmp<Foam::volScalarField>
00362 Foam::hhuMixtureThermo<MixtureType>::Tb() const
00363 {
00364     tmp<volScalarField> tTb
00365     (
00366         new volScalarField
00367         (
00368             IOobject
00369             (
00370                 "Tb",
00371                 T_.time().timeName(),
00372                 T_.db(),
00373                 IOobject::NO_READ,
00374                 IOobject::NO_WRITE
00375             ),
00376             T_
00377         )
00378     );
00379 
00380     volScalarField& Tb_ = tTb();
00381     scalarField& TbCells = Tb_.internalField();
00382     const scalarField& TCells = T_.internalField();
00383     const scalarField& hCells = h_.internalField();
00384 
00385     forAll(TbCells, celli)
00386     {
00387         TbCells[celli] =
00388             this->cellProducts(celli).TH(hCells[celli], TCells[celli]);
00389     }
00390 
00391     forAll(Tb_.boundaryField(), patchi)
00392     {
00393         fvPatchScalarField& pTb = Tb_.boundaryField()[patchi];
00394 
00395         const fvPatchScalarField& ph = h_.boundaryField()[patchi];
00396         const fvPatchScalarField& pT = T_.boundaryField()[patchi];
00397 
00398         forAll(pTb, facei)
00399         {
00400             pTb[facei] =
00401                 this->patchFaceProducts(patchi, facei)
00402                .TH(ph[facei], pT[facei]);
00403         }
00404     }
00405 
00406     return tTb;
00407 }
00408 
00409 
00410 template<class MixtureType>
00411 Foam::tmp<Foam::volScalarField>
00412 Foam::hhuMixtureThermo<MixtureType>::psiu() const
00413 {
00414     tmp<volScalarField> tpsiu
00415     (
00416         new volScalarField
00417         (
00418             IOobject
00419             (
00420                 "psiu",
00421                 psi_.time().timeName(),
00422                 psi_.db(),
00423                 IOobject::NO_READ,
00424                 IOobject::NO_WRITE
00425             ),
00426             psi_.mesh(),
00427             psi_.dimensions()
00428         )
00429     );
00430 
00431     volScalarField& psiu = tpsiu();
00432     scalarField& psiuCells = psiu.internalField();
00433     const scalarField& TuCells = Tu_.internalField();
00434     const scalarField& pCells = p_.internalField();
00435 
00436     forAll(psiuCells, celli)
00437     {
00438         psiuCells[celli] =
00439             this->cellReactants(celli).psi(pCells[celli], TuCells[celli]);
00440     }
00441 
00442     forAll(psiu.boundaryField(), patchi)
00443     {
00444         fvPatchScalarField& ppsiu = psiu.boundaryField()[patchi];
00445 
00446         const fvPatchScalarField& pp = p_.boundaryField()[patchi];
00447         const fvPatchScalarField& pTu = Tu_.boundaryField()[patchi];
00448 
00449         forAll(ppsiu, facei)
00450         {
00451             ppsiu[facei] =
00452                 this->
00453                 patchFaceReactants(patchi, facei).psi(pp[facei], pTu[facei]);
00454         }
00455     }
00456 
00457     return tpsiu;
00458 }
00459 
00460 
00461 template<class MixtureType>
00462 Foam::tmp<Foam::volScalarField>
00463 Foam::hhuMixtureThermo<MixtureType>::psib() const
00464 {
00465     tmp<volScalarField> tpsib
00466     (
00467         new volScalarField
00468         (
00469             IOobject
00470             (
00471                 "psib",
00472                 psi_.time().timeName(),
00473                 psi_.db(),
00474                 IOobject::NO_READ,
00475                 IOobject::NO_WRITE
00476             ),
00477             psi_.mesh(),
00478             psi_.dimensions()
00479         )
00480     );
00481 
00482     volScalarField& psib = tpsib();
00483     scalarField& psibCells = psib.internalField();
00484     volScalarField Tb_ = Tb();
00485     const scalarField& TbCells = Tb_.internalField();
00486     const scalarField& pCells = p_.internalField();
00487 
00488     forAll(psibCells, celli)
00489     {
00490         psibCells[celli] =
00491             this->cellReactants(celli).psi(pCells[celli], TbCells[celli]);
00492     }
00493 
00494     forAll(psib.boundaryField(), patchi)
00495     {
00496         fvPatchScalarField& ppsib = psib.boundaryField()[patchi];
00497 
00498         const fvPatchScalarField& pp = p_.boundaryField()[patchi];
00499         const fvPatchScalarField& pTb = Tb_.boundaryField()[patchi];
00500 
00501         forAll(ppsib, facei)
00502         {
00503             ppsib[facei] =
00504                 this->patchFaceReactants
00505                 (patchi, facei).psi(pp[facei], pTb[facei]);
00506         }
00507     }
00508 
00509     return tpsib;
00510 }
00511 
00512 
00513 template<class MixtureType>
00514 Foam::tmp<Foam::volScalarField>
00515 Foam::hhuMixtureThermo<MixtureType>::muu() const
00516 {
00517     tmp<volScalarField> tmuu
00518     (
00519         new volScalarField
00520         (
00521             IOobject
00522             (
00523                 "muu",
00524                 T_.time().timeName(),
00525                 T_.db(),
00526                 IOobject::NO_READ,
00527                 IOobject::NO_WRITE
00528             ),
00529             T_.mesh(),
00530             dimensionSet(1, -1, -1, 0, 0)
00531         )
00532     );
00533 
00534     volScalarField& muu_ = tmuu();
00535     scalarField& muuCells = muu_.internalField();
00536     const scalarField& TuCells = Tu_.internalField();
00537 
00538     forAll(muuCells, celli)
00539     {
00540         muuCells[celli] = this->cellReactants(celli).mu(TuCells[celli]);
00541     }
00542 
00543     forAll(muu_.boundaryField(), patchi)
00544     {
00545         fvPatchScalarField& pMuu = muu_.boundaryField()[patchi];
00546         const fvPatchScalarField& pTu = Tu_.boundaryField()[patchi];
00547 
00548         forAll(pMuu, facei)
00549         {
00550             pMuu[facei] =
00551                 this->patchFaceReactants(patchi, facei).mu(pTu[facei]);
00552         }
00553     }
00554 
00555     return tmuu;
00556 }
00557 
00558 
00559 template<class MixtureType>
00560 Foam::tmp<Foam::volScalarField>
00561 Foam::hhuMixtureThermo<MixtureType>::mub() const
00562 {
00563     tmp<volScalarField> tmub
00564     (
00565         new volScalarField
00566         (
00567             IOobject
00568             (
00569                 "mub",
00570                 T_.time().timeName(),
00571                 T_.db(),
00572                 IOobject::NO_READ,
00573                 IOobject::NO_WRITE
00574             ),
00575             T_.mesh(),
00576             dimensionSet(1, -1, -1, 0, 0)
00577         )
00578     );
00579 
00580     volScalarField& mub_ = tmub();
00581     scalarField& mubCells = mub_.internalField();
00582     volScalarField Tb_ = Tb();
00583     const scalarField& TbCells = Tb_.internalField();
00584 
00585     forAll(mubCells, celli)
00586     {
00587         mubCells[celli] = this->cellProducts(celli).mu(TbCells[celli]);
00588     }
00589 
00590     forAll(mub_.boundaryField(), patchi)
00591     {
00592         fvPatchScalarField& pMub = mub_.boundaryField()[patchi];
00593         const fvPatchScalarField& pTb = Tb_.boundaryField()[patchi];
00594 
00595         forAll(pMub, facei)
00596         {
00597             pMub[facei] =
00598                 this->patchFaceProducts(patchi, facei).mu(pTb[facei]);
00599         }
00600     }
00601 
00602     return tmub;
00603 }
00604 
00605 
00606 template<class MixtureType>
00607 bool Foam::hhuMixtureThermo<MixtureType>::read()
00608 {
00609     if (hhuCombustionThermo::read())
00610     {
00611         MixtureType::read(*this);
00612         return true;
00613     }
00614     else
00615     {
00616         return false;
00617     }
00618 }
00619 
00620 
00621 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines