FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 2008-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "phaseProperties.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 template<>
32 {
33  "gas",
34  "liquid",
35  "solid",
36  "unknown"
37 };
38 
39 
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::phaseProperties::setGlobalIds(const wordList& globalNames)
47 {
48  forAll(names_, i)
49  {
50  forAll(globalNames, j)
51  {
52  if (globalNames[j] == names_[i])
53  {
54  globalIds_[i] = j;
55  break;
56  }
57  }
58  if (globalIds_[i] == -1)
59  {
61  (
62  "void Foam::phaseProperties::setGlobalIds(const wordList&)"
63  ) << "Could not find specie " << names_[i]
64  << " in species list" << nl
65  << "Available species are: " << nl << globalNames << nl
66  << exit(FatalError);
67  }
68  }
69 }
70 
71 
72 void Foam::phaseProperties::setGlobalCarrierIds
73 (
74  const wordList& carrierNames
75 )
76 {
77  globalCarrierIds_ = -1;
78 
79  forAll(names_, i)
80  {
81  forAll (carrierNames, j)
82  {
83  if (carrierNames[j] == names_[i])
84  {
85  globalCarrierIds_[i] = j;
86  break;
87  }
88  }
89  if (globalCarrierIds_[i] == -1)
90  {
92  (
93  "void Foam::phaseProperties::setGlobalCarrierIds"
94  "("
95  "const wordList&"
96  ")"
97  ) << "Could not find carrier specie " << names_[i]
98  << " in species list" << nl
99  << "Available species are: " << nl << carrierNames << nl
100  << exit(FatalError);
101  }
102  }
103 }
104 
105 
106 void Foam::phaseProperties::checkTotalMassFraction() const
107 {
108  scalar total = 0.0;
109  forAll(Y_, cmptI)
110  {
111  total += Y_[cmptI];
112  }
113 
114  if (Y_.size() != 0 && mag(total - 1.0) > SMALL)
115  {
117  (
118  "void Foam::phaseProperties::checkTotalMassFraction() const"
119  ) << "Component fractions must total to unity for phase "
120  << phaseTypeNames_[phase_] << nl
121  << "Components: " << nl << names_ << nl << exit(FatalError);
122  }
123 }
124 
125 
126 Foam::word Foam::phaseProperties::phaseToStateLabel(const phaseType pt) const
127 {
128  word state = "(unknown)";
129  switch (pt)
130  {
131  case GAS:
132  {
133  state = "(g)";
134  break;
135  }
136  case LIQUID:
137  {
138  state = "(l)";
139  break;
140  }
141  case SOLID:
142  {
143  state = "(s)";
144  break;
145  }
146  default:
147  {
149  (
150  "Foam::phaseProperties::phaseToStateLabel(phaseType pt)"
151  ) << "Invalid phase: " << phaseTypeNames_[pt] << nl
152  << " phase must be gas, liquid or solid" << nl
153  << exit(FatalError);
154  }
155  }
156 
157  return state;
158 }
159 
160 
161 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
162 
164 :
165  phase_(UNKNOWN),
166  stateLabel_("(unknown)"),
167  names_(0),
168  Y_(0),
169  globalIds_(0),
170  globalCarrierIds_(0)
171 {}
172 
173 
175 :
176  phase_(pp.phase_),
177  stateLabel_(pp.stateLabel_),
178  names_(pp.names_),
179  Y_(pp.Y_),
180  globalIds_(pp.globalIds_),
181  globalCarrierIds_(pp.globalCarrierIds_)
182 {}
183 
184 
185 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
186 
188 {}
189 
190 
191 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 
194 (
195  const wordList& gasNames,
196  const wordList& liquidNames,
197  const wordList& solidNames
198 )
199 {
200  // determine the addressing to map between components listed in the phase
201  // with those given in the (main) thermo properties
202  switch (phase_)
203  {
204  case GAS:
205  {
206  setGlobalIds(gasNames);
207  forAll(globalCarrierIds_, i)
208  {
209  globalCarrierIds_[i] = globalIds_[i];
210  }
211  break;
212  }
213  case LIQUID:
214  {
215  setGlobalIds(liquidNames);
216  setGlobalCarrierIds(gasNames);
217  break;
218  }
219  case SOLID:
220  {
221  setGlobalIds(solidNames);
222  WarningIn
223  (
224  "phaseProperties::initialiseGlobalIds(...)"
225  ) << "Assuming no mapping between solid and carrier species"
226  << endl;
227 // setGlobalCarrierIds(gasNames);
228  break;
229  }
230  default:
231  {
233  (
234  "Foam::phaseProperties::setGlobalIds"
235  "("
236  "const PtrList<volScalarField>&, "
237  "const wordList&, "
238  "const wordList&"
239  ")"
240  ) << "Invalid phase: " << phaseTypeNames_[phase_] << nl
241  << " phase must be gas, liquid or solid" << nl
242  << exit(FatalError);
243  }
244  }
245 }
246 
247 
249 {
250  return phase_;
251 }
252 
253 
255 {
256  return stateLabel_;
257 }
258 
259 
261 {
262  return phaseTypeNames_[phase_];
263 }
264 
265 
267 {
268  return names_;
269 }
270 
271 
272 const Foam::word& Foam::phaseProperties::name(const label cmptI) const
273 {
274  if (cmptI >= names_.size())
275  {
277  (
278  "const Foam::word& Foam::phaseProperties::name"
279  "("
280  "const label"
281  ") const"
282  ) << "Requested component " << cmptI << "out of range" << nl
283  << "Available phase components:" << nl << names_ << nl
284  << exit(FatalError);
285  }
286 
287  return names_[cmptI];
288 }
289 
290 
292 {
293  return Y_;
294 }
295 
296 
297 Foam::scalar& Foam::phaseProperties::Y(const label cmptI)
298 {
299  if (cmptI >= Y_.size())
300  {
302  (
303  "const Foam::scalar& Foam::phaseProperties::Y"
304  "("
305  "const label"
306  ") const"
307  ) << "Requested component " << cmptI << "out of range" << nl
308  << "Available phase components:" << nl << names_ << nl
309  << exit(FatalError);
310  }
311 
312  return Y_[cmptI];
313 }
314 
315 
316 Foam::label Foam::phaseProperties::globalId(const word& cmptName) const
317 {
318  label id = this->id(cmptName);
319 
320  if (id < 0)
321  {
322  return id;
323  }
324  else
325  {
326  return globalIds_[id];
327  }
328 
329 }
330 
331 
333 {
334  return globalIds_;
335 }
336 
337 
339 {
340  return globalCarrierIds_;
341 }
342 
343 
344 Foam::label Foam::phaseProperties::id(const word& cmptName) const
345 {
346  forAll(names_, cmptI)
347  {
348  if (names_[cmptI] == cmptName)
349  {
350  return cmptI;
351  }
352  }
353 
354  return -1;
355 }
356 
357 
358 // ************************ vim: set sw=4 sts=4 et: ************************ //
359