1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
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 const typename Foam::janafThermo<EquationOfState>::coeffArray&
57 Foam::janafThermo<EquationOfState>::coeffs
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 template<class EquationOfState>
76 inline Foam::janafThermo<EquationOfState>::janafThermo
82 EquationOfState(name, jt),
87 for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
89 highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
90 lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 template<class EquationOfState>
98 inline Foam::scalar Foam::janafThermo<EquationOfState>::limit
103 if (T < Tlow_ || T > Thigh_)
107 "janafThermo<EquationOfState>::limit(const scalar T) const"
108 ) << "attempt to use janafThermo<EquationOfState>"
109 " out of temperature range "
110 << Tlow_ << " -> " << Thigh_ << "; T = " << T
113 return min(max(T, Tlow_), Thigh_);
122 template<class EquationOfState>
123 inline Foam::scalar Foam::janafThermo<EquationOfState>::cp
128 const coeffArray& a = coeffs(T);
129 return this->RR*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]);
133 template<class EquationOfState>
134 inline Foam::scalar Foam::janafThermo<EquationOfState>::h
139 const coeffArray& a = coeffs(T);
142 ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
148 template<class EquationOfState>
149 inline Foam::scalar Foam::janafThermo<EquationOfState>::hs
158 template<class EquationOfState>
159 inline Foam::scalar Foam::janafThermo<EquationOfState>::hc() const
161 const coeffArray& a = lowCpCoeffs_;
162 const scalar Tstd = specie::Tstd;
166 (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd
173 template<class EquationOfState>
174 inline Foam::scalar Foam::janafThermo<EquationOfState>::s
179 const coeffArray& a = coeffs(T);
183 (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
189 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
191 template<class EquationOfState>
192 inline void Foam::janafThermo<EquationOfState>::operator+=
194 const janafThermo<EquationOfState>& jt
197 scalar molr1 = this->nMoles();
199 EquationOfState::operator+=(jt);
201 molr1 /= this->nMoles();
202 scalar molr2 = jt.nMoles()/this->nMoles();
204 Tlow_ = max(Tlow_, jt.Tlow_);
205 Thigh_ = min(Thigh_, jt.Thigh_);
207 if (notEqual(Tcommon_, jt.Tcommon_))
211 "janafThermo<EquationOfState>::operator+="
212 "(const janafThermo<EquationOfState>& jt) const"
213 ) << "Tcommon " << Tcommon_ << " for "
214 << (this->name().size() ? this->name() : "others")
215 << " != " << jt.Tcommon_ << " for "
216 << (jt.name().size() ? jt.name() : "others")
222 register label coefLabel=0;
223 coefLabel<janafThermo<EquationOfState>::nCoeffs_;
227 highCpCoeffs_[coefLabel] =
228 molr1*highCpCoeffs_[coefLabel]
229 + molr2*jt.highCpCoeffs_[coefLabel];
231 lowCpCoeffs_[coefLabel] =
232 molr1*lowCpCoeffs_[coefLabel]
233 + molr2*jt.lowCpCoeffs_[coefLabel];
238 template<class EquationOfState>
239 inline void Foam::janafThermo<EquationOfState>::operator-=
241 const janafThermo<EquationOfState>& jt
244 scalar molr1 = this->nMoles();
246 EquationOfState::operator-=(jt);
248 molr1 /= this->nMoles();
249 scalar molr2 = jt.nMoles()/this->nMoles();
251 Tlow_ = max(Tlow_, jt.Tlow_);
252 Thigh_ = min(Thigh_, jt.Thigh_);
254 if (notEqual(Tcommon_, jt.Tcommon_))
258 "janafThermo<EquationOfState>::operator-="
259 "(const janafThermo<EquationOfState>& jt) const"
260 ) << "Tcommon " << Tcommon_ << " for "
261 << (this->name().size() ? this->name() : "others")
262 << " != " << jt.Tcommon_ << " for "
263 << (jt.name().size() ? jt.name() : "others")
269 register label coefLabel=0;
270 coefLabel<janafThermo<EquationOfState>::nCoeffs_;
274 highCpCoeffs_[coefLabel] =
275 molr1*highCpCoeffs_[coefLabel]
276 - molr2*jt.highCpCoeffs_[coefLabel];
278 lowCpCoeffs_[coefLabel] =
279 molr1*lowCpCoeffs_[coefLabel]
280 - molr2*jt.lowCpCoeffs_[coefLabel];
285 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
287 template<class EquationOfState>
288 inline Foam::janafThermo<EquationOfState> Foam::operator+
290 const janafThermo<EquationOfState>& jt1,
291 const janafThermo<EquationOfState>& jt2
294 EquationOfState eofs = jt1;
297 scalar molr1 = jt1.nMoles()/eofs.nMoles();
298 scalar molr2 = jt2.nMoles()/eofs.nMoles();
300 typename janafThermo<EquationOfState>::coeffArray highCpCoeffs;
301 typename janafThermo<EquationOfState>::coeffArray lowCpCoeffs;
305 register label coefLabel=0;
306 coefLabel<janafThermo<EquationOfState>::nCoeffs_;
310 highCpCoeffs[coefLabel] =
311 molr1*jt1.highCpCoeffs_[coefLabel]
312 + molr2*jt2.highCpCoeffs_[coefLabel];
314 lowCpCoeffs[coefLabel] =
315 molr1*jt1.lowCpCoeffs_[coefLabel]
316 + molr2*jt2.lowCpCoeffs_[coefLabel];
319 if (notEqual(jt1.Tcommon_, jt2.Tcommon_))
324 "(const janafThermo<EquationOfState>& jt1,"
325 " const janafThermo<EquationOfState>& jt2)"
326 ) << "Tcommon " << jt1.Tcommon_ << " for "
327 << (jt1.name().size() ? jt1.name() : "others")
328 << " != " << jt2.Tcommon_ << " for "
329 << (jt2.name().size() ? jt2.name() : "others")
333 return janafThermo<EquationOfState>
336 max(jt1.Tlow_, jt2.Tlow_),
337 min(jt1.Thigh_, jt2.Thigh_),
345 template<class EquationOfState>
346 inline Foam::janafThermo<EquationOfState> Foam::operator-
348 const janafThermo<EquationOfState>& jt1,
349 const janafThermo<EquationOfState>& jt2
352 EquationOfState eofs = jt1;
355 scalar molr1 = jt1.nMoles()/eofs.nMoles();
356 scalar molr2 = jt2.nMoles()/eofs.nMoles();
358 typename janafThermo<EquationOfState>::coeffArray highCpCoeffs;
359 typename janafThermo<EquationOfState>::coeffArray lowCpCoeffs;
363 register label coefLabel=0;
364 coefLabel<janafThermo<EquationOfState>::nCoeffs_;
368 highCpCoeffs[coefLabel] =
369 molr1*jt1.highCpCoeffs_[coefLabel]
370 - molr2*jt2.highCpCoeffs_[coefLabel];
372 lowCpCoeffs[coefLabel] =
373 molr1*jt1.lowCpCoeffs_[coefLabel]
374 - molr2*jt2.lowCpCoeffs_[coefLabel];
377 if (notEqual(jt1.Tcommon_, jt2.Tcommon_))
382 "(const janafThermo<EquationOfState>& jt1,"
383 " const janafThermo<EquationOfState>& jt2)"
384 ) << "Tcommon " << jt1.Tcommon_ << " for "
385 << (jt1.name().size() ? jt1.name() : "others")
386 << " != " << jt2.Tcommon_ << " for "
387 << (jt2.name().size() ? jt2.name() : "others")
391 return janafThermo<EquationOfState>
394 max(jt1.Tlow_, jt2.Tlow_),
395 min(jt1.Thigh_, jt2.Thigh_),
403 template<class EquationOfState>
404 inline Foam::janafThermo<EquationOfState> Foam::operator*
407 const janafThermo<EquationOfState>& jt
410 return janafThermo<EquationOfState>
412 s*static_cast<const EquationOfState&>(jt),
422 template<class EquationOfState>
423 inline Foam::janafThermo<EquationOfState> Foam::operator==
425 const janafThermo<EquationOfState>& jt1,
426 const janafThermo<EquationOfState>& jt2
433 // ************************************************************************* //