FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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/specie.H>
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 // Construct from components
36 inline specie::specie
37 (
38  const word& name,
39  const scalar nMoles,
40  const scalar molWeight
41 )
42 :
43  name_(name),
44  nMoles_(nMoles),
45  molWeight_(molWeight)
46 {}
47 
48 
49 // Construct from components without name
50 inline specie::specie
51 (
52  const scalar nMoles,
53  const scalar molWeight
54 )
55 :
56  //name_(),
57  nMoles_(nMoles),
58  molWeight_(molWeight)
59 {}
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
64 // Construct as copy
65 inline specie::specie(const specie& st)
66 :
67  name_(st.name_),
68  nMoles_(st.nMoles_),
69  molWeight_(st.molWeight_)
70 {}
71 
72 
73 // Construct as named copy
74 inline specie::specie(const word& name, const specie& st)
75 :
76  name_(name),
77  nMoles_(st.nMoles_),
78  molWeight_(st.molWeight_)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
84 //- Molecular weight [kg/kmol]
85 inline scalar specie::W() const
86 {
87  return molWeight_;
88 }
89 
90 //- No of moles of this species in mixture
91 inline scalar specie::nMoles() const
92 {
93  return nMoles_;
94 }
95 
96 //- Gas constant [J/(kg K)]
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 // ************************ vim: set sw=4 sts=4 et: ************************ //