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  (
169  "label CompositionModel<CloudType>::carrierId"
170  "("
171  "const word&, "
172  "const bool"
173  ") const"
174  ) << "Unable to determine global id for requested component "
175  << cmptName << ". Available components are " << nl
176  << thermo_.carrier().species()
177  << abort(FatalError);
178  }
179 
180  return id;
181 }
182 
183 
184 template<class CloudType>
186 (
187  const label phasei,
188  const word& cmptName,
189  const bool allowNotFound
190 ) const
191 {
192  label id = phaseProps_[phasei].id(cmptName);
193 
194  if (id < 0 && !allowNotFound)
195  {
197  (
198  "label CompositionModel<CloudType>::localId"
199  "("
200  "const label, "
201  "const word&, "
202  "const bool"
203  ") const"
204  ) << "Unable to determine local id for component " << cmptName
205  << abort(FatalError);
206  }
207 
208  return id;
209 }
210 
211 
212 template<class CloudType>
214 (
215  const label phasei,
216  const label id,
217  const bool allowNotFound
218 ) const
219 {
220  label cid = phaseProps_[phasei].carrierIds()[id];
221 
222  if (cid < 0 && !allowNotFound)
223  {
225  (
226  "label "
227  "CompositionModel<CloudType>::localToCarrierId"
228  "("
229  "const label, "
230  "const label, "
231  "const bool"
232  ") const"
233  ) << "Unable to determine global carrier id for phase "
234  << phasei << " with local id " << id
235  << abort(FatalError);
236  }
237 
238  return cid;
239 }
240 
241 
242 template<class CloudType>
244 (
245  const label phasei
246 ) const
247 {
248  return phaseProps_[phasei].Y();
249 }
250 
251 
252 template<class CloudType>
254 (
255  const label phasei,
256  const scalarField& Y
257 ) const
258 {
259  const phaseProperties& props = phaseProps_[phasei];
260  scalarField X(Y.size());
261  scalar WInv = 0.0;
262  switch (props.phase())
263  {
265  {
266  forAll(Y, i)
267  {
268  label cid = props.carrierIds()[i];
269  X[i] = Y[i]/thermo_.carrier().W(cid);
270  WInv += X[i];
271  }
272  break;
273  }
275  {
276  forAll(Y, i)
277  {
278  X[i] = Y[i]/thermo_.liquids().properties()[i].W();
279  WInv += X[i];
280  }
281  break;
282  }
283  default:
284  {
286  (
287  "scalarField CompositionModel<CloudType>::X"
288  "("
289  "const label, "
290  "const scalarField&"
291  ") const"
292  ) << "Only possible to convert gas and liquid mass fractions"
293  << abort(FatalError);
294  }
295  }
296 
297  X /= WInv;
298 
299  return X;
300 }
301 
302 
303 template<class CloudType>
305 (
306  const label phasei,
307  const scalarField& Y,
308  const scalar p,
309  const scalar T
310 ) const
311 {
312  const phaseProperties& props = phaseProps_[phasei];
313  scalar HMixture = 0.0;
314  switch (props.phase())
315  {
317  {
318  forAll(Y, i)
319  {
320  label cid = props.carrierIds()[i];
321  HMixture += Y[i]*thermo_.carrier().Ha(cid, p, T);
322  }
323  break;
324  }
326  {
327  forAll(Y, i)
328  {
329  HMixture += Y[i]*thermo_.liquids().properties()[i].h(p, T);
330  }
331  break;
332  }
334  {
335  forAll(Y, i)
336  {
337  HMixture +=
338  Y[i]
339  *(
340  thermo_.solids().properties()[i].Hf()
341  + thermo_.solids().properties()[i].Cp()*T
342  );
343  }
344  break;
345  }
346  default:
347  {
349  (
350  "scalar CompositionModel<CloudType>::H"
351  "("
352  " const label, "
353  " const scalarField&, "
354  " const scalar, "
355  " const scalar"
356  ") const"
357  ) << "Unknown phase enumeration" << abort(FatalError);
358  }
359  }
360 
361  return HMixture;
362 }
363 
364 
365 template<class CloudType>
367 (
368  const label phasei,
369  const scalarField& Y,
370  const scalar p,
371  const scalar T
372 ) const
373 {
374  const phaseProperties& props = phaseProps_[phasei];
375  scalar HsMixture = 0.0;
376  switch (props.phase())
377  {
379  {
380  forAll(Y, i)
381  {
382  label cid = props.carrierIds()[i];
383  HsMixture += Y[i]*thermo_.carrier().Hs(cid, p, T);
384  }
385  break;
386  }
388  {
389  forAll(Y, i)
390  {
391  HsMixture +=
392  Y[i]
393  *(
394  thermo_.liquids().properties()[i].h(p, T)
395  - thermo_.liquids().properties()[i].h(p, 298.15)
396  );
397  }
398  break;
399  }
401  {
402  forAll(Y, i)
403  {
404  HsMixture += Y[i]*thermo_.solids().properties()[i].Cp()*T;
405  }
406  break;
407  }
408  default:
409  {
411  (
412  "scalar CompositionModel<CloudType>::Hs"
413  "("
414  " const label, "
415  " const scalarField&, "
416  " const scalar, "
417  " const scalar"
418  ") const"
419  ) << "Unknown phase enumeration"
420  << abort(FatalError);
421  }
422  }
423 
424  return HsMixture;
425 }
426 
427 
428 template<class CloudType>
430 (
431  const label phasei,
432  const scalarField& Y,
433  const scalar p,
434  const scalar T
435 ) const
436 {
437  const phaseProperties& props = phaseProps_[phasei];
438  scalar HcMixture = 0.0;
439  switch (props.phase())
440  {
442  {
443  forAll(Y, i)
444  {
445  label cid = props.carrierIds()[i];
446  HcMixture += Y[i]*thermo_.carrier().Hc(cid);
447  }
448  break;
449  }
451  {
452  forAll(Y, i)
453  {
454  HcMixture +=
455  Y[i]*thermo_.liquids().properties()[i].h(p, 298.15);
456  }
457  break;
458  }
460  {
461  forAll(Y, i)
462  {
463  HcMixture += Y[i]*thermo_.solids().properties()[i].Hf();
464  }
465  break;
466  }
467  default:
468  {
470  (
471  "scalar CompositionModel<CloudType>::Hc"
472  "("
473  " const label, "
474  " const scalarField&, "
475  " const scalar, "
476  " const scalar"
477  ") const"
478  ) << "Unknown phase enumeration"
479  << abort(FatalError);
480  }
481  }
482 
483  return HcMixture;
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 CpMixture = 0.0;
498  switch (props.phase())
499  {
501  {
502  forAll(Y, i)
503  {
504  label cid = props.carrierIds()[i];
505  CpMixture += Y[i]*thermo_.carrier().Cp(cid, p, T);
506  }
507  break;
508  }
510  {
511  forAll(Y, i)
512  {
513  CpMixture += Y[i]*thermo_.liquids().properties()[i].Cp(p, T);
514  }
515  break;
516  }
518  {
519  forAll(Y, i)
520  {
521  CpMixture += Y[i]*thermo_.solids().properties()[i].Cp();
522  }
523  break;
524  }
525  default:
526  {
528  (
529  "scalar CompositionModel<CloudType>::Cp"
530  "("
531  "const label, "
532  "const scalarField&, "
533  "const scalar, "
534  "const scalar"
535  ") const"
536  ) << "Unknown phase enumeration"
537  << abort(FatalError);
538  }
539  }
540 
541  return CpMixture;
542 }
543 
544 
545 template<class CloudType>
547 (
548  const label phasei,
549  const scalarField& Y,
550  const scalar p,
551  const scalar T
552 ) const
553 {
554  const phaseProperties& props = phaseProps_[phasei];
555  scalar LMixture = 0.0;
556  switch (props.phase())
557  {
559  {
560  if (debug)
561  {
562  WarningIn
563  (
564  "scalar CompositionModel<CloudType>::L"
565  "("
566  "const label, "
567  "const scalarField&, "
568  "const scalar, "
569  "const scalar"
570  ") const\n"
571  ) << "No support for gaseous components" << endl;
572  }
573  break;
574  }
576  {
577  forAll(Y, i)
578  {
579  LMixture += Y[i]*thermo_.liquids().properties()[i].hl(p, T);
580  }
581  break;
582  }
584  {
585  if (debug)
586  {
587  WarningIn
588  (
589  "scalar CompositionModel<CloudType>::L"
590  "("
591  "const label, "
592  "const scalarField&, "
593  "const scalar, "
594  "const scalar"
595  ") const\n"
596  ) << "No support for solid components" << endl;
597  }
598  break;
599  }
600  default:
601  {
603  (
604  "scalar CompositionModel<CloudType>::L"
605  "("
606  "const label, "
607  "const scalarField&, "
608  "const scalar, "
609  "const scalar"
610  ") const"
611  ) << "Unknown phase enumeration"
612  << abort(FatalError);
613  }
614  }
615 
616  return LMixture;
617 }
618 
619 
620 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
621 
622 #include "CompositionModelNew.C"
623 
624 // ************************************************************************* //
const basicSpecieMixture & carrier() const
Return reference to the gaseous components.
Definition: SLGThermo.C:108
virtual scalar H(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return total enthalpy for the phase phaseI.
const CloudType & owner() const
Return const access to the owner cloud.
const scalarField & Y0(const label phaseI) const
Return the list of phase phaseI mass fractions.
label localId(const label phaseI, const word &cmptName, const bool allowNotFound=false) const
Return local id of component cmptName in phase phaseI.
label phasei
Definition: pEqn.H:37
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const wordList & stateLabels() const
Return the list of state labels (s), (l), (g) etc.
const solidMixtureProperties & solids() const
Return the global (additional) solids.
A class for handling words, derived from string.
Definition: word.H:59
virtual ~CompositionModel()
Destructor.
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual scalar W(const label speciei) const =0
Molecular weight of the given specie [kg/kmol].
const PtrList< solidProperties > & properties() const
Return the solidProperties properties.
const liquidMixtureProperties & liquids() const
Return the global (additional) liquids.
label nPhase() const
Return the number of phases.
virtual scalar L(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return latent heat for the phase phaseI.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Simple container for a list of phase properties.
const wordList & phaseTypes() const
Return the list of word representation of phase types.
phaseType phase() const
Return const access to the phase type.
Thermo package for (S)olids (L)iquids and (G)ases Takes reference to thermo package, and provides:
Definition: SLGThermo.H:62
const List< word > & components() const
Return the solidProperties names.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
label localToCarrierId(const label phaseI, const label id, const bool allowNotFound=false) const
Return carrier id of component given local id.
const phasePropertiesList & phaseProps() const
Return the list of phase properties.
#define forAll(list, i)
Definition: UList.H:421
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:110
const solidMixtureProperties & solids() const
Return reference to the global (additional) solids.
Definition: SLGThermo.C:140
const SLGThermo & thermo() const
Return the thermo database.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
virtual scalar Hc(const label speciei) const =0
Chemical enthalpy [J/kg].
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
virtual scalar Hs(const label speciei, const scalar p, const scalar T) const =0
Sensible enthalpy [J/kg].
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
virtual scalar Hs(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return sensible enthalpy for the phase phaseI.
Helper class to manage multi-specie phase properties.
scalarField X(const label phaseI, const scalarField &Y) const
Return the list of phase phaseI volume fractions fractions.
const PtrList< liquidProperties > & properties() const
Return the liquid properties.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
virtual scalar Ha(const label speciei, const scalar p, const scalar T) const =0
Absolute enthalpy [J/kg].
Base class for cloud sub-models.
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:128
virtual scalar Cp(const label speciei, const scalar p, const scalar T) const =0
Heat capacity at constant pressure [J/(kg K)].
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
Templated reacting parcel composition model class Consists of carrier species (via thermo package)...
Definition: ReactingCloud.H:52
const List< word > & components() const
Return the liquid names.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
virtual scalar Cp(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return specific heat caoacity for the phase phaseI.
const speciesTable & species() const
Return the table of species.
const wordList & phaseTypes() const
Return the list of phase type names.
label size() const
Return the size (number of phases)
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
const basicSpecieMixture & carrier() const
Return the carrier components (wrapper function)
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
label carrierId(const word &cmptName, bool allowNotFound=false) const
Index of carrier component.
Definition: SLGThermo.C:157
label carrierId(const word &cmptName, const bool allowNotFound=false) const
Return global id of component cmptName in carrier thermo.
virtual scalar Hc(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return chemical enthalpy for the phase phaseI.
const wordList & stateLabels() const
Return the list of state labels.
const wordList & componentNames(const label phaseI) const
Return the list of component names for phaseI.
CompositionModel(CloudType &owner)
Construct null from owner.
const liquidMixtureProperties & liquids() const
Return reference to the global (additional) liquids.
Definition: SLGThermo.C:124