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  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 "CompositionModel.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class CloudType>
35 :
37  thermo_(owner.thermo()),
38  phaseProps_()
39 {}
40 
41 
42 template<class CloudType>
44 (
45  const dictionary& dict,
46  CloudType& owner,
47  const word& type
48 )
49 :
50  CloudSubModelBase<CloudType>(owner, dict, typeName, type),
51  thermo_(owner.thermo()),
52  phaseProps_
53  (
54  this->coeffDict().lookup("phases"),
55  thermo_.carrier().species(),
56  thermo_.liquids().components(),
57  thermo_.solids().components()
58  )
59 {}
60 
61 
62 template<class CloudType>
64 (
66 )
67 :
69  thermo_(cm.thermo_),
70  phaseProps_(cm.phaseProps_)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75 
76 template<class CloudType>
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
83 template<class CloudType>
85 {
86  return thermo_;
87 }
88 
89 
90 template<class CloudType>
93 {
94  return thermo_.carrier();
95 }
96 
97 
98 template<class CloudType>
101 {
102  return thermo_.liquids();
103 }
104 
105 
106 template<class CloudType>
109 {
110  return thermo_.solids();
111 }
112 
113 
114 template<class CloudType>
117 {
118  return phaseProps_;
119 }
120 
121 
122 template<class CloudType>
124 {
125  return phaseProps_.size();
126 }
127 
128 
129 template<class CloudType>
131 {
132  // if only 1 phase, return the constituent component names
133  if (phaseProps_.size() == 1)
134  {
135  return phaseProps_[0].names();
136  }
137  else
138  {
139  return phaseProps_.phaseTypes();
140  }
141 }
142 
143 
144 template<class CloudType>
146 {
147  return phaseProps_.stateLabels();
148 }
149 
150 
151 template<class CloudType>
152 const Foam::wordList&
154 {
155  return phaseProps_[phasei].names();
156 }
157 
158 
159 template<class CloudType>
161 (
162  const word& cmptName,
163  const bool allowNotFound
164 ) const
165 {
166  label id = thermo_.carrierId(cmptName);
167 
168  if (id < 0 && !allowNotFound)
169  {
171  << "Unable to determine global id for requested component "
172  << cmptName << ". Available components are " << nl
173  << thermo_.carrier().species()
174  << abort(FatalError);
175  }
176 
177  return id;
178 }
179 
180 
181 template<class CloudType>
183 (
184  const label phasei,
185  const word& cmptName,
186  const bool allowNotFound
187 ) const
188 {
189  label id = phaseProps_[phasei].id(cmptName);
190 
191  if (id < 0 && !allowNotFound)
192  {
194  << "Unable to determine local id for component " << cmptName
195  << abort(FatalError);
196  }
197 
198  return id;
199 }
200 
201 
202 template<class CloudType>
204 (
205  const label phasei,
206  const label id,
207  const bool allowNotFound
208 ) const
209 {
210  label cid = phaseProps_[phasei].carrierIds()[id];
211 
212  if (cid < 0 && !allowNotFound)
213  {
215  << "Unable to determine global carrier id for phase "
216  << phasei << " with local id " << id
217  << abort(FatalError);
218  }
219 
220  return cid;
221 }
222 
223 
224 template<class CloudType>
226 (
227  const label phasei
228 ) const
229 {
230  return phaseProps_[phasei].Y();
231 }
232 
233 
234 template<class CloudType>
236 (
237  const label phasei,
238  const scalarField& Y
239 ) const
240 {
241  const phaseProperties& props = phaseProps_[phasei];
242  scalarField X(Y.size());
243  scalar WInv = 0.0;
244  switch (props.phase())
245  {
246  case phaseProperties::GAS:
247  {
248  forAll(Y, i)
249  {
250  label cid = props.carrierIds()[i];
251  X[i] = Y[i]/thermo_.carrier().W(cid);
252  WInv += X[i];
253  }
254  break;
255  }
256  case phaseProperties::LIQUID:
257  {
258  forAll(Y, i)
259  {
260  X[i] = Y[i]/thermo_.liquids().properties()[i].W();
261  WInv += X[i];
262  }
263  break;
264  }
265  case phaseProperties::SOLID:
266  {
267  forAll(Y, i)
268  {
269  X[i] = Y[i]/thermo_.solids().properties()[i].W();
270  WInv += X[i];
271  }
272  break;
273  }
274  }
275 
276  tmp<scalarField> tfld = X/(WInv + ROOTVSMALL);
277  return tfld;
278 }
279 
280 
281 template<class CloudType>
283 (
284  const label phasei,
285  const scalarField& Y,
286  const scalar p,
287  const scalar T
288 ) const
289 {
290  const phaseProperties& props = phaseProps_[phasei];
291  scalar HMixture = 0.0;
292  switch (props.phase())
293  {
294  case phaseProperties::GAS:
295  {
296  forAll(Y, i)
297  {
298  label cid = props.carrierIds()[i];
299  HMixture += Y[i]*thermo_.carrier().Ha(cid, p, T);
300  }
301  break;
302  }
303  case phaseProperties::LIQUID:
304  {
305  forAll(Y, i)
306  {
307  HMixture += Y[i]*thermo_.liquids().properties()[i].h(p, T);
308  }
309  break;
310  }
311  case phaseProperties::SOLID:
312  {
313  forAll(Y, i)
314  {
315  HMixture +=
316  Y[i]
317  *(
318  thermo_.solids().properties()[i].Hf()
319  + thermo_.solids().properties()[i].Cp()*T
320  );
321  }
322  break;
323  }
324  default:
325  {
327  << "Unknown phase enumeration" << abort(FatalError);
328  }
329  }
330 
331  return HMixture;
332 }
333 
334 
335 template<class CloudType>
337 (
338  const label phasei,
339  const scalarField& Y,
340  const scalar p,
341  const scalar T
342 ) const
343 {
344  const phaseProperties& props = phaseProps_[phasei];
345  scalar HsMixture = 0.0;
346  switch (props.phase())
347  {
348  case phaseProperties::GAS:
349  {
350  forAll(Y, i)
351  {
352  label cid = props.carrierIds()[i];
353  HsMixture += Y[i]*thermo_.carrier().Hs(cid, p, T);
354  }
355  break;
356  }
357  case phaseProperties::LIQUID:
358  {
359  forAll(Y, i)
360  {
361  HsMixture +=
362  Y[i]
363  *(
364  thermo_.liquids().properties()[i].h(p, T)
365  - thermo_.liquids().properties()[i].h(p, 298.15)
366  );
367  }
368  break;
369  }
370  case phaseProperties::SOLID:
371  {
372  forAll(Y, i)
373  {
374  HsMixture += Y[i]*thermo_.solids().properties()[i].Cp()*T;
375  }
376  break;
377  }
378  default:
379  {
381  << "Unknown phase enumeration"
382  << abort(FatalError);
383  }
384  }
385 
386  return HsMixture;
387 }
388 
389 
390 template<class CloudType>
392 (
393  const label phasei,
394  const scalarField& Y,
395  const scalar p,
396  const scalar T
397 ) const
398 {
399  const phaseProperties& props = phaseProps_[phasei];
400  scalar HcMixture = 0.0;
401  switch (props.phase())
402  {
403  case phaseProperties::GAS:
404  {
405  forAll(Y, i)
406  {
407  label cid = props.carrierIds()[i];
408  HcMixture += Y[i]*thermo_.carrier().Hc(cid);
409  }
410  break;
411  }
412  case phaseProperties::LIQUID:
413  {
414  forAll(Y, i)
415  {
416  HcMixture +=
417  Y[i]*thermo_.liquids().properties()[i].h(p, 298.15);
418  }
419  break;
420  }
421  case phaseProperties::SOLID:
422  {
423  forAll(Y, i)
424  {
425  HcMixture += Y[i]*thermo_.solids().properties()[i].Hf();
426  }
427  break;
428  }
429  default:
430  {
432  << "Unknown phase enumeration"
433  << abort(FatalError);
434  }
435  }
436 
437  return HcMixture;
438 }
439 
440 
441 template<class CloudType>
443 (
444  const label phasei,
445  const scalarField& Y,
446  const scalar p,
447  const scalar T
448 ) const
449 {
450  const phaseProperties& props = phaseProps_[phasei];
451  scalar CpMixture = 0.0;
452  switch (props.phase())
453  {
454  case phaseProperties::GAS:
455  {
456  forAll(Y, i)
457  {
458  label cid = props.carrierIds()[i];
459  CpMixture += Y[i]*thermo_.carrier().Cp(cid, p, T);
460  }
461  break;
462  }
463  case phaseProperties::LIQUID:
464  {
465  forAll(Y, i)
466  {
467  CpMixture += Y[i]*thermo_.liquids().properties()[i].Cp(p, T);
468  }
469  break;
470  }
471  case phaseProperties::SOLID:
472  {
473  forAll(Y, i)
474  {
475  CpMixture += Y[i]*thermo_.solids().properties()[i].Cp();
476  }
477  break;
478  }
479  default:
480  {
482  << "Unknown phase enumeration"
483  << abort(FatalError);
484  }
485  }
486 
487  return CpMixture;
488 }
489 
490 
491 template<class CloudType>
493 (
494  const label phasei,
495  const scalarField& Y,
496  const scalar p,
497  const scalar T
498 ) const
499 {
500  const phaseProperties& props = phaseProps_[phasei];
501  scalar LMixture = 0.0;
502  switch (props.phase())
503  {
504  case phaseProperties::GAS:
505  {
506  if (debug)
507  {
509  << "No support for gaseous components" << endl;
510  }
511  break;
512  }
513  case phaseProperties::LIQUID:
514  {
515  forAll(Y, i)
516  {
517  LMixture += Y[i]*thermo_.liquids().properties()[i].hl(p, T);
518  }
519  break;
520  }
521  case phaseProperties::SOLID:
522  {
523  if (debug)
524  {
526  << "No support for solid components" << endl;
527  }
528  break;
529  }
530  default:
531  {
533  << "Unknown phase enumeration"
534  << abort(FatalError);
535  }
536  }
537 
538  return LMixture;
539 }
540 
541 
542 template<class CloudType>
544 (
545  const scalarField& Ygas,
546  const scalarField& Yliq,
547  const scalarField& Ysol,
548  const scalar T,
549  const scalar p
550 ) const
551 {
552  const scalarField& YMix = this->YMixture0();
553 
554  const auto& carrier = this->carrier();
555  const auto& thermo = this->thermo();
556 
557  scalarField Xgas(Ygas.size(), 0);
558  scalar WInv = 0;
559  forAll(Ygas, i)
560  {
561  label cid = phaseProps_[idGas()].carrierIds()[i];
562  Xgas[i] = YMix[idGas()]*Ygas[i]/carrier.W(cid);
563  WInv += Xgas[i];
564  }
565 
566  scalarField Xliq(Yliq.size(), 0);
567  forAll(Yliq, i)
568  {
569  Xliq[i] = YMix[idLiquid()]*Yliq[i]/thermo.liquids().properties()[i].W();
570  WInv += Xliq[i];
571  }
572 
573  scalarField Xsol(Ysol.size(), 0);
574  forAll(Ysol, i)
575  {
576  Xsol[i] = YMix[idSolid()]*Ysol[i]/thermo.solids().properties()[i].W();
577  WInv += Xsol[i];
578  }
579 
580  Xgas /= (WInv + ROOTVSMALL);
581  Xliq /= (WInv + ROOTVSMALL);
582  Xsol /= (WInv + ROOTVSMALL);
583 
584 
585  scalar rho = 0;
586  forAll(Xgas, i)
587  {
588  label cid = phaseProps_[idGas()].carrierIds()[i];
589  rho += Xgas[i]*carrier.rho(cid, p, T);
590  }
591  forAll(Xliq, i)
592  {
593  rho += Xliq[i]*thermo.liquids().properties()[i].rho(p, T);
594  }
595  forAll(Xsol, i)
596  {
597  rho += Xsol[i]*thermo.solids().properties()[i].rho();
598  }
599 
600  return rho;
601 
602 }
603 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
604 
605 #include "CompositionModelNew.C"
606 
607 // ************************************************************************* //
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:443
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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:283
Foam::basicSpecieMixture
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
Definition: basicSpecieMixture.H:58
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:61
Foam::CompositionModel::rho
virtual scalar rho(const scalarField &Ygas, const scalarField &Yliq, const scalarField &Ysol, const scalar T, const scalar p) const
Return rho of the full composition.
Definition: CompositionModel.C:544
thermo
psiReactionThermo & thermo
Definition: createFields.H:28
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:183
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:204
Foam::phaseProperties
Helper class to manage multi-specie phase properties.
Definition: phaseProperties.H:60
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:369
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:337
rho
rho
Definition: readInitialConditions.H:88
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::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:392
Foam::CompositionModel
Templated reacting parcel composition model class Consists of carrier species (via thermo package),...
Definition: ReactingCloud.H:58
Foam::CompositionModel::phaseProps
const phasePropertiesList & phaseProps() const
Return the list of phase properties.
Definition: CompositionModel.C:116
Foam::Field< scalar >
Foam::CompositionModel::Y0
const scalarField & Y0(const label phaseI) const
Return the list of phase phaseI mass fractions.
Definition: CompositionModel.C:226
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:236
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:100
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::CompositionModel::carrier
const basicSpecieMixture & carrier() const
Return the carrier components (wrapper function)
Definition: CompositionModel.C:92
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:123
Foam::CompositionModel::CompositionModel
CompositionModel(CloudType &owner)
Construct null from owner.
Definition: CompositionModel.C:34
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
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:153
Foam::CompositionModel::solids
const solidMixtureProperties & solids() const
Return the global (additional) solids.
Definition: CompositionModel.C:108
Foam::CompositionModel::nPhase
label nPhase() const
Return the number of phases.
Definition: CompositionModel.C:123
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::liquidMixtureProperties
A mixture of liquids.
Definition: liquidMixtureProperties.H:68
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::CompositionModel::thermo
const SLGThermo & thermo() const
Return the thermo database.
Definition: CompositionModel.C:84
Foam::CompositionModel::~CompositionModel
virtual ~CompositionModel()
Destructor.
Definition: CompositionModel.C:77
Foam::List< word >
CompositionModel.H
Foam::CompositionModel::phaseTypes
const wordList & phaseTypes() const
Return the list of phase type names.
Definition: CompositionModel.C:130
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:161
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:493
Foam::phaseProperties::phase
phaseType phase() const
Return const access to the phase type.
Definition: phaseProperties.C:242
Foam::CompositionModel::stateLabels
const wordList & stateLabels() const
Return the list of state labels (s), (l), (g) etc.
Definition: CompositionModel.C:145
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328