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 :
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  {
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  }
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  X /= WInv;
271 
272  return X;
273 }
274 
275 
276 template<class CloudType>
278 (
279  const label phasei,
280  const scalarField& Y,
281  const scalar p,
282  const scalar T
283 ) const
284 {
285  const phaseProperties& props = phaseProps_[phasei];
286  scalar HMixture = 0.0;
287  switch (props.phase())
288  {
290  {
291  forAll(Y, i)
292  {
293  label cid = props.carrierIds()[i];
294  HMixture += Y[i]*thermo_.carrier().Ha(cid, p, T);
295  }
296  break;
297  }
299  {
300  forAll(Y, i)
301  {
302  HMixture += Y[i]*thermo_.liquids().properties()[i].h(p, T);
303  }
304  break;
305  }
307  {
308  forAll(Y, i)
309  {
310  HMixture +=
311  Y[i]
312  *(
313  thermo_.solids().properties()[i].Hf()
314  + thermo_.solids().properties()[i].Cp()*T
315  );
316  }
317  break;
318  }
319  default:
320  {
322  << "Unknown phase enumeration" << abort(FatalError);
323  }
324  }
325 
326  return HMixture;
327 }
328 
329 
330 template<class CloudType>
332 (
333  const label phasei,
334  const scalarField& Y,
335  const scalar p,
336  const scalar T
337 ) const
338 {
339  const phaseProperties& props = phaseProps_[phasei];
340  scalar HsMixture = 0.0;
341  switch (props.phase())
342  {
344  {
345  forAll(Y, i)
346  {
347  label cid = props.carrierIds()[i];
348  HsMixture += Y[i]*thermo_.carrier().Hs(cid, p, T);
349  }
350  break;
351  }
353  {
354  forAll(Y, i)
355  {
356  HsMixture +=
357  Y[i]
358  *(
359  thermo_.liquids().properties()[i].h(p, T)
360  - thermo_.liquids().properties()[i].h(p, 298.15)
361  );
362  }
363  break;
364  }
366  {
367  forAll(Y, i)
368  {
369  HsMixture += Y[i]*thermo_.solids().properties()[i].Cp()*T;
370  }
371  break;
372  }
373  default:
374  {
376  << "Unknown phase enumeration"
377  << abort(FatalError);
378  }
379  }
380 
381  return HsMixture;
382 }
383 
384 
385 template<class CloudType>
387 (
388  const label phasei,
389  const scalarField& Y,
390  const scalar p,
391  const scalar T
392 ) const
393 {
394  const phaseProperties& props = phaseProps_[phasei];
395  scalar HcMixture = 0.0;
396  switch (props.phase())
397  {
399  {
400  forAll(Y, i)
401  {
402  label cid = props.carrierIds()[i];
403  HcMixture += Y[i]*thermo_.carrier().Hc(cid);
404  }
405  break;
406  }
408  {
409  forAll(Y, i)
410  {
411  HcMixture +=
412  Y[i]*thermo_.liquids().properties()[i].h(p, 298.15);
413  }
414  break;
415  }
417  {
418  forAll(Y, i)
419  {
420  HcMixture += Y[i]*thermo_.solids().properties()[i].Hf();
421  }
422  break;
423  }
424  default:
425  {
427  << "Unknown phase enumeration"
428  << abort(FatalError);
429  }
430  }
431 
432  return HcMixture;
433 }
434 
435 
436 template<class CloudType>
438 (
439  const label phasei,
440  const scalarField& Y,
441  const scalar p,
442  const scalar T
443 ) const
444 {
445  const phaseProperties& props = phaseProps_[phasei];
446  scalar CpMixture = 0.0;
447  switch (props.phase())
448  {
450  {
451  forAll(Y, i)
452  {
453  label cid = props.carrierIds()[i];
454  CpMixture += Y[i]*thermo_.carrier().Cp(cid, p, T);
455  }
456  break;
457  }
459  {
460  forAll(Y, i)
461  {
462  CpMixture += Y[i]*thermo_.liquids().properties()[i].Cp(p, T);
463  }
464  break;
465  }
467  {
468  forAll(Y, i)
469  {
470  CpMixture += Y[i]*thermo_.solids().properties()[i].Cp();
471  }
472  break;
473  }
474  default:
475  {
477  << "Unknown phase enumeration"
478  << abort(FatalError);
479  }
480  }
481 
482  return CpMixture;
483 }
484 
485 
486 template<class CloudType>
488 (
489  const label phasei,
490  const scalarField& Y,
491  const scalar p,
492  const scalar T
493 ) const
494 {
495  const phaseProperties& props = phaseProps_[phasei];
496  scalar LMixture = 0.0;
497  switch (props.phase())
498  {
500  {
501  if (debug)
502  {
504  << "No support for gaseous components" << endl;
505  }
506  break;
507  }
509  {
510  forAll(Y, i)
511  {
512  LMixture += Y[i]*thermo_.liquids().properties()[i].hl(p, T);
513  }
514  break;
515  }
517  {
518  if (debug)
519  {
521  << "No support for solid components" << endl;
522  }
523  break;
524  }
525  default:
526  {
528  << "Unknown phase enumeration"
529  << abort(FatalError);
530  }
531  }
532 
533  return LMixture;
534 }
535 
536 
537 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
538 
539 #include "CompositionModelNew.C"
540 
541 // ************************************************************************* //
label localId(const label phaseI, const word &cmptName, const bool allowNotFound=false) const
Return local id of component cmptName in phase phaseI.
const PtrList< liquidProperties > & properties() const
Return the liquid properties.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
const wordList & stateLabels() const
Return the list of state labels.
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
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
const List< word > & components() const
Return the liquid names.
label phasei
Definition: pEqn.H:27
CompositionModel(CloudType &owner)
Construct null from owner.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Helper class to manage multi-specie phase properties.
label localToCarrierId(const label phaseI, const label id, const bool allowNotFound=false) const
Return carrier id of component given local id.
label nPhase() const
Return the number of phases.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual scalar Ha(const label speciei, const scalar p, const scalar T) const =0
Absolute enthalpy [J/kg].
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
const solidMixtureProperties & solids() const
Return the global (additional) solids.
const scalarField & Y0(const label phaseI) const
Return the list of phase phaseI mass fractions.
Base class for cloud sub-models.
const wordList & phaseTypes() const
Return the list of word representation of phase types.
virtual scalar Cp(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return specific heat caoacity for the phase phaseI.
virtual scalar H(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return total enthalpy for the phase phaseI.
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
const basicSpecieMixture & carrier() const
Return the carrier components (wrapper function)
virtual scalar Hs(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return sensible enthalpy for the phase phaseI.
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
const SLGThermo & thermo() const
Return the thermo database.
virtual scalar Cp(const label speciei, const scalar p, const scalar T) const =0
Heat capacity at constant pressure [J/(kg K)].
label carrierId(const word &cmptName, const bool allowNotFound=false) const
Return global id of component cmptName in carrier thermo.
A class for handling words, derived from string.
Definition: word.H:59
virtual scalar Hc(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return chemical enthalpy for the phase phaseI.
Thermo package for (S)olids (L)iquids and (G)ases Takes reference to thermo package, and provides:
Definition: SLGThermo.H:62
label size() const
Return the size (number of phases)
const solidMixtureProperties & solids() const
Return reference to the global (additional) solids.
Definition: SLGThermo.C:134
virtual scalar Hc(const label speciei) const =0
Chemical enthalpy [J/kg].
const liquidMixtureProperties & liquids() const
Return reference to the global (additional) liquids.
Definition: SLGThermo.C:121
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
const wordList & phaseTypes() const
Return the list of phase type names.
static const char nl
Definition: Ostream.H:262
const PtrList< solidProperties > & properties() const
Return the solidProperties properties.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const List< word > & components() const
Return the solidProperties names.
const phasePropertiesList & phaseProps() const
Return the list of phase properties.
Simple container for a list of phase properties.
const wordList & stateLabels() const
Return the list of state labels (s), (l), (g) etc.
label carrierId(const word &cmptName, bool allowNotFound=false) const
Index of carrier component.
Definition: SLGThermo.C:148
const liquidMixtureProperties & liquids() const
Return the global (additional) liquids.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
#define WarningInFunction
Report a warning using Foam::Warning.
virtual scalar Hs(const label speciei, const scalar p, const scalar T) const =0
Sensible enthalpy [J/kg].
const wordList & componentNames(const label phaseI) const
Return the list of component names for phaseI.
const basicSpecieMixture & carrier() const
Return reference to the gaseous components.
Definition: SLGThermo.C:108
virtual ~CompositionModel()
Destructor.
virtual scalar L(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return latent heat for the phase phaseI.
const speciesTable & species() const
Return the table of species.
const CloudType & owner() const
Return const access to the owner cloud.
scalarField X(const label phaseI, const scalarField &Y) const
Return the list of phase phaseI volume fractions fractions.
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:128
Templated reacting parcel composition model class Consists of carrier species (via thermo package)...
Definition: ReactingCloud.H:52
virtual scalar W(const label speciei) const =0
Molecular weight of the given specie [kg/kmol].
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
phaseType phase() const
Return const access to the phase type.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451