CompositionModel.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) 2011-2015 OpenFOAM Foundation
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 "CompositionModel.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class CloudType>
32 :
34  thermo_(owner.thermo()),
35  phaseProps_()
36 {}
37 
38 
39 template<class CloudType>
41 (
42  const dictionary& dict,
43  CloudType& owner,
44  const word& type
45 )
46 :
47  CloudSubModelBase<CloudType>(owner, dict, typeName, type),
48  thermo_(owner.thermo()),
49  phaseProps_
50  (
51  this->coeffDict().lookup("phases"),
52  thermo_.carrier().species(),
53  thermo_.liquids().components(),
54  thermo_.solids().components()
55  )
56 {}
57 
58 
59 template<class CloudType>
61 (
63 )
64 :
66  thermo_(cm.thermo_),
67  phaseProps_(cm.phaseProps_)
68 {}
69 
70 
71 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
72 
73 template<class CloudType>
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
80 template<class CloudType>
82 {
83  return thermo_;
84 }
85 
86 
87 template<class CloudType>
90 {
91  return thermo_.carrier();
92 }
93 
94 
95 template<class CloudType>
98 {
99  return thermo_.liquids();
100 }
101 
102 
103 template<class CloudType>
106 {
107  return thermo_.solids();
108 }
109 
110 
111 template<class CloudType>
114 {
115  return phaseProps_;
116 }
117 
118 
119 template<class CloudType>
121 {
122  return phaseProps_.size();
123 }
124 
125 
126 template<class CloudType>
128 {
129  // if only 1 phase, return the constituent component names
130  if (phaseProps_.size() == 1)
131  {
132  return phaseProps_[0].names();
133  }
134  else
135  {
136  return phaseProps_.phaseTypes();
137  }
138 }
139 
140 
141 template<class CloudType>
143 {
144  return phaseProps_.stateLabels();
145 }
146 
147 
148 template<class CloudType>
149 const Foam::wordList&
151 {
152  return phaseProps_[phasei].names();
153 }
154 
155 
156 template<class CloudType>
158 (
159  const word& cmptName,
160  const bool allowNotFound
161 ) const
162 {
163  label id = thermo_.carrierId(cmptName);
164 
165  if (id < 0 && !allowNotFound)
166  {
168  << "Unable to determine global id for requested component "
169  << cmptName << ". Available components are " << nl
170  << thermo_.carrier().species()
171  << abort(FatalError);
172  }
173 
174  return id;
175 }
176 
177 
178 template<class CloudType>
180 (
181  const label phasei,
182  const word& cmptName,
183  const bool allowNotFound
184 ) const
185 {
186  label id = phaseProps_[phasei].id(cmptName);
187 
188  if (id < 0 && !allowNotFound)
189  {
191  << "Unable to determine local id for component " << cmptName
192  << abort(FatalError);
193  }
194 
195  return id;
196 }
197 
198 
199 template<class CloudType>
201 (
202  const label phasei,
203  const label id,
204  const bool allowNotFound
205 ) const
206 {
207  label cid = phaseProps_[phasei].carrierIds()[id];
208 
209  if (cid < 0 && !allowNotFound)
210  {
212  << "Unable to determine global carrier id for phase "
213  << phasei << " with local id " << id
214  << abort(FatalError);
215  }
216 
217  return cid;
218 }
219 
220 
221 template<class CloudType>
223 (
224  const label phasei
225 ) const
226 {
227  return phaseProps_[phasei].Y();
228 }
229 
230 
231 template<class CloudType>
233 (
234  const label phasei,
235  const scalarField& Y
236 ) const
237 {
238  const phaseProperties& props = phaseProps_[phasei];
239  scalarField X(Y.size());
240  scalar WInv = 0.0;
241  switch (props.phase())
242  {
243  case phaseProperties::GAS:
244  {
245  forAll(Y, i)
246  {
247  label cid = props.carrierIds()[i];
248  X[i] = Y[i]/thermo_.carrier().W(cid);
249  WInv += X[i];
250  }
251  break;
252  }
253  case phaseProperties::LIQUID:
254  {
255  forAll(Y, i)
256  {
257  X[i] = Y[i]/thermo_.liquids().properties()[i].W();
258  WInv += X[i];
259  }
260  break;
261  }
262  default:
263  {
265  << "Only possible to convert gas and liquid mass fractions"
266  << abort(FatalError);
267  }
268  }
269 
270  tmp<scalarField> tfld = X/(WInv + ROOTVSMALL);
271  return tfld;
272 }
273 
274 
275 template<class CloudType>
277 (
278  const label phasei,
279  const scalarField& Y,
280  const scalar p,
281  const scalar T
282 ) const
283 {
284  const phaseProperties& props = phaseProps_[phasei];
285  scalar HMixture = 0.0;
286  switch (props.phase())
287  {
288  case phaseProperties::GAS:
289  {
290  forAll(Y, i)
291  {
292  label cid = props.carrierIds()[i];
293  HMixture += Y[i]*thermo_.carrier().Ha(cid, p, T);
294  }
295  break;
296  }
297  case phaseProperties::LIQUID:
298  {
299  forAll(Y, i)
300  {
301  HMixture += Y[i]*thermo_.liquids().properties()[i].h(p, T);
302  }
303  break;
304  }
305  case phaseProperties::SOLID:
306  {
307  forAll(Y, i)
308  {
309  HMixture +=
310  Y[i]
311  *(
312  thermo_.solids().properties()[i].Hf()
313  + thermo_.solids().properties()[i].Cp()*T
314  );
315  }
316  break;
317  }
318  default:
319  {
321  << "Unknown phase enumeration" << abort(FatalError);
322  }
323  }
324 
325  return HMixture;
326 }
327 
328 
329 template<class CloudType>
331 (
332  const label phasei,
333  const scalarField& Y,
334  const scalar p,
335  const scalar T
336 ) const
337 {
338  const phaseProperties& props = phaseProps_[phasei];
339  scalar HsMixture = 0.0;
340  switch (props.phase())
341  {
342  case phaseProperties::GAS:
343  {
344  forAll(Y, i)
345  {
346  label cid = props.carrierIds()[i];
347  HsMixture += Y[i]*thermo_.carrier().Hs(cid, p, T);
348  }
349  break;
350  }
351  case phaseProperties::LIQUID:
352  {
353  forAll(Y, i)
354  {
355  HsMixture +=
356  Y[i]
357  *(
358  thermo_.liquids().properties()[i].h(p, T)
359  - thermo_.liquids().properties()[i].h(p, 298.15)
360  );
361  }
362  break;
363  }
364  case phaseProperties::SOLID:
365  {
366  forAll(Y, i)
367  {
368  HsMixture += Y[i]*thermo_.solids().properties()[i].Cp()*T;
369  }
370  break;
371  }
372  default:
373  {
375  << "Unknown phase enumeration"
376  << abort(FatalError);
377  }
378  }
379 
380  return HsMixture;
381 }
382 
383 
384 template<class CloudType>
386 (
387  const label phasei,
388  const scalarField& Y,
389  const scalar p,
390  const scalar T
391 ) const
392 {
393  const phaseProperties& props = phaseProps_[phasei];
394  scalar HcMixture = 0.0;
395  switch (props.phase())
396  {
397  case phaseProperties::GAS:
398  {
399  forAll(Y, i)
400  {
401  label cid = props.carrierIds()[i];
402  HcMixture += Y[i]*thermo_.carrier().Hc(cid);
403  }
404  break;
405  }
406  case phaseProperties::LIQUID:
407  {
408  forAll(Y, i)
409  {
410  HcMixture +=
411  Y[i]*thermo_.liquids().properties()[i].h(p, 298.15);
412  }
413  break;
414  }
415  case phaseProperties::SOLID:
416  {
417  forAll(Y, i)
418  {
419  HcMixture += Y[i]*thermo_.solids().properties()[i].Hf();
420  }
421  break;
422  }
423  default:
424  {
426  << "Unknown phase enumeration"
427  << abort(FatalError);
428  }
429  }
430 
431  return HcMixture;
432 }
433 
434 
435 template<class CloudType>
437 (
438  const label phasei,
439  const scalarField& Y,
440  const scalar p,
441  const scalar T
442 ) const
443 {
444  const phaseProperties& props = phaseProps_[phasei];
445  scalar CpMixture = 0.0;
446  switch (props.phase())
447  {
448  case phaseProperties::GAS:
449  {
450  forAll(Y, i)
451  {
452  label cid = props.carrierIds()[i];
453  CpMixture += Y[i]*thermo_.carrier().Cp(cid, p, T);
454  }
455  break;
456  }
457  case phaseProperties::LIQUID:
458  {
459  forAll(Y, i)
460  {
461  CpMixture += Y[i]*thermo_.liquids().properties()[i].Cp(p, T);
462  }
463  break;
464  }
465  case phaseProperties::SOLID:
466  {
467  forAll(Y, i)
468  {
469  CpMixture += Y[i]*thermo_.solids().properties()[i].Cp();
470  }
471  break;
472  }
473  default:
474  {
476  << "Unknown phase enumeration"
477  << abort(FatalError);
478  }
479  }
480 
481  return CpMixture;
482 }
483 
484 
485 template<class CloudType>
487 (
488  const label phasei,
489  const scalarField& Y,
490  const scalar p,
491  const scalar T
492 ) const
493 {
494  const phaseProperties& props = phaseProps_[phasei];
495  scalar LMixture = 0.0;
496  switch (props.phase())
497  {
498  case phaseProperties::GAS:
499  {
500  if (debug)
501  {
503  << "No support for gaseous components" << endl;
504  }
505  break;
506  }
507  case phaseProperties::LIQUID:
508  {
509  forAll(Y, i)
510  {
511  LMixture += Y[i]*thermo_.liquids().properties()[i].hl(p, T);
512  }
513  break;
514  }
515  case phaseProperties::SOLID:
516  {
517  if (debug)
518  {
520  << "No support for solid components" << endl;
521  }
522  break;
523  }
524  default:
525  {
527  << "Unknown phase enumeration"
528  << abort(FatalError);
529  }
530  }
531 
532  return LMixture;
533 }
534 
535 
536 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
537 
538 #include "CompositionModelNew.C"
539 
540 // ************************************************************************* //
Foam::CompositionModel::Cp
virtual scalar Cp(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return specific heat caoacity for the phase phaseI.
Definition: CompositionModel.C:437
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::CompositionModel::H
virtual scalar H(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return total enthalpy for the phase phaseI.
Definition: CompositionModel.C:277
Foam::basicSpecieMixture
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
Definition: basicSpecieMixture.H:49
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::SLGThermo
Thermo package for (S)olids (L)iquids and (G)ases Takes reference to thermo package,...
Definition: SLGThermo.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::CompositionModel::thermo_
const SLGThermo & thermo_
Reference to the thermo database.
Definition: CompositionModel.H:67
Foam::CompositionModel::localId
label localId(const label phaseI, const word &cmptName, const bool allowNotFound=false) const
Return local id of component cmptName in phase phaseI.
Definition: CompositionModel.C:180
Foam::CompositionModel::localToCarrierId
label localToCarrierId(const label phaseI, const label id, const bool allowNotFound=false) const
Return carrier id of component given local id.
Definition: CompositionModel.C:201
Foam::phaseProperties
Helper class to manage multi-specie phase properties.
Definition: phaseProperties.H:52
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::CloudSubModelBase
Base class for cloud sub-models.
Definition: CloudSubModelBase.H:49
Foam::solidMixtureProperties
A mixture of solids.
Definition: solidMixtureProperties.H:74
Foam::phasePropertiesList
Simple container for a list of phase properties.
Definition: phasePropertiesList.H:51
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::CompositionModel::Hs
virtual scalar Hs(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return sensible enthalpy for the phase phaseI.
Definition: CompositionModel.C:331
Foam::phaseProperties::carrierIds
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
Definition: phaseProperties.C:319
Foam::CompositionModel::Hc
virtual scalar Hc(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return chemical enthalpy for the phase phaseI.
Definition: CompositionModel.C:386
Foam::CompositionModel< CloudType >
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:59
Foam::CompositionModel::phaseProps
const phasePropertiesList & phaseProps() const
Return the list of phase properties.
Definition: CompositionModel.C:113
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::CompositionModel::Y0
const scalarField & Y0(const label phaseI) const
Return the list of phase phaseI mass fractions.
Definition: CompositionModel.C:223
Foam::CompositionModel::X
tmp< scalarField > X(const label phaseI, const scalarField &Y) const
Return the list of phase phaseI volume fractions fractions.
Definition: CompositionModel.C:233
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::CompositionModel::phaseProps_
phasePropertiesList phaseProps_
List of phase properties.
Definition: CompositionModel.H:70
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
Foam::CompositionModel::liquids
const liquidMixtureProperties & liquids() const
Return the global (additional) liquids.
Definition: CompositionModel.C:97
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::CompositionModel::carrier
const basicSpecieMixture & carrier() const
Return the carrier components (wrapper function)
Definition: CompositionModel.C:89
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::CompositionModel::CompositionModel
CompositionModel(CloudType &owner)
Construct null from owner.
Definition: CompositionModel.C:31
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::CompositionModel::componentNames
const wordList & componentNames(const label phaseI) const
Return the list of component names for phaseI.
Definition: CompositionModel.C:150
Foam::CompositionModel::solids
const solidMixtureProperties & solids() const
Return the global (additional) solids.
Definition: CompositionModel.C:105
Foam::CompositionModel::nPhase
label nPhase() const
Return the number of phases.
Definition: CompositionModel.C:120
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
T
const volScalarField & T
Definition: createFields.H:25
Foam::liquidMixtureProperties
A mixture of liquids.
Definition: liquidMixtureProperties.H:74
phasei
label phasei
Definition: pEqn.H:37
Foam::CompositionModel::thermo
const SLGThermo & thermo() const
Return the thermo database.
Definition: CompositionModel.C:81
Foam::CompositionModel::~CompositionModel
virtual ~CompositionModel()
Destructor.
Definition: CompositionModel.C:74
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
CompositionModel.H
Foam::CompositionModel::phaseTypes
const wordList & phaseTypes() const
Return the list of phase type names.
Definition: CompositionModel.C:127
CompositionModelNew.C
Foam::CompositionModel::carrierId
label carrierId(const word &cmptName, const bool allowNotFound=false) const
Return global id of component cmptName in carrier thermo.
Definition: CompositionModel.C:158
Foam::CompositionModel::L
virtual scalar L(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return latent heat for the phase phaseI.
Definition: CompositionModel.C:487
Foam::phaseProperties::phase
phaseType phase() const
Return const access to the phase type.
Definition: phaseProperties.C:261
Foam::CompositionModel::stateLabels
const wordList & stateLabels() const
Return the list of state labels (s), (l), (g) etc.
Definition: CompositionModel.C:142
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Y
PtrList< volScalarField > & Y
Definition: createFields.H:36
lookup
stressControl lookup("compactNormalStress") >> compactNormalStress