1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "janafThermo.H"
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 template<class equationOfState>
32 inline Foam::janafThermo<equationOfState>::janafThermo
34 const equationOfState& st,
38 const typename janafThermo<equationOfState>::coeffArray& highCpCoeffs,
39 const typename janafThermo<equationOfState>::coeffArray& lowCpCoeffs
47 for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
49 highCpCoeffs_[coefLabel] = highCpCoeffs[coefLabel];
50 lowCpCoeffs_[coefLabel] = lowCpCoeffs[coefLabel];
55 template<class equationOfState>
56 inline void Foam::janafThermo<equationOfState>::checkT(scalar& T) const
58 if (T < Tlow_ || T > Thigh_)
60 // Improvements: graceful exit with recovery. HJ, 11/Oct/2010
63 "janafThermo<equationOfState>::checkT(scalar& T) const"
64 ) << "attempt to use janafThermo<equationOfState>"
65 " out of temperature range "
66 << Tlow_ << " -> " << Thigh_ << "; T = " << T
69 // Bracket T to avoid out-of-range error
70 T = Foam::min(Thigh_, Foam::max(T, Tlow_));
75 template<class equationOfState>
76 inline const typename Foam::janafThermo<equationOfState>::coeffArray&
77 Foam::janafThermo<equationOfState>::coeffs
82 // Note: T will be bounded by checkT in coeffs(T). No longer const
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 template<class equationOfState>
100 inline Foam::janafThermo<equationOfState>::janafThermo
103 const janafThermo& jt
106 equationOfState(name, jt),
109 Tcommon_(jt.Tcommon_)
111 for (register label coefLabel = 0; coefLabel < nCoeffs_; coefLabel++)
113 highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
114 lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 template<class equationOfState>
122 inline Foam::scalar Foam::janafThermo<equationOfState>::cp
127 const coeffArray& a = coeffs(T);
128 return this->RR()*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]);
132 template<class equationOfState>
133 inline Foam::scalar Foam::janafThermo<equationOfState>::h
138 const coeffArray& a = coeffs(T);
141 ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
147 template<class equationOfState>
148 inline Foam::scalar Foam::janafThermo<equationOfState>::hs
157 template<class equationOfState>
158 inline Foam::scalar Foam::janafThermo<equationOfState>::hc() const
160 const coeffArray& a = lowCpCoeffs_;
161 const scalar& Tstd = specie::Tstd();
165 (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd
172 template<class equationOfState>
173 inline Foam::scalar Foam::janafThermo<equationOfState>::s
178 // Note: T will be bounded by checkT in coeffs(T). No longer const
181 const coeffArray& a = coeffs(T);
185 (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
191 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
193 template<class equationOfState>
194 inline void Foam::janafThermo<equationOfState>::operator+=
196 const janafThermo<equationOfState>& jt
199 scalar molr1 = this->nMoles();
201 equationOfState::operator+=(jt);
203 molr1 /= this->nMoles();
204 scalar molr2 = jt.nMoles()/this->nMoles();
206 Tlow_ = max(Tlow_, jt.Tlow_);
207 Thigh_ = min(Thigh_, jt.Thigh_);
208 Tcommon_ = molr1*Tcommon_ + molr2*jt.Tcommon_;
212 register label coefLabel=0;
213 coefLabel<janafThermo<equationOfState>::nCoeffs_;
217 highCpCoeffs_[coefLabel] =
218 molr1*highCpCoeffs_[coefLabel]
219 + molr2*jt.highCpCoeffs_[coefLabel];
221 lowCpCoeffs_[coefLabel] =
222 molr1*lowCpCoeffs_[coefLabel]
223 + molr2*jt.lowCpCoeffs_[coefLabel];
228 template<class equationOfState>
229 inline void Foam::janafThermo<equationOfState>::operator-=
231 const janafThermo<equationOfState>& jt
234 scalar molr1 = this->nMoles();
236 equationOfState::operator-=(jt);
238 molr1 /= this->nMoles();
239 scalar molr2 = jt.nMoles()/this->nMoles();
241 Tlow_ = max(Tlow_, jt.Tlow_);
242 Thigh_ = min(Thigh_, jt.Thigh_);
243 Tcommon_ = molr1*Tcommon_ - molr2*jt.Tcommon_;
247 register label coefLabel=0;
248 coefLabel<janafThermo<equationOfState>::nCoeffs_;
252 highCpCoeffs_[coefLabel] =
253 molr1*highCpCoeffs_[coefLabel]
254 - molr2*jt.highCpCoeffs_[coefLabel];
256 lowCpCoeffs_[coefLabel] =
257 molr1*lowCpCoeffs_[coefLabel]
258 - molr2*jt.lowCpCoeffs_[coefLabel];
263 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
265 template<class equationOfState>
266 inline Foam::janafThermo<equationOfState> Foam::operator+
268 const janafThermo<equationOfState>& jt1,
269 const janafThermo<equationOfState>& jt2
272 equationOfState eofs = jt1;
275 scalar molr1 = jt1.nMoles()/eofs.nMoles();
276 scalar molr2 = jt2.nMoles()/eofs.nMoles();
278 typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
279 typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
283 register label coefLabel=0;
284 coefLabel<janafThermo<equationOfState>::nCoeffs_;
288 highCpCoeffs[coefLabel] =
289 molr1*jt1.highCpCoeffs_[coefLabel]
290 + molr2*jt2.highCpCoeffs_[coefLabel];
292 lowCpCoeffs[coefLabel] =
293 molr1*jt1.lowCpCoeffs_[coefLabel]
294 + molr2*jt2.lowCpCoeffs_[coefLabel];
297 return janafThermo<equationOfState>
300 max(jt1.Tlow_, jt2.Tlow_),
301 min(jt1.Thigh_, jt2.Thigh_),
302 molr1*jt1.Tcommon_ + molr2*jt2.Tcommon_,
309 template<class equationOfState>
310 inline Foam::janafThermo<equationOfState> Foam::operator-
312 const janafThermo<equationOfState>& jt1,
313 const janafThermo<equationOfState>& jt2
316 equationOfState eofs = jt1;
319 scalar molr1 = jt1.nMoles()/eofs.nMoles();
320 scalar molr2 = jt2.nMoles()/eofs.nMoles();
322 typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
323 typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
327 register label coefLabel=0;
328 coefLabel<janafThermo<equationOfState>::nCoeffs_;
332 highCpCoeffs[coefLabel] =
333 molr1*jt1.highCpCoeffs_[coefLabel]
334 - molr2*jt2.highCpCoeffs_[coefLabel];
336 lowCpCoeffs[coefLabel] =
337 molr1*jt1.lowCpCoeffs_[coefLabel]
338 - molr2*jt2.lowCpCoeffs_[coefLabel];
341 return janafThermo<equationOfState>
344 max(jt1.Tlow_, jt2.Tlow_),
345 min(jt1.Thigh_, jt2.Thigh_),
346 molr1*jt1.Tcommon_ - molr2*jt2.Tcommon_,
353 template<class equationOfState>
354 inline Foam::janafThermo<equationOfState> Foam::operator*
357 const janafThermo<equationOfState>& jt
360 return janafThermo<equationOfState>
362 s*static_cast<const equationOfState&>(jt),
372 template<class equationOfState>
373 inline Foam::janafThermo<equationOfState> Foam::operator==
375 const janafThermo<equationOfState>& jt1,
376 const janafThermo<equationOfState>& jt2
383 // ************************************************************************* //