BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / specie / thermo / janaf / janafThermoI.H
blob2135d53e03cc2f13e280ad00923ddd40a51b3c56
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
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 const typename Foam::janafThermo<EquationOfState>::coeffArray&
57 Foam::janafThermo<EquationOfState>::coeffs
59     const scalar T
60 ) const
62     if (T < Tcommon_)
63     {
64         return lowCpCoeffs_;
65     }
66     else
67     {
68         return highCpCoeffs_;
69     }
73 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
75 template<class EquationOfState>
76 inline Foam::janafThermo<EquationOfState>::janafThermo
78     const word& name,
79     const janafThermo& jt
82     EquationOfState(name, jt),
83     Tlow_(jt.Tlow_),
84     Thigh_(jt.Thigh_),
85     Tcommon_(jt.Tcommon_)
87     for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
88     {
89         highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
90         lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
91     }
95 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
97 template<class EquationOfState>
98 inline Foam::scalar Foam::janafThermo<EquationOfState>::limit
100     const scalar T
101 ) const
103     if (T < Tlow_ || T > Thigh_)
104     {
105         WarningIn
106         (
107             "janafThermo<EquationOfState>::limit(const scalar T) const"
108         )   << "attempt to use janafThermo<EquationOfState>"
109                " out of temperature range "
110             << Tlow_ << " -> " << Thigh_ << ";  T = " << T
111             << endl;
113         return min(max(T, Tlow_), Thigh_);
114     }
115     else
116     {
117         return T;
118     }
122 template<class EquationOfState>
123 inline Foam::scalar Foam::janafThermo<EquationOfState>::cp
125     const scalar T
126 ) const
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
136     const scalar T
137 ) const
139     const coeffArray& a = coeffs(T);
140     return this->RR*
141     (
142         ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
143       + a[5]
144     );
148 template<class EquationOfState>
149 inline Foam::scalar Foam::janafThermo<EquationOfState>::hs
151     const scalar T
152 ) const
154     return h(T) - hc();
158 template<class EquationOfState>
159 inline Foam::scalar Foam::janafThermo<EquationOfState>::hc() const
161     const coeffArray& a = lowCpCoeffs_;
162     const scalar Tstd = specie::Tstd;
163     return this->RR*
164     (
165         (
166             (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd
167           + a[0]
168         )*Tstd + a[5]
169     );
173 template<class EquationOfState>
174 inline Foam::scalar Foam::janafThermo<EquationOfState>::s
176     const scalar T
177 ) const
179     const coeffArray& a = coeffs(T);
180     return
181     this->RR*
182     (
183         (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
184       + a[6]
185     );
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_))
208     {
209         FatalErrorIn
210         (
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")
217             << exit(FatalError);
218     }
220     for
221     (
222         register label coefLabel=0;
223         coefLabel<janafThermo<EquationOfState>::nCoeffs_;
224         coefLabel++
225     )
226     {
227         highCpCoeffs_[coefLabel] =
228             molr1*highCpCoeffs_[coefLabel]
229           + molr2*jt.highCpCoeffs_[coefLabel];
231         lowCpCoeffs_[coefLabel] =
232             molr1*lowCpCoeffs_[coefLabel]
233           + molr2*jt.lowCpCoeffs_[coefLabel];
234     }
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_))
255     {
256         FatalErrorIn
257         (
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")
264             << exit(FatalError);
265     }
267     for
268     (
269         register label coefLabel=0;
270         coefLabel<janafThermo<EquationOfState>::nCoeffs_;
271         coefLabel++
272     )
273     {
274         highCpCoeffs_[coefLabel] =
275             molr1*highCpCoeffs_[coefLabel]
276           - molr2*jt.highCpCoeffs_[coefLabel];
278         lowCpCoeffs_[coefLabel] =
279             molr1*lowCpCoeffs_[coefLabel]
280           - molr2*jt.lowCpCoeffs_[coefLabel];
281     }
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;
295     eofs += jt2;
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;
303     for
304     (
305         register label coefLabel=0;
306         coefLabel<janafThermo<EquationOfState>::nCoeffs_;
307         coefLabel++
308     )
309     {
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];
317     }
319     if (notEqual(jt1.Tcommon_, jt2.Tcommon_))
320     {
321         FatalErrorIn
322         (
323             "operator+"
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")
330             << exit(FatalError);
331     }
333     return janafThermo<EquationOfState>
334     (
335         eofs,
336         max(jt1.Tlow_, jt2.Tlow_),
337         min(jt1.Thigh_, jt2.Thigh_),
338         jt1.Tcommon_,
339         highCpCoeffs,
340         lowCpCoeffs
341     );
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;
353     eofs -= jt2;
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;
361     for
362     (
363         register label coefLabel=0;
364         coefLabel<janafThermo<EquationOfState>::nCoeffs_;
365         coefLabel++
366     )
367     {
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];
375     }
377     if (notEqual(jt1.Tcommon_, jt2.Tcommon_))
378     {
379         FatalErrorIn
380         (
381             "operator-"
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")
388             << exit(FatalError);
389     }
391     return janafThermo<EquationOfState>
392     (
393         eofs,
394         max(jt1.Tlow_, jt2.Tlow_),
395         min(jt1.Thigh_, jt2.Thigh_),
396         jt1.Tcommon_,
397         highCpCoeffs,
398         lowCpCoeffs
399     );
403 template<class EquationOfState>
404 inline Foam::janafThermo<EquationOfState> Foam::operator*
406     const scalar s,
407     const janafThermo<EquationOfState>& jt
410     return janafThermo<EquationOfState>
411     (
412         s*static_cast<const EquationOfState&>(jt),
413         jt.Tlow_,
414         jt.Thigh_,
415         jt.Tcommon_,
416         jt.highCpCoeffs_,
417         jt.lowCpCoeffs_
418     );
422 template<class EquationOfState>
423 inline Foam::janafThermo<EquationOfState> Foam::operator==
425     const janafThermo<EquationOfState>& jt1,
426     const janafThermo<EquationOfState>& jt2
429     return jt2 - jt1;
433 // ************************************************************************* //