Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / thermophysicalModels / specie / thermo / janaf / janafThermoI.H
blobb31ca04b97ede0f938c148cba5e63268c2292bc2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
27 #include "specie.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 template<class equationOfState>
32 inline Foam::janafThermo<equationOfState>::janafThermo
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
42     equationOfState(st),
43     Tlow_(Tlow),
44     Thigh_(Thigh),
45     Tcommon_(Tcommon)
47     for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
48     {
49         highCpCoeffs_[coefLabel] = highCpCoeffs[coefLabel];
50         lowCpCoeffs_[coefLabel] = lowCpCoeffs[coefLabel];
51     }
55 template<class equationOfState>
56 inline void Foam::janafThermo<equationOfState>::checkT(scalar& T) const
58     if (T <  Tlow_ || T > Thigh_)
59     {
60         // Improvements: graceful exit with recovery.  HJ, 11/Oct/2010
61         InfoIn
62         (
63             "janafThermo<equationOfState>::checkT(scalar& T) const"
64         )   << "attempt to use janafThermo<equationOfState>"
65                " out of temperature range "
66             << Tlow_ << " -> " << Thigh_ << ";  T = " << T
67             << endl;
69         // Bracket T to avoid out-of-range error
70         T = Foam::min(Thigh_, Foam::max(T, Tlow_));
71     }
75 template<class equationOfState>
76 inline const typename Foam::janafThermo<equationOfState>::coeffArray&
77 Foam::janafThermo<equationOfState>::coeffs
79     scalar& T
80 ) const
82     // Note: T will be bounded by checkT in coeffs(T).  No longer const
83     // HJ, 12/Oct/2010
84     checkT(T);
86     if (T < Tcommon_)
87     {
88         return lowCpCoeffs_;
89     }
90     else
91     {
92         return highCpCoeffs_;
93     }
97 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
99 template<class equationOfState>
100 inline Foam::janafThermo<equationOfState>::janafThermo
102     const word& name,
103     const janafThermo& jt
106     equationOfState(name, jt),
107     Tlow_(jt.Tlow_),
108     Thigh_(jt.Thigh_),
109     Tcommon_(jt.Tcommon_)
111     for (register label coefLabel = 0; coefLabel < nCoeffs_; coefLabel++)
112     {
113         highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
114         lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
115     }
119 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
121 template<class equationOfState>
122 inline Foam::scalar Foam::janafThermo<equationOfState>::cp
124     scalar T
125 ) const
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
135     scalar T
136 ) const
138     const coeffArray& a = coeffs(T);
139     return this->RR()*
140     (
141         ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
142       + a[5]
143     );
147 template<class equationOfState>
148 inline Foam::scalar Foam::janafThermo<equationOfState>::hs
150     scalar T
151 ) const
153     return h(T) - hc();
157 template<class equationOfState>
158 inline Foam::scalar Foam::janafThermo<equationOfState>::hc() const
160     const coeffArray& a = lowCpCoeffs_;
161     const scalar& Tstd = specie::Tstd();
162     return this->RR()*
163     (
164         (
165             (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd
166           + a[0]
167         )*Tstd + a[5]
168     );
172 template<class equationOfState>
173 inline Foam::scalar Foam::janafThermo<equationOfState>::s
175     scalar T
176 ) const
178     // Note: T will be bounded by checkT in coeffs(T).  No longer const
179     // HJ, 12/Oct/2010
181     const coeffArray& a = coeffs(T);
182     return
183     this->RR()*
184     (
185         (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
186       + a[6]
187     );
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_;
210     for
211     (
212         register label coefLabel=0;
213         coefLabel<janafThermo<equationOfState>::nCoeffs_;
214         coefLabel++
215     )
216     {
217         highCpCoeffs_[coefLabel] =
218             molr1*highCpCoeffs_[coefLabel]
219           + molr2*jt.highCpCoeffs_[coefLabel];
221         lowCpCoeffs_[coefLabel] =
222             molr1*lowCpCoeffs_[coefLabel]
223           + molr2*jt.lowCpCoeffs_[coefLabel];
224     }
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_;
245     for
246     (
247         register label coefLabel=0;
248         coefLabel<janafThermo<equationOfState>::nCoeffs_;
249         coefLabel++
250     )
251     {
252         highCpCoeffs_[coefLabel] =
253             molr1*highCpCoeffs_[coefLabel]
254           - molr2*jt.highCpCoeffs_[coefLabel];
256         lowCpCoeffs_[coefLabel] =
257             molr1*lowCpCoeffs_[coefLabel]
258           - molr2*jt.lowCpCoeffs_[coefLabel];
259     }
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;
273     eofs += jt2;
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;
281     for
282     (
283         register label coefLabel=0;
284         coefLabel<janafThermo<equationOfState>::nCoeffs_;
285         coefLabel++
286     )
287     {
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];
295     }
297     return janafThermo<equationOfState>
298     (
299         eofs,
300         max(jt1.Tlow_, jt2.Tlow_),
301         min(jt1.Thigh_, jt2.Thigh_),
302         molr1*jt1.Tcommon_ + molr2*jt2.Tcommon_,
303         highCpCoeffs,
304         lowCpCoeffs
305     );
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;
317     eofs -= jt2;
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;
325     for
326     (
327         register label coefLabel=0;
328         coefLabel<janafThermo<equationOfState>::nCoeffs_;
329         coefLabel++
330     )
331     {
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];
339     }
341     return janafThermo<equationOfState>
342     (
343         eofs,
344         max(jt1.Tlow_, jt2.Tlow_),
345         min(jt1.Thigh_, jt2.Thigh_),
346         molr1*jt1.Tcommon_ - molr2*jt2.Tcommon_,
347         highCpCoeffs,
348         lowCpCoeffs
349     );
353 template<class equationOfState>
354 inline Foam::janafThermo<equationOfState> Foam::operator*
356     const scalar s,
357     const janafThermo<equationOfState>& jt
360     return janafThermo<equationOfState>
361     (
362         s*static_cast<const equationOfState&>(jt),
363         jt.Tlow_,
364         jt.Thigh_,
365         jt.Tcommon_,
366         jt.highCpCoeffs_,
367         jt.lowCpCoeffs_
368     );
372 template<class equationOfState>
373 inline Foam::janafThermo<equationOfState> Foam::operator==
375     const janafThermo<equationOfState>& jt1,
376     const janafThermo<equationOfState>& jt2
379     return jt2 - jt1;
383 // ************************************************************************* //