FreeFOAM The Cross-Platform CFD Toolkit
specieThermoI.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 "specieThermo.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class thermo>
32 (
33  const thermo& sp
34 )
35 :
36  thermo(sp)
37 {}
38 
39 
40 template<class thermo>
41 inline Foam::scalar Foam::specieThermo<thermo>::T
42 (
43  scalar f,
44  scalar T0,
45  scalar (specieThermo<thermo>::*F)(const scalar) const,
46  scalar (specieThermo<thermo>::*dFdT)(const scalar) const
47 ) const
48 {
49  scalar Test = T0;
50  scalar Tnew = T0;
51  scalar Ttol = T0*tol_;
52  int iter = 0;
53 
54  do
55  {
56  Test = Tnew;
57  Tnew = Test - ((this->*F)(Test) - f)/(this->*dFdT)(Test);
58 
59  if (iter++ > maxIter_)
60  {
62  (
63  "specieThermo<thermo>::T(scalar f, scalar T0, "
64  "scalar (specieThermo<thermo>::*F)(const scalar) const, "
65  "scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
66  ") const"
67  ) << "Maximum number of iterations exceeded"
68  << abort(FatalError);
69  }
70 
71  } while (mag(Tnew - Test) > Ttol);
72 
73  return Tnew;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
79 template<class thermo>
81 (
82  const word& name,
83  const specieThermo& st
84 )
85 :
86  thermo(name, st)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
92 template<class thermo>
93 inline Foam::scalar Foam::specieThermo<thermo>::cv(const scalar T) const
94 {
95  return this->cp(T) - this->RR;
96 }
97 
98 
99 template<class thermo>
100 inline Foam::scalar Foam::specieThermo<thermo>::gamma(const scalar T) const
101 {
102  scalar CP = this->cp(T);
103  return CP/(CP - this->RR);
104 }
105 
106 
107 template<class thermo>
108 inline Foam::scalar Foam::specieThermo<thermo>::e(const scalar T) const
109 {
110  return this->h(T) - this->RR*(T - this->Tstd);
111 }
112 
113 
114 template<class thermo>
115 inline Foam::scalar Foam::specieThermo<thermo>::es(const scalar T) const
116 {
117  return this->hs(T) - this->RR*(T - this->Tstd);
118 }
119 
120 
121 template<class thermo>
122 inline Foam::scalar Foam::specieThermo<thermo>::g(const scalar T) const
123 {
124  return this->h(T) - T*this->s(T);
125 }
126 
127 
128 template<class thermo>
129 inline Foam::scalar Foam::specieThermo<thermo>::a(const scalar T) const
130 {
131  return this->e(T) - T*this->s(T);
132 }
133 
134 
135 template<class thermo>
136 inline Foam::scalar Foam::specieThermo<thermo>::Cp(const scalar T) const
137 {
138  return this->cp(T)/this->W();
139 }
140 
141 
142 template<class thermo>
143 inline Foam::scalar Foam::specieThermo<thermo>::Cv(const scalar T) const
144 {
145  return this->cv(T)/this->W();
146 }
147 
148 
149 template<class thermo>
150 inline Foam::scalar Foam::specieThermo<thermo>::H(const scalar T) const
151 {
152  return this->h(T)/this->W();
153 }
154 
155 
156 template<class thermo>
157 inline Foam::scalar Foam::specieThermo<thermo>::Hs(const scalar T) const
158 {
159  return this->hs(T)/this->W();
160 }
161 
162 
163 template<class thermo>
164 inline Foam::scalar Foam::specieThermo<thermo>::Hc() const
165 {
166  return this->hc()/this->W();
167 }
168 
169 
170 template<class thermo>
171 inline Foam::scalar Foam::specieThermo<thermo>::S(const scalar T) const
172 {
173  return this->s(T)/this->W();
174 }
175 
176 
177 template<class thermo>
178 inline Foam::scalar Foam::specieThermo<thermo>::E(const scalar T) const
179 {
180  return this->e(T)/this->W();
181 }
182 
183 
184 template<class thermo>
185 inline Foam::scalar Foam::specieThermo<thermo>::G(const scalar T) const
186 {
187  return this->g(T)/this->W();
188 }
189 
190 
191 template<class thermo>
192 inline Foam::scalar Foam::specieThermo<thermo>::A(const scalar T) const
193 {
194  return this->a(T)/this->W();
195 }
196 
197 
198 template<class thermo>
199 inline Foam::scalar Foam::specieThermo<thermo>::K(const scalar T) const
200 {
201  scalar arg = -this->nMoles()*this->g(T)/(this->RR*T);
202 
203  if (arg < 600.0)
204  {
205  return ::exp(arg);
206  }
207  else
208  {
209  return VGREAT;
210  }
211 }
212 
213 
214 template<class thermo>
215 inline Foam::scalar Foam::specieThermo<thermo>::Kp(const scalar T) const
216 {
217  return K(T);
218 }
219 
220 
221 template<class thermo>
222 inline Foam::scalar Foam::specieThermo<thermo>::Kc(const scalar T) const
223 {
224  if (equal(this->nMoles(), SMALL))
225  {
226  return Kp(T);
227  }
228  else
229  {
230  return Kp(T)*pow(this->Pstd/(this->RR*T), this->nMoles());
231  }
232 }
233 
234 
235 template<class thermo>
236 inline Foam::scalar Foam::specieThermo<thermo>::Kx
237 (
238  const scalar T,
239  const scalar p
240 ) const
241 {
242  if (equal(this->nMoles(), SMALL))
243  {
244  return Kp(T);
245  }
246  else
247  {
248  return Kp(T)*pow(this->Pstd/p, this->nMoles());
249  }
250 }
251 
252 
253 template<class thermo>
254 inline Foam::scalar Foam::specieThermo<thermo>::Kn
255 (
256  const scalar T,
257  const scalar p,
258  const scalar n
259 ) const
260 {
261  if (equal(this->nMoles(), SMALL))
262  {
263  return Kp(T);
264  }
265  else
266  {
267  return Kp(T)*pow(n*this->Pstd/p, this->nMoles());
268  }
269 }
270 
271 
272 template<class thermo>
273 inline Foam::scalar Foam::specieThermo<thermo>::TH
274 (
275  const scalar h,
276  const scalar T0
277 ) const
278 {
280 }
281 
282 
283 template<class thermo>
284 inline Foam::scalar Foam::specieThermo<thermo>::THs
285 (
286  const scalar hs,
287  const scalar T0
288 ) const
289 {
291 }
292 
293 
294 template<class thermo>
295 inline Foam::scalar Foam::specieThermo<thermo>::TE
296 (
297  const scalar e,
298  const scalar T0
299 ) const
300 {
302 }
303 
304 
305 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
306 
307 template<class thermo>
309 (
310  const specieThermo<thermo>& st
311 )
312 {
313  thermo::operator+=(st);
314 }
315 
316 template<class thermo>
317 inline void Foam::specieThermo<thermo>::operator-=
318 (
319  const specieThermo<thermo>& st
320 )
321 {
322  thermo::operator-=(st);
323 }
324 
325 template<class thermo>
326 inline void Foam::specieThermo<thermo>::operator*=(const scalar s)
327 {
328  thermo::operator*=(s);
329 }
330 
331 
332 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
333 
334 template<class thermo>
335 inline Foam::specieThermo<thermo> Foam::operator+
336 (
337  const specieThermo<thermo>& st1,
338  const specieThermo<thermo>& st2
339 )
340 {
341  return specieThermo<thermo>
342  (
343  static_cast<const thermo&>(st1) + static_cast<const thermo&>(st2)
344  );
345 }
346 
347 
348 template<class thermo>
349 inline Foam::specieThermo<thermo> Foam::operator-
350 (
351  const specieThermo<thermo>& st1,
352  const specieThermo<thermo>& st2
353 )
354 {
355  return specieThermo<thermo>
356  (
357  static_cast<const thermo&>(st1) - static_cast<const thermo&>(st2)
358  );
359 }
360 
361 
362 template<class thermo>
363 inline Foam::specieThermo<thermo> Foam::operator*
364 (
365  const scalar s,
366  const specieThermo<thermo>& st
367 )
368 {
369  return specieThermo<thermo>
370  (
371  s*static_cast<const thermo&>(st)
372  );
373 }
374 
375 
376 template<class thermo>
377 inline Foam::specieThermo<thermo> Foam::operator==
378 (
379  const specieThermo<thermo>& st1,
380  const specieThermo<thermo>& st2
381 )
382 {
383  return st2 - st1;
384 }
385 
386 
387 // ************************ vim: set sw=4 sts=4 et: ************************ //