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