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-------------------------------------------------------------------------------
11License
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
33template<class CloudType>
35:
37 thermo_(owner.thermo()),
38 phaseProps_()
39{}
40
41
42template<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
62template<class CloudType>
64(
66)
67:
69 thermo_(cm.thermo_),
70 phaseProps_(cm.phaseProps_)
71{}
72
73
74// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75
76template<class CloudType>
78{}
79
80
81// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82
83template<class CloudType>
85{
86 return thermo_;
87}
88
89
90template<class CloudType>
93{
94 return thermo_.carrier();
95}
96
97
98template<class CloudType>
102 return thermo_.liquids();
103}
105
106template<class CloudType>
109{
110 return thermo_.solids();
111}
113
114template<class CloudType>
117{
118 return phaseProps_;
120
121
122template<class CloudType>
124{
125 return phaseProps_.size();
126}
127
128
129template<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 }
142
143
144template<class CloudType>
146{
147 return phaseProps_.stateLabels();
148}
149
151template<class CloudType>
152const Foam::wordList&
154{
155 return phaseProps_[phasei].names();
156}
157
158
159template<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)
171 << "Unable to determine global id for requested component "
172 << cmptName << ". Available components are " << nl
173 << thermo_.carrier().species()
174 << abort(FatalError);
175 }
177 return id;
178}
179
180
181template<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)
194 << "Unable to determine local id for component " << cmptName
195 << abort(FatalError);
197
198 return id;
199}
200
201
202template<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
224template<class CloudType>
226(
227 const label phasei
228) const
229{
230 return phaseProps_[phasei].Y();
231}
232
233
234template<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 {
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 }
257 {
258 forAll(Y, i)
259 {
260 X[i] = Y[i]/thermo_.liquids().properties()[i].W();
261 WInv += X[i];
262 }
263 break;
264 }
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
281template<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 {
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 }
304 {
305 forAll(Y, i)
306 {
307 HMixture += Y[i]*thermo_.liquids().properties()[i].h(p, T);
308 }
309 break;
310 }
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
335template<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 {
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 }
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 }
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
390template<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 {
404 {
405 forAll(Y, i)
406 {
407 label cid = props.carrierIds()[i];
408 HcMixture += Y[i]*thermo_.carrier().Hc(cid);
409 }
410 break;
411 }
413 {
414 forAll(Y, i)
415 {
416 HcMixture +=
417 Y[i]*thermo_.liquids().properties()[i].h(p, 298.15);
418 }
419 break;
420 }
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
441template<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 {
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 }
464 {
465 forAll(Y, i)
466 {
467 CpMixture += Y[i]*thermo_.liquids().properties()[i].Cp(p, T);
468 }
469 break;
470 }
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
491template<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 {
505 {
506 if (debug)
507 {
509 << "No support for gaseous components" << endl;
510 }
511 break;
512 }
514 {
515 forAll(Y, i)
516 {
517 LMixture += Y[i]*thermo_.liquids().properties()[i].hl(p, T);
518 }
519 break;
520 }
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
542template<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// ************************************************************************* //
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.
const wordList & stateLabels() const
Return the list of state labels (s), (l), (g) etc.
const phasePropertiesList & phaseProps() const
Return the list of phase properties.
const basicSpecieMixture & carrier() const
Return the carrier components (wrapper function)
const SLGThermo & thermo() const
Return the thermo database.
virtual ~CompositionModel()
Destructor.
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 Hs(const label phaseI, const scalarField &Y, const scalar p, const scalar T) const
Return sensible enthalpy 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.
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:75
Thermo package for (S)olids (L)iquids and (G)ases Takes reference to thermo package,...
Definition: SLGThermo.H:67
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
scalar Hc() const
Chemical enthalpy [J/kg].
tmp< GeometricField< Type, faPatchField, areaMesh > > H() const
Return the H operation source.
Definition: faMatrix.C:633
static const char *const componentNames[]
Definition: bool.H:104
Simple container for a list of phase properties.
Helper class to manage multi-specie phase properties.
const labelList & carrierIds() const
Return const access to the map to the carrier ids.
phaseType phase() const
Return const access to the phase type.
Lookup type of boundary radiation properties.
Definition: lookup.H:66
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
PtrList< volScalarField > & Y
const volScalarField & T
const volScalarField & Cp
Definition: EEqn.H:7
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
label phasei
Definition: pEqn.H:27
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
const vector L(dict.get< vector >("L"))