Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
33const 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
48void 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
99void 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
128void 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
147Foam::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 }
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
194void 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
236 break;
237 }
238 }
239}
240
245}
246
249{
250 return stateLabel_;
251}
252
257}
258
261{
262 return names_;
263}
264
265
266const 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
274 }
275
276 return names_[speciei];
277}
278
281{
282 return Y_;
283}
284
285
286Foam::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
294 }
295
296 return Y_[speciei];
297}
298
301{
302 return carrierIds_;
303}
304
305
306Foam::label Foam::phaseProperties::id(const word& specieName) const
307{
308 return names_.find(specieName);
309}
310
311
312// ************************************************************************* //
bool found
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
label find(const T &val) const
Find index of the first occurrence of the value.
Definition UList.C:160
static const Enum< phaseType > phaseTypeNames
Corresponding word representations for phase type enumerations.
const List< word > & names() const
Return the list of specie names.
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
const word & name(const label speciei) const
Return const access to a specie name.
phaseType
Phase type enumeration.
phaseProperties()
Default construct, as 'UNKNOWN' state.
phaseType phase() const
Return const access to the phase type.
const scalarField & Y() const
Return const access to all specie mass fractions.
const word & stateLabel() const
Return const access to the phase state label.
label id(const word &specieName) const
Return the id of a specie in the local list by name.
word phaseTypeName() const
Return word representation of the phase type.
A class for handling words, derived from Foam::string.
Definition word.H:66
const wordList solidNames(rp["solid"])
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define WarningInFunction
Report a warning using Foam::Warning.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
scalarList Y0(nSpecie, Zero)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299