phaseProperties.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "phaseProperties.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const Foam::Enum
33 <
35 >
37 ({
38  { phaseType::GAS, "gas" },
39  { phaseType::LIQUID, "liquid" },
40  { phaseType::SOLID, "solid" },
41  { phaseType::UNKNOWN, "unknown" },
42 });
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 void Foam::phaseProperties::reorder(const wordList& specieNames)
48 {
49  // ***HGW Unfortunately in the current implementation it is assumed that
50  // if no species are specified the phase is not present and this MUST
51  // be checked at the point of use. This needs a rewrite.
52  if (!names_.size())
53  {
54  return;
55  }
56 
57  // Store the current sames and mass-fractions
58  List<word> names0(names_);
59  scalarField Y0(Y_);
60 
61  // Update the specie names to those given
62  names_ = specieNames;
63 
64  // Re-size mass-fractions if necessary, initialize to 0
65  if (names_.size() != names0.size())
66  {
67  Y_.setSize(names_.size());
68  Y_ = 0;
69  }
70 
71  // Set the mass-fraction for each specie in the list to the corresponding
72  // value in the original list
73  forAll(names0, i)
74  {
75  bool found = false;
76  forAll(names_, j)
77  {
78  if (names_[j] == names0[i])
79  {
80  Y_[j] = Y0[i];
81  found = true;
82  break;
83  }
84  }
85 
86  if (!found)
87  {
89  << "Could not find specie " << names0[i]
90  << " in list " << names_
91  << " for phase " << phaseTypeNames[phase_]
92  << exit(FatalError);
93  }
94  }
95 }
96 
97 
98 void Foam::phaseProperties::setCarrierIds
99 (
100  const wordList& carrierNames
101 )
102 {
103  carrierIds_ = -1;
104 
105  forAll(names_, i)
106  {
107  forAll(carrierNames, j)
108  {
109  if (carrierNames[j] == names_[i])
110  {
111  carrierIds_[i] = j;
112  break;
113  }
114  }
115  if (carrierIds_[i] == -1)
116  {
118  << "Could not find carrier specie " << names_[i]
119  << " in species list" << nl
120  << "Available species are: " << nl << carrierNames << nl
121  << exit(FatalError);
122  }
123  }
124 }
125 
126 
127 void Foam::phaseProperties::checkTotalMassFraction() const
128 {
129  scalar total = 0;
130  for (const scalar& val : Y_)
131  {
132  total += val;
133  }
134 
135  if (Y_.size() && mag(total - 1.0) > SMALL)
136  {
138  << "Specie fractions must total to unity for phase "
139  << phaseTypeNames[phase_] << nl
140  << "Species: " << nl << flatOutput(names_) << nl
141  << exit(FatalError);
142  }
143 }
144 
145 
146 Foam::word Foam::phaseProperties::phaseToStateLabel(const phaseType pt) const
147 {
148  switch (pt)
149  {
150  case GAS:
151  {
152  return "(g)";
153  break;
154  }
155  case LIQUID:
156  {
157  return "(l)";
158  break;
159  }
160  case SOLID:
161  {
162  return "(s)";
163  break;
164  }
165  default:
166  {
168  << "Invalid phase: " << phaseTypeNames[pt] << nl
169  << " phase must be gas, liquid or solid" << nl
170  << exit(FatalError);
171  break;
172  }
173  }
174 
175  return "(unknown)";
176 }
177 
178 
179 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
180 
182 :
183  phase_(UNKNOWN),
184  stateLabel_("(unknown)"),
185  names_(),
186  Y_(),
187  carrierIds_()
188 {}
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
193 void Foam::phaseProperties::reorder
194 (
195  const wordList& gasNames,
196  const wordList& liquidNames,
197  const wordList& solidNames
198 )
199 {
200  // Determine the addressing to map between species listed in the phase
201  // with those given in the (main) thermo properties
202  switch (phase_)
203  {
204  case GAS:
205  {
206  // The list of gaseous species in the mixture may be a sub-set of
207  // the gaseous species in the carrier phase
208  setCarrierIds(gasNames);
209  break;
210  }
211  case LIQUID:
212  {
213  // Set the list of liquid species to correspond to the complete list
214  // defined in the thermodynamics package.
215  reorder(liquidNames);
216  // Set the ids of the corresponding species in the carrier phase
217  setCarrierIds(gasNames);
218  break;
219  }
220  case SOLID:
221  {
222  // Set the list of solid species to correspond to the complete list
223  // defined in the thermodynamics package.
225  // Assume there is no correspondence between the solid species and
226  // the species in the carrier phase (no sublimation).
227  break;
228  }
229  default:
230  {
232  << "Invalid phase: " << phaseTypeNames[phase_] << nl
233  << " phase must be gas, liquid or solid" << nl
234  << exit(FatalError);
235  break;
236  }
237  }
238 }
239 
240 
242 {
243  return phase_;
244 }
245 
246 
248 {
249  return stateLabel_;
250 }
251 
252 
254 {
255  return phaseTypeNames[phase_];
256 }
257 
258 
260 {
261  return names_;
262 }
263 
264 
265 const Foam::word& Foam::phaseProperties::name(const label speciei) const
266 {
267  if (speciei >= names_.size())
268  {
270  << "Requested specie " << speciei << "out of range" << nl
271  << "Available phase species:" << nl << names_ << nl
272  << exit(FatalError);
273  }
274 
275  return names_[speciei];
276 }
277 
278 
280 {
281  return Y_;
282 }
283 
284 
285 Foam::scalar& Foam::phaseProperties::Y(const label speciei)
286 {
287  if (speciei >= Y_.size())
288  {
290  << "Requested specie " << speciei << "out of range" << nl
291  << "Available phase species:" << nl << names_ << nl
292  << exit(FatalError);
293  }
294 
295  return Y_[speciei];
296 }
297 
298 
300 {
301  return carrierIds_;
302 }
303 
304 
305 Foam::label Foam::phaseProperties::id(const word& specieName) const
306 {
307  return names_.find(specieName);
308 }
309 
310 
311 // ************************************************************************* //
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::phaseProperties::phaseTypeNames
static const Enum< phaseType > phaseTypeNames
Corresponding word representations for phase type enumerations.
Definition: phaseProperties.H:76
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::phaseProperties::phaseTypeName
word phaseTypeName() const
Return word representation of the phase type.
Definition: phaseProperties.C:253
Foam::phaseProperties::id
label id(const word &specieName) const
Return the id of a specie in the local list by name.
Definition: phaseProperties.C:305
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::phaseProperties::carrierIds
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
Definition: phaseProperties.C:299
Foam::phaseProperties::names
const List< word > & names() const
Return the list of specie names.
Definition: phaseProperties.C:259
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::Field< scalar >
Foam::reorder
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
Definition: ListOpsTemplates.C:80
Foam::FatalError
error FatalError
phaseProperties.H
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:217
Foam::phaseProperties::phaseProperties
phaseProperties()
Default construct, as 'UNKNOWN' state.
Definition: phaseProperties.C:181
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
found
bool found
Definition: TABSMDCalcMethod2.H:32
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::phaseProperties::phaseType
phaseType
Phase type enumeration.
Definition: phaseProperties.H:67
Foam::List< word >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::phaseProperties::stateLabel
const word & stateLabel() const
Return const access to the phase state label.
Definition: phaseProperties.C:247
Foam::phaseProperties::phase
phaseType phase() const
Return const access to the phase type.
Definition: phaseProperties.C:241
Y0
scalarList Y0(nSpecie, Zero)
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
solidNames
const wordList solidNames(rp["solid"])
Foam::phaseProperties::name
const word & name(const label speciei) const
Return const access to a specie name.
Definition: phaseProperties.C:265
Foam::phaseProperties::Y
const scalarField & Y() const
Return const access to all specie mass fractions.
Definition: phaseProperties.C:279