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

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