CompositionModel.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 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"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class CloudType>
33 :
35  carrierThermo_(owner.carrierThermo()),
36  carrierMcThermoPtr_
37  (
38  isA<fluidMulticomponentThermo>(carrierThermo_)
39  ? &refCast<const fluidMulticomponentThermo>(carrierThermo_)
40  : nullptr
41  ),
42  thermo_(owner.thermo()),
43  phaseProps_()
44 {}
45 
46 
47 template<class CloudType>
49 (
50  const dictionary& dict,
51  CloudType& owner,
52  const word& type
53 )
54 :
55  CloudSubModelBase<CloudType>(owner, dict, typeName, type),
56  carrierThermo_(owner.carrierThermo()),
57  carrierMcThermoPtr_
58  (
59  isA<fluidMulticomponentThermo>(carrierThermo_)
60  ? &refCast<const fluidMulticomponentThermo>(carrierThermo_)
61  : nullptr
62  ),
63  thermo_(owner.thermo()),
64  phaseProps_
65  (
66  this->coeffDict().lookup("phases"),
67  carrierMcThermoPtr_ == nullptr
68  ? hashedWordList::null()
69  : carrierMcThermoPtr_->species(),
70  thermo_.liquids().components(),
71  thermo_.solids().components()
72  )
73 {}
74 
75 
76 template<class CloudType>
78 (
80 )
81 :
83  carrierThermo_(cm.carrierThermo_),
84  carrierMcThermoPtr_(cm.carrierMcThermoPtr_),
85  thermo_(cm.thermo_),
86  phaseProps_(cm.phaseProps_)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
91 
92 template<class CloudType>
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
99 template<class CloudType>
101 {
102  return thermo_;
103 }
104 
105 
106 template<class CloudType>
109 {
110  if (carrierMcThermoPtr_ == nullptr)
111  {
113  << "carrier requested, but object is not allocated"
114  << abort(FatalError);
115  }
116 
117  return *carrierMcThermoPtr_;
118 }
119 
120 
121 template<class CloudType>
124 {
125  return thermo_.liquids();
126 }
127 
128 
129 template<class CloudType>
132 {
133  return thermo_.solids();
134 }
135 
136 
137 template<class CloudType>
140 {
141  return phaseProps_;
142 }
143 
144 
145 template<class CloudType>
147 {
148  return phaseProps_.size();
149 }
150 
151 
152 template<class CloudType>
154 {
155  // if only 1 phase, return the constituent component names
156  if (phaseProps_.size() == 1)
157  {
158  return phaseProps_[0].names();
159  }
160  else
161  {
162  return phaseProps_.phaseTypes();
163  }
164 }
165 
166 
167 template<class CloudType>
169 {
170  return phaseProps_.stateLabels();
171 }
172 
173 
174 template<class CloudType>
175 const Foam::wordList&
177 {
178  return phaseProps_[phasei].names();
179 }
180 
181 
182 template<class CloudType>
184 (
185  const word& cmptName,
186  const bool allowNotFound
187 ) const
188 {
189  label id = -1;
190 
191  forAll(carrierMcThermoPtr_->species(), i)
192  {
193  if (cmptName == carrierMcThermoPtr_->species()[i])
194  {
195  id = i;
196  }
197  }
198 
199  if (id < 0 && !allowNotFound)
200  {
202  << "Unable to determine global id for requested component "
203  << cmptName << ". Available components are " << nl
204  << carrierMcThermoPtr_->species()
205  << abort(FatalError);
206  }
207 
208  return id;
209 }
210 
211 
212 template<class CloudType>
214 (
215  const label phasei,
216  const word& cmptName,
217  const bool allowNotFound
218 ) const
219 {
220  label id = phaseProps_[phasei].id(cmptName);
221 
222  if (id < 0 && !allowNotFound)
223  {
225  << "Unable to determine local id for component " << cmptName
226  << abort(FatalError);
227  }
228 
229  return id;
230 }
231 
232 
233 template<class CloudType>
235 (
236  const label phasei,
237  const label id,
238  const bool allowNotFound
239 ) const
240 {
241  label cid = phaseProps_[phasei].carrierId(id);
242 
243  if (cid < 0 && !allowNotFound)
244  {
246  << "Unable to determine global carrier id for phase "
247  << phasei << " with local id " << id
248  << abort(FatalError);
249  }
250 
251  return cid;
252 }
253 
254 
255 template<class CloudType>
257 (
258  const label phasei
259 ) const
260 {
261  return phaseProps_[phasei].Y();
262 }
263 
264 
265 template<class CloudType>
267 (
268  const label phasei,
269  const scalarField& Y
270 ) const
271 {
272  const phaseProperties& props = phaseProps_[phasei];
273  scalarField X(Y.size());
274  scalar WInv = 0.0;
275  switch (props.phase())
276  {
278  {
279  forAll(Y, i)
280  {
281  label cid = props.carrierId(i);
282  X[i] = Y[i]/carrierMcThermoPtr_->WiValue(cid);
283  WInv += X[i];
284  }
285  break;
286  }
288  {
289  forAll(Y, i)
290  {
291  X[i] = Y[i]/thermo_.liquids().properties()[i].W();
292  WInv += X[i];
293  }
294  break;
295  }
296  default:
297  {
299  << "Only possible to convert gas and liquid mass fractions"
300  << abort(FatalError);
301  }
302  }
303 
304  X /= WInv;
305 
306  return X;
307 }
308 
309 
310 template<class CloudType>
312 (
313  const label phasei,
314  const scalarField& Y,
315  const scalar p,
316  const scalar T
317 ) const
318 {
319  const phaseProperties& props = phaseProps_[phasei];
320  scalar HMixture = 0.0;
321  switch (props.phase())
322  {
324  {
325  forAll(Y, i)
326  {
327  label cid = props.carrierId(i);
328  HMixture += Y[i]*carrierMcThermoPtr_->hai(cid, p, T);
329  }
330  break;
331  }
333  {
334  forAll(Y, i)
335  {
336  HMixture += Y[i]*thermo_.liquids().properties()[i].ha(p, T);
337  }
338  break;
339  }
341  {
342  forAll(Y, i)
343  {
344  HMixture += Y[i]*thermo_.solids().properties()[i].ha(T);
345  }
346  break;
347  }
348  default:
349  {
351  << "Unknown phase enumeration" << abort(FatalError);
352  }
353  }
354 
355  return HMixture;
356 }
357 
358 
359 template<class CloudType>
361 (
362  const label phasei,
363  const scalarField& Y,
364  const scalar p,
365  const scalar T
366 ) const
367 {
368  const phaseProperties& props = phaseProps_[phasei];
369  scalar hsMixture = 0.0;
370  switch (props.phase())
371  {
373  {
374  forAll(Y, i)
375  {
376  label cid = props.carrierId(i);
377  hsMixture += Y[i]*carrierMcThermoPtr_->hsi(cid, p, T);
378  }
379  break;
380  }
382  {
383  forAll(Y, i)
384  {
385  hsMixture +=
386  Y[i]*(thermo_.liquids().properties()[i].hs(p, T));
387  }
388  break;
389  }
391  {
392  forAll(Y, i)
393  {
394  hsMixture += Y[i]*thermo_.solids().properties()[i].hs(T);
395  }
396  break;
397  }
398  default:
399  {
401  << "Unknown phase enumeration"
402  << abort(FatalError);
403  }
404  }
405 
406  return hsMixture;
407 }
408 
409 
410 template<class CloudType>
412 (
413  const label phasei,
414  const scalarField& Y,
415  const scalar p,
416  const scalar T
417 ) const
418 {
419  const phaseProperties& props = phaseProps_[phasei];
420  scalar CpMixture = 0.0;
421  switch (props.phase())
422  {
424  {
425  forAll(Y, i)
426  {
427  label cid = props.carrierId(i);
428  CpMixture += Y[i]*carrierMcThermoPtr_->Cpi(cid, p, T);
429  }
430  break;
431  }
433  {
434  forAll(Y, i)
435  {
436  CpMixture += Y[i]*thermo_.liquids().properties()[i].Cp(p, T);
437  }
438  break;
439  }
441  {
442  forAll(Y, i)
443  {
444  CpMixture += Y[i]*thermo_.solids().properties()[i].Cp();
445  }
446  break;
447  }
448  default:
449  {
451  << "Unknown phase enumeration"
452  << abort(FatalError);
453  }
454  }
455 
456  return CpMixture;
457 }
458 
459 
460 template<class CloudType>
462 (
463  const label phasei,
464  const scalarField& Y,
465  const scalar p,
466  const scalar T
467 ) const
468 {
469  const phaseProperties& props = phaseProps_[phasei];
470  scalar LMixture = 0.0;
471  switch (props.phase())
472  {
474  {
475  if (debug)
476  {
478  << "No support for gaseous components" << endl;
479  }
480  break;
481  }
483  {
484  forAll(Y, i)
485  {
486  LMixture += Y[i]*thermo_.liquids().properties()[i].hl(p, T);
487  }
488  break;
489  }
491  {
492  if (debug)
493  {
495  << "No support for solid components" << endl;
496  }
497  break;
498  }
499  default:
500  {
502  << "Unknown phase enumeration"
503  << abort(FatalError);
504  }
505  }
506 
507  return LMixture;
508 }
509 
510 
511 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
512 
513 #include "CompositionModelNew.C"
514 
515 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Base class for cloud sub-models.
Templated reacting parcel composition model class Consists of carrier species (via thermo package),...
const liquidMixtureProperties & liquids() const
Return the global (additional) liquids.
scalarField X(const label phaseI, const scalarField &Y) const
Return the list of phase phaseI volume fractions fractions.
const parcelThermo & thermo() const
Return the thermo database.
const wordList & stateLabels() const
Return the list of state labels (s), (l), (g) etc.
CompositionModel(CloudType &owner)
Construct null from owner.
virtual scalar ha(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return total enthalpy for the phase phaseI.
const phasePropertiesList & phaseProps() const
Return the list of phase properties.
virtual scalar L(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return latent heat for the phase phaseI.
virtual ~CompositionModel()
Destructor.
const fluidMulticomponentThermo & carrier() const
Return the carrier components (wrapper function)
const wordList & componentNames(const label phaseI) const
Return the list of component names for phaseI.
label nPhase() const
Return the number of phases.
label localToCarrierId(const label phaseI, const label id, const bool allowNotFound=false) const
Return carrier id of component given local id.
virtual scalar Cp(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return specific heat capacity for the phase phaseI.
const solidMixtureProperties & solids() const
Return the global (additional) solids.
label localId(const label phaseI, const word &cmptName, const bool allowNotFound=false) const
Return local id of component cmptName in phase phaseI.
virtual scalar hs(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return sensible enthalpy for the phase phaseI.
label carrierId(const word &cmptName, const bool allowNotFound=false) const
Return global id of component cmptName in carrier thermo.
const scalarField & Y0(const label phaseI) const
Return the list of phase phaseI mass fractions.
const wordList & phaseTypes() const
Return the list of phase type names.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Base-class for multi-component fluid thermodynamic properties.
A wordList with hashed indices for faster lookup by name.
Thermo package for (S)olids (L)iquids and (G)ases Takes reference to thermo package,...
Definition: parcelThermo.H:59
Simple container for a list of phase properties.
Helper class to manage multi-specie phase properties.
label carrierId(const label speciei) const
Return the carrier id for a given specie.
phaseType phase() const
Return const access to the phase type.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define WarningInFunction
Report a warning using Foam::Warning.
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
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:129
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:166
error FatalError
static const char nl
Definition: Ostream.H:266
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p
PtrList< volScalarField > & Y
fluidMulticomponentThermo & thermo
Definition: createFields.H:31