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

CompositionModel.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 "CompositionModel.H"
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 template<class CloudType>
00032 Foam::CompositionModel<CloudType>::CompositionModel
00033 (
00034     const dictionary& dict,
00035     CloudType& owner,
00036     const word& type
00037 )
00038 :
00039     dict_(dict),
00040     owner_(owner),
00041     coeffDict_(dict.subDict(type + "Coeffs")),
00042     mcCarrierThermo_(owner.mcCarrierThermo()),
00043     liquids_
00044     (
00045         liquidMixture::New
00046         (
00047             owner.mesh().objectRegistry::lookupObject<dictionary>
00048             (
00049                 owner.carrierThermo().name()
00050             )
00051         )
00052     ),
00053     solids_
00054     (
00055         solidMixture::New
00056         (
00057             owner.mesh().objectRegistry::lookupObject<dictionary>
00058             (
00059                 owner.carrierThermo().name()
00060             )
00061         )
00062     ),
00063     phaseProps_
00064     (
00065         coeffDict_.lookup("phases"),
00066         mcCarrierThermo_.species(),
00067         liquids_().components(),
00068         solids_().components()
00069     )
00070 {}
00071 
00072 
00073 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00074 
00075 template<class CloudType>
00076 Foam::CompositionModel<CloudType>::~CompositionModel()
00077 {}
00078 
00079 
00080 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00081 
00082 template<class CloudType>
00083 const CloudType& Foam::CompositionModel<CloudType>::owner() const
00084 {
00085     return owner_;
00086 }
00087 
00088 
00089 template<class CloudType>
00090 const Foam::dictionary& Foam::CompositionModel<CloudType>::dict() const
00091 {
00092     return dict_;
00093 }
00094 
00095 
00096 template<class CloudType>
00097 const Foam::dictionary& Foam::CompositionModel<CloudType>::coeffDict() const
00098 {
00099     return coeffDict_;
00100 }
00101 
00102 
00103 template<class CloudType>
00104 const Foam::multiComponentMixture<typename CloudType::thermoType>&
00105 Foam::CompositionModel<CloudType>::mcCarrierThermo() const
00106 {
00107     return mcCarrierThermo_;
00108 }
00109 
00110 
00111 template<class CloudType>
00112 const Foam::liquidMixture& Foam::CompositionModel<CloudType>::liquids() const
00113 {
00114     return liquids_();
00115 }
00116 
00117 
00118 template<class CloudType>
00119 const Foam::solidMixture& Foam::CompositionModel<CloudType>::solids() const
00120 {
00121     return solids_();
00122 }
00123 
00124 
00125 template<class CloudType>
00126 const Foam::phasePropertiesList&
00127 Foam::CompositionModel<CloudType>::phaseProps() const
00128 {
00129     return phaseProps_;
00130 }
00131 
00132 
00133 template<class CloudType>
00134 Foam::label Foam::CompositionModel<CloudType>::nPhase() const
00135 {
00136     return phaseProps_.size();
00137 }
00138 
00139 
00140 template<class CloudType>
00141 const Foam::wordList&
00142 Foam::CompositionModel<CloudType>::phaseTypes() const
00143 {
00144     // if only 1 phase, return the constituent component names
00145     if (phaseProps_.size() == 1)
00146     {
00147         return phaseProps_[0].names();
00148     }
00149     else
00150     {
00151         return phaseProps_.phaseTypes();
00152     }
00153 }
00154 
00155 
00156 template<class CloudType>
00157 const Foam::wordList&
00158 Foam::CompositionModel<CloudType>::stateLabels() const
00159 {
00160     return phaseProps_.stateLabels();
00161 }
00162 
00163 
00164 template<class CloudType>
00165 const Foam::wordList&
00166 Foam::CompositionModel<CloudType>::componentNames(const label phaseI) const
00167 {
00168     return phaseProps_[phaseI].names();
00169 }
00170 
00171 
00172 template<class CloudType>
00173 Foam::label Foam::CompositionModel<CloudType>::globalCarrierId
00174 (
00175     const word& cmptName
00176 ) const
00177 {
00178     forAll(mcCarrierThermo_.species(), i)
00179     {
00180         if (cmptName == mcCarrierThermo_.species()[i])
00181         {
00182             return i;
00183         }
00184     }
00185 
00186     FatalErrorIn
00187     (
00188         "Foam::label Foam::CompositionModel<CloudType>::globalCarrierId"
00189         "("
00190             "const word&"
00191         ") const"
00192     )   << "Unable to determine global id for requested component "
00193         << cmptName << nl << abort(FatalError);
00194 
00195     return -1;
00196 }
00197 
00198 
00199 template<class CloudType>
00200 Foam::label Foam::CompositionModel<CloudType>::globalId
00201 (
00202     const label phaseI,
00203     const word& cmptName
00204 ) const
00205 {
00206     label id = phaseProps_[phaseI].globalId(cmptName);
00207 
00208     if (id < 0)
00209     {
00210         FatalErrorIn
00211         (
00212             "Foam::label Foam::CompositionModel<CloudType>::globalId"
00213             "("
00214                 "const label, "
00215                 "const word&"
00216             ") const"
00217         )   << "Unable to determine global id for requested component "
00218             << cmptName << nl << abort(FatalError);
00219     }
00220 
00221     return id;
00222 }
00223 
00224 
00225 template<class CloudType>
00226 const Foam::labelList& Foam::CompositionModel<CloudType>::globalIds
00227 (
00228     const label phaseI
00229 ) const
00230 {
00231     return phaseProps_[phaseI].globalIds();
00232 }
00233 
00234 
00235 template<class CloudType>
00236 Foam::label Foam::CompositionModel<CloudType>::localId
00237 (
00238     const label phaseI,
00239     const word& cmptName
00240 ) const
00241 {
00242     label id = phaseProps_[phaseI].id(cmptName);
00243 
00244     if (id < 0)
00245     {
00246         FatalErrorIn
00247         (
00248             "Foam::label Foam::CompositionModel<CloudType>::localId"
00249             "("
00250                 "const label, "
00251                 "const word&"
00252             ") const"
00253         )   << "Unable to determine local id for component " << cmptName
00254             << nl << abort(FatalError);
00255     }
00256 
00257     return id;
00258 }
00259 
00260 
00261 template<class CloudType>
00262 Foam::label Foam::CompositionModel<CloudType>::localToGlobalCarrierId
00263 (
00264     const label phaseI,
00265     const label id
00266 ) const
00267 {
00268     label gid = phaseProps_[phaseI].globalCarrierIds()[id];
00269 
00270     if (gid < 0)
00271     {
00272         FatalErrorIn
00273         (
00274             "Foam::label "
00275             "Foam::CompositionModel<CloudType>::localToGlobalCarrierId"
00276             "("
00277                 "const label, "
00278                 "const label"
00279             ") const"
00280         )   << "Unable to determine global carrier id for phase "
00281             << phaseI << " with local id " << id
00282             << nl << abort(FatalError);
00283     }
00284 
00285     return gid;
00286 }
00287 
00288 
00289 template<class CloudType>
00290 const Foam::scalarField& Foam::CompositionModel<CloudType>::Y0
00291 (
00292     const label phaseI
00293 ) const
00294 {
00295     return phaseProps_[phaseI].Y();
00296 }
00297 
00298 
00299 template<class CloudType>
00300 Foam::scalarField Foam::CompositionModel<CloudType>::X
00301 (
00302     const label phaseI,
00303     const scalarField& Y
00304 ) const
00305 {
00306     const phaseProperties& props = phaseProps_[phaseI];
00307     scalarField X(Y.size(), 0.0);
00308     scalar WInv = 0.0;
00309     switch (props.phase())
00310     {
00311         case phaseProperties::GAS:
00312         {
00313             forAll(Y, i)
00314             {
00315                 label gid = props.globalIds()[i];
00316                 WInv += Y[i]/mcCarrierThermo_.speciesData()[gid].W();
00317                 X[i] = Y[i]/mcCarrierThermo_.speciesData()[gid].W();
00318             }
00319             break;
00320         }
00321         case phaseProperties::LIQUID:
00322         {
00323             forAll(Y, i)
00324             {
00325                 label gid = props.globalIds()[i];
00326                 WInv += Y[i]/this->liquids().properties()[gid].W();
00327                 X[i] += Y[i]/this->liquids().properties()[gid].W();
00328             }
00329             break;
00330         }
00331         default:
00332         {
00333             FatalErrorIn
00334             (
00335                 "Foam::scalarField Foam::CompositionModel<CloudType>::X"
00336                 "("
00337                     "const label, "
00338                     "const scalarField&"
00339                 ") const"
00340             )   << "Only possible to convert gas and liquid mass fractions"
00341                 << nl << abort(FatalError);
00342         }
00343     }
00344 
00345     return X/WInv;
00346 }
00347 
00348 
00349 template<class CloudType>
00350 Foam::scalar Foam::CompositionModel<CloudType>::H
00351 (
00352     const label phaseI,
00353     const scalarField& Y,
00354     const scalar p,
00355     const scalar T
00356 ) const
00357 {
00358     const phaseProperties& props = phaseProps_[phaseI];
00359     scalar HMixture = 0.0;
00360     switch (props.phase())
00361     {
00362         case phaseProperties::GAS:
00363         {
00364             forAll(Y, i)
00365             {
00366                 label gid = props.globalIds()[i];
00367                 HMixture += Y[i]*mcCarrierThermo_.speciesData()[gid].H(T);
00368             }
00369             break;
00370         }
00371         case phaseProperties::LIQUID:
00372         {
00373             forAll(Y, i)
00374             {
00375                 label gid = props.globalIds()[i];
00376                 HMixture += Y[i]*this->liquids().properties()[gid].h(p, T);
00377             }
00378             break;
00379         }
00380         case phaseProperties::SOLID:
00381         {
00382             forAll(Y, i)
00383             {
00384                 label gid = props.globalIds()[i];
00385                 HMixture +=
00386                      Y[i]
00387                     *(
00388                         this->solids().properties()[gid].Hf()
00389                       + this->solids().properties()[gid].cp()*T
00390                      );
00391             }
00392             break;
00393         }
00394         default:
00395         {
00396             FatalErrorIn
00397             (
00398                 "Foam::scalar Foam::CompositionModel<CloudType>::H"
00399                 "("
00400                 "    const label, "
00401                 "    const scalarField&, "
00402                 "    const scalar, "
00403                 "    const scalar"
00404                 ") const"
00405             )   << "Unknown phase enumeration" << nl << abort(FatalError);
00406         }
00407     }
00408 
00409     return HMixture;
00410 }
00411 
00412 
00413 template<class CloudType>
00414 Foam::scalar Foam::CompositionModel<CloudType>::cp
00415 (
00416     const label phaseI,
00417     const scalarField& Y,
00418     const scalar p,
00419     const scalar T
00420 ) const
00421 {
00422     const phaseProperties& props = phaseProps_[phaseI];
00423     scalar cpMixture = 0.0;
00424     switch (props.phase())
00425     {
00426         case phaseProperties::GAS:
00427         {
00428             forAll(Y, i)
00429             {
00430                 label gid = props.globalIds()[i];
00431                 cpMixture += Y[i]*mcCarrierThermo_.speciesData()[gid].Cp(T);
00432             }
00433             break;
00434         }
00435         case phaseProperties::LIQUID:
00436         {
00437             forAll(Y, i)
00438             {
00439                 label gid = props.globalIds()[i];
00440                 cpMixture += Y[i]*this->liquids().properties()[gid].cp(p, T);
00441             }
00442             break;
00443         }
00444         case phaseProperties::SOLID:
00445         {
00446             forAll(Y, i)
00447             {
00448                 label gid = props.globalIds()[i];
00449                 cpMixture += Y[i]*this->solids().properties()[gid].cp();
00450             }
00451             break;
00452         }
00453         default:
00454         {
00455             FatalErrorIn
00456             (
00457                 "Foam::scalar Foam::CompositionModel<CloudType>::cp"
00458                 "("
00459                     "const label, "
00460                     "const scalarField&, "
00461                     "const scalar, "
00462                     "const scalar"
00463                 ") const"
00464             )   << "Unknown phase enumeration" << nl << abort(FatalError);
00465         }
00466     }
00467 
00468     return cpMixture;
00469 }
00470 
00471 
00472 template<class CloudType>
00473 Foam::scalar Foam::CompositionModel<CloudType>::L
00474 (
00475     const label phaseI,
00476     const scalarField& Y,
00477     const scalar p,
00478     const scalar T
00479 ) const
00480 {
00481     const phaseProperties& props = phaseProps_[phaseI];
00482     scalar LMixture = 0.0;
00483     switch (props.phase())
00484     {
00485         case phaseProperties::GAS:
00486         {
00487             if (debug)
00488             {
00489                 WarningIn
00490                 (
00491                     "Foam::scalar Foam::CompositionModel<CloudType>::L"
00492                     "("
00493                         "const label, "
00494                         "const scalarField&, "
00495                         "const scalar, "
00496                         "const scalar"
00497                     ") const\n"
00498                 )   << "No support for gaseous components" << endl;
00499             }
00500             break;
00501         }
00502         case phaseProperties::LIQUID:
00503         {
00504             forAll(Y, i)
00505             {
00506                 label gid = props.globalIds()[i];
00507                 LMixture += Y[i]*this->liquids().properties()[gid].hl(p, T);
00508             }
00509             break;
00510         }
00511         case phaseProperties::SOLID:
00512         {
00513             if (debug)
00514             {
00515                 WarningIn
00516                 (
00517                     "Foam::scalar Foam::CompositionModel<CloudType>::L"
00518                     "("
00519                         "const label, "
00520                         "const scalarField&, "
00521                         "const scalar, "
00522                         "const scalar"
00523                     ") const\n"
00524                 )   << "No support for solid components" << endl;
00525             }
00526             break;
00527         }
00528         default:
00529         {
00530             FatalErrorIn
00531             (
00532                 "Foam::scalar Foam::CompositionModel<CloudType>::L"
00533                 "("
00534                     "const label, "
00535                     "const scalarField&, "
00536                     "const scalar, "
00537                     "const scalar"
00538                 ") const"
00539             )   << "Unknown phase enumeration" << nl << abort(FatalError);
00540         }
00541     }
00542 
00543     return LMixture;
00544 }
00545 
00546 
00547 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00548 
00549 #include "NewCompositionModel.C"
00550 
00551 // ************************************************************************* //
00552 
Copyright © 2000-2009 OpenCFD Ltd