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

phaseProperties.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 "phaseProperties.H"
00027 
00028 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00029 
00030 template<>
00031 const char* Foam::NamedEnum<Foam::phaseProperties::phaseType, 4>::names[] =
00032 {
00033     "gas",
00034     "liquid",
00035     "solid",
00036     "unknown"
00037 };
00038 
00039 
00040 const Foam::NamedEnum<Foam::phaseProperties::phaseType, 4>
00041     Foam::phaseProperties::phaseTypeNames_;
00042 
00043 
00044 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00045 
00046 void Foam::phaseProperties::setGlobalIds(const wordList& globalNames)
00047 {
00048     forAll(names_, i)
00049     {
00050         forAll(globalNames, j)
00051         {
00052             if (globalNames[j] == names_[i])
00053             {
00054                 globalIds_[i] = j;
00055                 break;
00056             }
00057         }
00058         if (globalIds_[i] == -1)
00059         {
00060             FatalErrorIn
00061             (
00062                 "void Foam::phaseProperties::setGlobalIds(const wordList&)"
00063             )   << "Could not find specie " << names_[i]
00064                 << " in species list" <<  nl
00065                 << "Available species are: " << nl << globalNames << nl
00066                 << exit(FatalError);
00067         }
00068     }
00069 }
00070 
00071 
00072 void Foam::phaseProperties::setGlobalCarrierIds
00073 (
00074     const wordList& carrierNames
00075 )
00076 {
00077     globalCarrierIds_ = -1;
00078 
00079     forAll(names_, i)
00080     {
00081         forAll (carrierNames, j)
00082         {
00083             if (carrierNames[j] == names_[i])
00084             {
00085                 globalCarrierIds_[i] = j;
00086                 break;
00087             }
00088         }
00089         if (globalCarrierIds_[i] == -1)
00090         {
00091             FatalErrorIn
00092             (
00093                 "void Foam::phaseProperties::setGlobalCarrierIds"
00094                 "("
00095                     "const wordList&"
00096                 ")"
00097             )   << "Could not find carrier specie " << names_[i]
00098                 << " in species list" <<  nl
00099                 << "Available species are: " << nl << carrierNames << nl
00100                 << exit(FatalError);
00101         }
00102     }
00103 }
00104 
00105 
00106 void Foam::phaseProperties::checkTotalMassFraction() const
00107 {
00108     scalar total = 0.0;
00109     forAll(Y_, cmptI)
00110     {
00111         total += Y_[cmptI];
00112     }
00113 
00114     if (Y_.size() != 0 && mag(total - 1.0) > SMALL)
00115     {
00116         FatalErrorIn
00117         (
00118             "void Foam::phaseProperties::checkTotalMassFraction() const"
00119         )   << "Component fractions must total to unity for phase "
00120             << phaseTypeNames_[phase_] << nl
00121             << "Components: " << nl << names_ << nl << exit(FatalError);
00122     }
00123 }
00124 
00125 
00126 Foam::word Foam::phaseProperties::phaseToStateLabel(const phaseType pt) const
00127 {
00128     word state = "(unknown)";
00129     switch (pt)
00130     {
00131         case GAS:
00132         {
00133             state = "(g)";
00134             break;
00135         }
00136         case LIQUID:
00137         {
00138             state = "(l)";
00139             break;
00140         }
00141         case SOLID:
00142         {
00143             state = "(s)";
00144             break;
00145         }
00146         default:
00147         {
00148             FatalErrorIn
00149             (
00150                 "Foam::phaseProperties::phaseToStateLabel(phaseType pt)"
00151             )   << "Invalid phase: " << phaseTypeNames_[pt] << nl
00152                 << "    phase must be gas, liquid or solid" << nl
00153                 << exit(FatalError);
00154         }
00155     }
00156 
00157     return state;
00158 }
00159 
00160 
00161 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00162 
00163 Foam::phaseProperties::phaseProperties()
00164 :
00165     phase_(UNKNOWN),
00166     stateLabel_("(unknown)"),
00167     names_(0),
00168     Y_(0),
00169     globalIds_(0),
00170     globalCarrierIds_(0)
00171 {}
00172 
00173 
00174 Foam::phaseProperties::phaseProperties(const phaseProperties& pp)
00175 :
00176     phase_(pp.phase_),
00177     stateLabel_(pp.stateLabel_),
00178     names_(pp.names_),
00179     Y_(pp.Y_),
00180     globalIds_(pp.globalIds_),
00181     globalCarrierIds_(pp.globalCarrierIds_)
00182 {}
00183 
00184 
00185 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00186 
00187 Foam::phaseProperties::~phaseProperties()
00188 {}
00189 
00190 
00191 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00192 
00193 void Foam::phaseProperties::initialiseGlobalIds
00194 (
00195     const wordList& gasNames,
00196     const wordList& liquidNames,
00197     const wordList& solidNames
00198 )
00199 {
00200     // determine the addressing to map between components listed in the phase
00201     // with those given in the (main) thermo properties
00202     switch (phase_)
00203     {
00204         case GAS:
00205         {
00206             setGlobalIds(gasNames);
00207             forAll(globalCarrierIds_, i)
00208             {
00209                 globalCarrierIds_[i] = globalIds_[i];
00210             }
00211             break;
00212         }
00213         case LIQUID:
00214         {
00215             setGlobalIds(liquidNames);
00216             setGlobalCarrierIds(gasNames);
00217             break;
00218         }
00219         case SOLID:
00220         {
00221             setGlobalIds(solidNames);
00222             WarningIn
00223             (
00224                 "phaseProperties::initialiseGlobalIds(...)"
00225             )   << "Assuming no mapping between solid and carrier species"
00226                 << endl;
00227 //            setGlobalCarrierIds(gasNames);
00228             break;
00229         }
00230         default:
00231         {
00232             FatalErrorIn
00233             (
00234                 "Foam::phaseProperties::setGlobalIds"
00235                 "("
00236                     "const PtrList<volScalarField>&, "
00237                     "const wordList&, "
00238                     "const wordList&"
00239                 ")"
00240             )   << "Invalid phase: " << phaseTypeNames_[phase_] << nl
00241                 << "    phase must be gas, liquid or solid" << nl
00242                 << exit(FatalError);
00243         }
00244     }
00245 }
00246 
00247 
00248 Foam::phaseProperties::phaseType Foam::phaseProperties::phase() const
00249 {
00250     return phase_;
00251 }
00252 
00253 
00254 const Foam::word& Foam::phaseProperties::stateLabel() const
00255 {
00256     return stateLabel_;
00257 }
00258 
00259 
00260 Foam::word Foam::phaseProperties::phaseTypeName() const
00261 {
00262     return phaseTypeNames_[phase_];
00263 }
00264 
00265 
00266 const Foam::List<Foam::word>& Foam::phaseProperties::names() const
00267 {
00268     return names_;
00269 }
00270 
00271 
00272 const Foam::word& Foam::phaseProperties::name(const label cmptI) const
00273 {
00274     if (cmptI >= names_.size())
00275     {
00276         FatalErrorIn
00277         (
00278             "const Foam::word& Foam::phaseProperties::name"
00279             "("
00280                 "const label"
00281             ") const"
00282         )   << "Requested component " << cmptI << "out of range" << nl
00283             << "Available phase components:" << nl << names_ << nl
00284             << exit(FatalError);
00285     }
00286 
00287     return names_[cmptI];
00288 }
00289 
00290 
00291 const Foam::scalarField& Foam::phaseProperties::Y() const
00292 {
00293     return Y_;
00294 }
00295 
00296 
00297 Foam::scalar& Foam::phaseProperties::Y(const label cmptI)
00298 {
00299     if (cmptI >= Y_.size())
00300     {
00301         FatalErrorIn
00302         (
00303             "const Foam::scalar& Foam::phaseProperties::Y"
00304             "("
00305                 "const label"
00306             ") const"
00307         )   << "Requested component " << cmptI << "out of range" << nl
00308             << "Available phase components:" << nl << names_ << nl
00309             << exit(FatalError);
00310     }
00311 
00312     return Y_[cmptI];
00313 }
00314 
00315 
00316 Foam::label Foam::phaseProperties::globalId(const word& cmptName) const
00317 {
00318     label id = this->id(cmptName);
00319 
00320     if (id < 0)
00321     {
00322         return id;
00323     }
00324     else
00325     {
00326         return globalIds_[id];
00327     }
00328 
00329 }
00330 
00331 
00332 const Foam::labelList& Foam::phaseProperties::globalIds() const
00333 {
00334     return globalIds_;
00335 }
00336 
00337 
00338 const Foam::labelList& Foam::phaseProperties::globalCarrierIds() const
00339 {
00340     return globalCarrierIds_;
00341 }
00342 
00343 
00344 Foam::label Foam::phaseProperties::id(const word& cmptName) const
00345 {
00346     forAll(names_, cmptI)
00347     {
00348         if (names_[cmptI] == cmptName)
00349         {
00350             return cmptI;
00351         }
00352     }
00353 
00354     return -1;
00355 }
00356 
00357 
00358 // ************************ vim: set sw=4 sts=4 et: ************************ //
00359 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines