FreeFOAM The Cross-Platform CFD Toolkit
janafThermoI.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 "janafThermo.H"
27 #include <specie/specie.H>
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class equationOfState>
33 (
34  const equationOfState& st,
35  const scalar Tlow,
36  const scalar Thigh,
37  const scalar Tcommon,
38  const typename janafThermo<equationOfState>::coeffArray& highCpCoeffs,
39  const typename janafThermo<equationOfState>::coeffArray& lowCpCoeffs
40 )
41 :
42  equationOfState(st),
43  Tlow_(Tlow),
44  Thigh_(Thigh),
45  Tcommon_(Tcommon)
46 {
47  for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
48  {
49  highCpCoeffs_[coefLabel] = highCpCoeffs[coefLabel];
50  lowCpCoeffs_[coefLabel] = lowCpCoeffs[coefLabel];
51  }
52 }
53 
54 
55 template<class equationOfState>
56 inline void Foam::janafThermo<equationOfState>::checkT(const scalar T) const
57 {
58  if (T < Tlow_ || T > Thigh_)
59  {
61  (
62  "janafThermo<equationOfState>::checkT(const scalar T) const"
63  ) << "attempt to use janafThermo<equationOfState>"
64  " out of temperature range "
65  << Tlow_ << " -> " << Thigh_ << "; T = " << T
66  << abort(FatalError);
67  }
68 }
69 
70 
71 template<class equationOfState>
74 (
75  const scalar T
76 ) const
77 {
78  checkT(T);
79 
80  if (T < Tcommon_)
81  {
82  return lowCpCoeffs_;
83  }
84  else
85  {
86  return highCpCoeffs_;
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
93 template<class equationOfState>
95 (
96  const word& name,
97  const janafThermo& jt
98 )
99 :
100  equationOfState(name, jt),
101  Tlow_(jt.Tlow_),
102  Thigh_(jt.Thigh_),
103  Tcommon_(jt.Tcommon_)
104 {
105  for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
106  {
107  highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
108  lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
115 template<class equationOfState>
116 inline Foam::scalar Foam::janafThermo<equationOfState>::cp
117 (
118  const scalar T
119 ) const
120 {
121  const coeffArray& a = coeffs(T);
122  return this->RR*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]);
123 }
124 
125 
126 template<class equationOfState>
127 inline Foam::scalar Foam::janafThermo<equationOfState>::h
128 (
129  const scalar T
130 ) const
131 {
132  const coeffArray& a = coeffs(T);
133  return this->RR*
134  (
135  ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
136  + a[5]
137  );
138 }
139 
140 
141 template<class equationOfState>
142 inline Foam::scalar Foam::janafThermo<equationOfState>::hs
143 (
144  const scalar T
145 ) const
146 {
147  return h(T) - hc();
148 }
149 
150 
151 template<class equationOfState>
152 inline Foam::scalar Foam::janafThermo<equationOfState>::hc() const
153 {
154  const coeffArray& a = lowCpCoeffs_;
155  const scalar& Tstd = specie::Tstd;
156  return this->RR*
157  (
158  (
159  (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd
160  + a[0]
161  )*Tstd + a[5]
162  );
163 }
164 
165 
166 template<class equationOfState>
167 inline Foam::scalar Foam::janafThermo<equationOfState>::s
168 (
169  const scalar T
170 ) const
171 {
172  const coeffArray& a = coeffs(T);
173  return
174  this->RR*
175  (
176  (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
177  + a[6]
178  );
179 }
180 
181 
182 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
183 
184 template<class equationOfState>
186 (
188 )
189 {
190  scalar molr1 = this->nMoles();
191 
192  equationOfState::operator+=(jt);
193 
194  molr1 /= this->nMoles();
195  scalar molr2 = jt.nMoles()/this->nMoles();
196 
197  Tlow_ = max(Tlow_, jt.Tlow_);
198  Thigh_ = min(Thigh_, jt.Thigh_);
199  Tcommon_ = molr1*Tcommon_ + molr2*jt.Tcommon_;
200 
201  for
202  (
203  register label coefLabel=0;
204  coefLabel<janafThermo<equationOfState>::nCoeffs_;
205  coefLabel++
206  )
207  {
208  highCpCoeffs_[coefLabel] =
209  molr1*highCpCoeffs_[coefLabel]
210  + molr2*jt.highCpCoeffs_[coefLabel];
211 
212  lowCpCoeffs_[coefLabel] =
213  molr1*lowCpCoeffs_[coefLabel]
214  + molr2*jt.lowCpCoeffs_[coefLabel];
215  }
216 }
217 
218 
219 template<class equationOfState>
220 inline void Foam::janafThermo<equationOfState>::operator-=
221 (
223 )
224 {
225  scalar molr1 = this->nMoles();
226 
227  equationOfState::operator-=(jt);
228 
229  molr1 /= this->nMoles();
230  scalar molr2 = jt.nMoles()/this->nMoles();
231 
232  Tlow_ = max(Tlow_, jt.Tlow_);
233  Thigh_ = min(Thigh_, jt.Thigh_);
234  Tcommon_ = molr1*Tcommon_ - molr2*jt.Tcommon_;
235 
236  for
237  (
238  register label coefLabel=0;
239  coefLabel<janafThermo<equationOfState>::nCoeffs_;
240  coefLabel++
241  )
242  {
243  highCpCoeffs_[coefLabel] =
244  molr1*highCpCoeffs_[coefLabel]
245  - molr2*jt.highCpCoeffs_[coefLabel];
246 
247  lowCpCoeffs_[coefLabel] =
248  molr1*lowCpCoeffs_[coefLabel]
249  - molr2*jt.lowCpCoeffs_[coefLabel];
250  }
251 }
252 
253 
254 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
255 
256 template<class equationOfState>
257 inline Foam::janafThermo<equationOfState> Foam::operator+
258 (
259  const janafThermo<equationOfState>& jt1,
261 )
262 {
263  equationOfState eofs = jt1;
264  eofs += jt2;
265 
266  scalar molr1 = jt1.nMoles()/eofs.nMoles();
267  scalar molr2 = jt2.nMoles()/eofs.nMoles();
268 
269  typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
270  typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
271 
272  for
273  (
274  register label coefLabel=0;
275  coefLabel<janafThermo<equationOfState>::nCoeffs_;
276  coefLabel++
277  )
278  {
279  highCpCoeffs[coefLabel] =
280  molr1*jt1.highCpCoeffs_[coefLabel]
281  + molr2*jt2.highCpCoeffs_[coefLabel];
282 
283  lowCpCoeffs[coefLabel] =
284  molr1*jt1.lowCpCoeffs_[coefLabel]
285  + molr2*jt2.lowCpCoeffs_[coefLabel];
286  }
287 
289  (
290  eofs,
291  max(jt1.Tlow_, jt2.Tlow_),
292  min(jt1.Thigh_, jt2.Thigh_),
293  molr1*jt1.Tcommon_ + molr2*jt2.Tcommon_,
294  highCpCoeffs,
295  lowCpCoeffs
296  );
297 }
298 
299 
300 template<class equationOfState>
301 inline Foam::janafThermo<equationOfState> Foam::operator-
302 (
303  const janafThermo<equationOfState>& jt1,
305 )
306 {
307  equationOfState eofs = jt1;
308  eofs -= jt2;
309 
310  scalar molr1 = jt1.nMoles()/eofs.nMoles();
311  scalar molr2 = jt2.nMoles()/eofs.nMoles();
312 
313  typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
314  typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
315 
316  for
317  (
318  register label coefLabel=0;
319  coefLabel<janafThermo<equationOfState>::nCoeffs_;
320  coefLabel++
321  )
322  {
323  highCpCoeffs[coefLabel] =
324  molr1*jt1.highCpCoeffs_[coefLabel]
325  - molr2*jt2.highCpCoeffs_[coefLabel];
326 
327  lowCpCoeffs[coefLabel] =
328  molr1*jt1.lowCpCoeffs_[coefLabel]
329  - molr2*jt2.lowCpCoeffs_[coefLabel];
330  }
331 
333  (
334  eofs,
335  max(jt1.Tlow_, jt2.Tlow_),
336  min(jt1.Thigh_, jt2.Thigh_),
337  molr1*jt1.Tcommon_ - molr2*jt2.Tcommon_,
338  highCpCoeffs,
339  lowCpCoeffs
340  );
341 }
342 
343 
344 template<class equationOfState>
345 inline Foam::janafThermo<equationOfState> Foam::operator*
346 (
347  const scalar s,
349 )
350 {
352  (
353  s*static_cast<const equationOfState&>(jt),
354  jt.Tlow_,
355  jt.Thigh_,
356  jt.Tcommon_,
357  jt.highCpCoeffs_,
358  jt.lowCpCoeffs_
359  );
360 }
361 
362 
363 template<class equationOfState>
364 inline Foam::janafThermo<equationOfState> Foam::operator==
365 (
366  const janafThermo<equationOfState>& jt1,
368 )
369 {
370  return jt2 - jt1;
371 }
372 
373 
374 // ************************ vim: set sw=4 sts=4 et: ************************ //