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 | Copyright (C) 2011 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 "specie.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 inline specie::specie
36 (
37  const word& name,
38  const scalar nMoles,
39  const scalar molWeight
40 )
41 :
42  name_(name),
43  nMoles_(nMoles),
44  molWeight_(molWeight)
45 {}
46 
47 
48 inline specie::specie
49 (
50  const scalar nMoles,
51  const scalar molWeight
52 )
53 :
54  nMoles_(nMoles),
55  molWeight_(molWeight)
56 {}
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
61 inline specie::specie(const specie& st)
62 :
63  name_(st.name_),
64  nMoles_(st.nMoles_),
65  molWeight_(st.molWeight_)
66 {}
67 
68 
69 inline specie::specie(const word& name, const specie& st)
70 :
71  name_(name),
72  nMoles_(st.nMoles_),
73  molWeight_(st.molWeight_)
74 {}
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
79 inline const word& specie::name() const
80 {
81  return name_;
82 }
83 
84 
85 inline scalar specie::W() const
86 {
87  return molWeight_;
88 }
89 
90 
91 inline scalar specie::nMoles() const
92 {
93  return nMoles_;
94 }
95 
96 
97 inline scalar specie::R() const
98 {
99  return RR/molWeight_;
100 }
101 
102 
103 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
104 
105 inline void specie::operator=(const specie& st)
106 {
107  //name_ = st.name_;
108  nMoles_ = st.nMoles_;
109  molWeight_ = st.molWeight_;
110 }
111 
112 
113 inline void specie::operator+=(const specie& st)
114 {
115  scalar sumNmoles = max(nMoles_ + st.nMoles_, SMALL);
116 
117  molWeight_ =
118  nMoles_/sumNmoles*molWeight_
119  + st.nMoles_/sumNmoles*st.molWeight_;
120 
121  nMoles_ = sumNmoles;
122 }
123 
124 
125 inline void specie::operator-=(const specie& st)
126 {
127  scalar diffnMoles = nMoles_ - st.nMoles_;
128  if (mag(diffnMoles) < SMALL)
129  {
130  diffnMoles = SMALL;
131  }
132 
133  molWeight_ =
134  nMoles_/diffnMoles*molWeight_
135  - st.nMoles_/diffnMoles*st.molWeight_;
136 
137  nMoles_ = diffnMoles;
138 }
139 
140 
141 inline void specie::operator*=(const scalar s)
142 {
143  nMoles_ *= s;
144 }
145 
146 
147 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
148 
149 inline specie operator+(const specie& st1, const specie& st2)
150 {
151  scalar sumNmoles = max(st1.nMoles_ + st2.nMoles_, SMALL);
152 
153  return specie
154  (
155  sumNmoles,
156  st1.nMoles_/sumNmoles*st1.molWeight_
157  + st2.nMoles_/sumNmoles*st2.molWeight_
158  );
159 }
160 
161 
162 inline specie operator-(const specie& st1, const specie& st2)
163 {
164  scalar diffNmoles = st1.nMoles_ - st2.nMoles_;
165  if (mag(diffNmoles) < SMALL)
166  {
167  diffNmoles = SMALL;
168  }
169 
170  return specie
171  (
172  diffNmoles,
173  st1.nMoles_/diffNmoles*st1.molWeight_
174  - st2.nMoles_/diffNmoles*st2.molWeight_
175  );
176 }
177 
178 
179 inline specie operator*(const scalar s, const specie& st)
180 {
181  return specie
182  (
183  s*st.nMoles_,
184  st.molWeight_
185  );
186 }
187 
188 
189 inline specie operator==(const specie& st1, const specie& st2)
190 {
191  return st2 - st1;
192 }
193 
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace Foam
198 
199 // ************************************************************************* //
void operator=(const specie &)
Definition: specieI.H:105
void operator*=(const scalar)
Definition: specieI.H:141
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
friend specie operator-(const specie &, const specie &)
Definition: specieI.H:162
friend specie operator==(const specie &, const specie &)
Definition: specieI.H:189
Base class of the thermophysical property types.
Definition: specie.H:66
void operator-=(const specie &)
Definition: specieI.H:125
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().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))
friend specie operator*(const scalar, const specie &)
Definition: specieI.H:179
A class for handling words, derived from string.
Definition: word.H:59
friend specie operator+(const specie &, const specie &)
Definition: specieI.H:149
scalar R() const
Gas constant [J/(kg K)].
Definition: specieI.H:97
scalar nMoles() const
No of moles of this species in mixture.
Definition: specieI.H:91
scalar W() const
Molecular weight [kg/kmol].
Definition: specieI.H:85
specie(const scalar nMoles, const scalar molWeight)
Construct from components without name.
Definition: specieI.H:49
dimensioned< scalar > mag(const dimensioned< Type > &)
const scalar RR
Universal gas constant (default in [J/(kmol K)])
void operator+=(const specie &)
Definition: specieI.H:113
const word & name() const
Name.
Definition: specieI.H:79
Namespace for OpenFOAM.