specieI.H
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-2017 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 "specie.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
34(
35 const word& name,
36 const scalar Y,
37 const scalar molWeight
38)
39:
40 name_(name),
41 Y_(Y),
42 molWeight_(molWeight)
43{}
44
45
47(
48 const scalar Y,
49 const scalar molWeight
50)
51:
52 Y_(Y),
53 molWeight_(molWeight)
54{}
55
56
57// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58
59inline Foam::specie::specie(const word& name, const specie& st)
60:
61 name_(name),
62 Y_(st.Y_),
63 molWeight_(st.molWeight_)
64{}
65
66
67// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68
69inline const Foam::word& Foam::specie::name() const
70{
71 return name_;
72}
73
74
75inline Foam::scalar Foam::specie::W() const
76{
77 return molWeight_;
78}
79
80
81inline Foam::scalar Foam::specie::Y() const
82{
83 return Y_;
84}
85
86
87inline Foam::scalar Foam::specie::R() const
88{
89 return RR/molWeight_;
90}
91
92
93// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
94
95inline void Foam::specie::operator=(const specie& st)
96{
97 // Preserve original name
98 Y_ = st.Y_;
99 molWeight_ = st.molWeight_;
100}
101
102
103inline void Foam::specie::operator+=(const specie& st)
104{
105 const scalar sumY = Y_ + st.Y_;
106 if (mag(sumY) > SMALL)
107 {
108 molWeight_ = sumY/(Y_/molWeight_ + st.Y_/st.molWeight_);
109 }
110
111 Y_ = sumY;
112}
113
114
115inline void Foam::specie::operator*=(const scalar s)
116{
117 Y_ *= s;
118}
119
120
121// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
122
123inline Foam::specie Foam::operator+(const specie& st1, const specie& st2)
124{
125 const scalar sumY = max(st1.Y_ + st2.Y_, SMALL);
126
127 if (mag(sumY) > SMALL)
128 {
129 return specie
130 (
131 sumY,
132 sumY/(st1.Y_/st1.molWeight_ + st2.Y_/st2.molWeight_)
133 );
134 }
135 else
136 {
137 return st1;
138 }
139}
140
141
142inline Foam::specie Foam::operator*(const scalar s, const specie& st)
143{
144 return specie
145 (
146 s*st.Y_,
147 st.molWeight_
148 );
149}
150
151
152inline Foam::specie Foam::operator==(const specie& st1, const specie& st2)
153{
154 scalar diffY = st2.Y_ - st1.Y_;
155 if (mag(diffY) < SMALL)
156 {
157 diffY = SMALL;
158 }
159
160 const scalar diffRW = st2.Y_/st2.molWeight_ - st1.Y_/st1.molWeight_;
161
162 #ifdef __clang__
163 // Using intermediate volatile bool to prevent compiler optimising out the
164 // if block (above) - CLANG 3.7.1
165 volatile const bool valid = (mag(diffRW) > SMALL);
166 const scalar molWeight = valid ? diffY/diffRW : GREAT;
167 #else
168 scalar molWeight = GREAT;
169 if (mag(diffRW) > SMALL)
170 {
171 molWeight = diffY/diffRW;
172 }
173 #endif
174
175 return specie(diffY, molWeight);
176}
177
178
179// ************************************************************************* //
Base class of the thermophysical property types.
Definition: specie.H:68
void operator=(const specie &)
Copy assignment, preserve original name.
Definition: specieI.H:95
void operator+=(const specie &)
Definition: specieI.H:103
scalar W() const
Molecular weight [kg/kmol].
Definition: specieI.H:75
scalar Y() const
No of moles of this species in mixture.
Definition: specieI.H:81
scalar R() const
Gas constant [J/(kg K)].
Definition: specieI.H:87
const word & name() const
Name.
Definition: specieI.H:69
void operator*=(const scalar)
Definition: specieI.H:115
A class for handling words, derived from Foam::string.
Definition: word.H:68
PtrList< volScalarField > & Y
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const scalar RR
Universal gas constant: default in [J/(kmol K)].
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59