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 
192 :
193  phase_(pp.phase_),
194  stateLabel_(pp.stateLabel_),
195  names_(pp.names_),
196  Y_(pp.Y_),
197  carrierIds_(pp.carrierIds_)
198 {}
199 
200 
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202 
203 void Foam::phaseProperties::reorder
204 (
205  const wordList& gasNames,
206  const wordList& liquidNames,
207  const wordList& solidNames
208 )
209 {
210  // Determine the addressing to map between species listed in the phase
211  // with those given in the (main) thermo properties
212  switch (phase_)
213  {
214  case GAS:
215  {
216  // The list of gaseous species in the mixture may be a sub-set of
217  // the gaseous species in the carrier phase
218  setCarrierIds(gasNames);
219  break;
220  }
221  case LIQUID:
222  {
223  // Set the list of liquid species to correspond to the complete list
224  // defined in the thermodynamics package.
225  reorder(liquidNames);
226  // Set the ids of the corresponding species in the carrier phase
227  setCarrierIds(gasNames);
228  break;
229  }
230  case SOLID:
231  {
232  // Set the list of solid species to correspond to the complete list
233  // defined in the thermodynamics package.
235  // Assume there is no correspondence between the solid species and
236  // the species in the carrier phase (no sublimation).
237  break;
238  }
239  default:
240  {
242  << "Invalid phase: " << phaseTypeNames[phase_] << nl
243  << " phase must be gas, liquid or solid" << nl
244  << exit(FatalError);
245  break;
246  }
247  }
248 }
249 
250 
252 {
253  return phase_;
254 }
255 
256 
258 {
259  return stateLabel_;
260 }
261 
262 
264 {
265  return phaseTypeNames[phase_];
266 }
267 
268 
270 {
271  return names_;
272 }
273 
274 
275 const Foam::word& Foam::phaseProperties::name(const label speciei) const
276 {
277  if (speciei >= names_.size())
278  {
280  << "Requested specie " << speciei << "out of range" << nl
281  << "Available phase species:" << nl << names_ << nl
282  << exit(FatalError);
283  }
284 
285  return names_[speciei];
286 }
287 
288 
290 {
291  return Y_;
292 }
293 
294 
295 Foam::scalar& Foam::phaseProperties::Y(const label speciei)
296 {
297  if (speciei >= Y_.size())
298  {
300  << "Requested specie " << speciei << "out of range" << nl
301  << "Available phase species:" << nl << names_ << nl
302  << exit(FatalError);
303  }
304 
305  return Y_[speciei];
306 }
307 
308 
310 {
311  return carrierIds_;
312 }
313 
314 
316 {
317  return names_.find(specieName);
318 }
319 
320 
321 // ************************************************************************* //
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:51
Foam::phaseProperties::phaseTypeNames
static const Enum< phaseType > phaseTypeNames
Corresponding word representations for phase type enumerations.
Definition: phaseProperties.H:78
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:263
Foam::phaseProperties
Helper class to manage multi-specie phase properties.
Definition: phaseProperties.H:62
Foam::phaseProperties::id
label id(const word &specieName) const
Return the id of a specie in the local list by name.
Definition: phaseProperties.C:315
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::phaseProperties::carrierIds
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
Definition: phaseProperties.C:309
Foam::phaseProperties::names
const List< word > & names() const
Return the list of specie names.
Definition: phaseProperties.C:269
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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::phaseProperties::phaseProperties
phaseProperties()
Null constructor.
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:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::phaseProperties::phaseType
phaseType
Phase type enumeration.
Definition: phaseProperties.H:69
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:257
Foam::phaseProperties::phase
phaseType phase() const
Return const access to the phase type.
Definition: phaseProperties.C:251
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:275
Foam::phaseProperties::Y
const scalarField & Y() const
Return const access to all specie mass fractions.
Definition: phaseProperties.C:289