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