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