OpenFOAM logo
Open Source CFD Toolkit

janafThermoI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     JANAF tables based thermodynamics package templated ito the equationOfState.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "janafThermo.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00038 
00039 // Construct from components
00040 template<class equationOfState>
00041 inline janafThermo<equationOfState>::janafThermo
00042 (
00043     const equationOfState& st,
00044     const scalar Tlow,
00045     const scalar Thigh,
00046     const scalar Tcommon,
00047     const typename janafThermo<equationOfState>::coeffArray& highCpCoeffs,
00048     const typename janafThermo<equationOfState>::coeffArray& lowCpCoeffs
00049 )
00050 :
00051     equationOfState(st),
00052     Tlow_(Tlow),
00053     Thigh_(Thigh),
00054     Tcommon_(Tcommon)
00055 {
00056     for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
00057     {
00058         highCpCoeffs_[coefLabel] = highCpCoeffs[coefLabel];
00059         lowCpCoeffs_[coefLabel] = lowCpCoeffs[coefLabel];
00060     }
00061 }
00062 
00063 
00064 // Check given temperature is within the range of the fitted coeffs.
00065 template<class equationOfState>
00066 inline void janafThermo<equationOfState>::checkT(const scalar T) const
00067 {
00068     if (T <  Tlow_ || T > Thigh_)
00069     {
00070         FatalErrorIn
00071         (
00072             "janafThermo<equationOfState>::checkT(const scalar T) const"
00073         )   << "attempt to use janafThermo<equationOfState>"
00074                " out of temperature range "
00075             << Tlow_ << " -> " << Thigh_ << ";  T = " << T
00076             << abort(FatalError);
00077     }
00078 }
00079 
00080 
00081 // Return the coefficients corresponding to the given temperature
00082 template<class equationOfState>
00083 inline const 
00084 #ifdef __GNUC__
00085 coeffArray2&
00086 #else
00087 typename janafThermo<equationOfState>::coeffArray&
00088 #endif
00089 janafThermo<equationOfState>::coeffs
00090 (
00091     const scalar T
00092 ) const
00093 {
00094     checkT(T);
00095 
00096     if (T < Tcommon_)
00097     {
00098         return lowCpCoeffs_;
00099     }
00100     else
00101     {
00102         return highCpCoeffs_;
00103     }
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00108 
00109 // Construct as a named copy
00110 template<class equationOfState>
00111 inline janafThermo<equationOfState>::janafThermo
00112 (
00113     const word& name,
00114     const janafThermo& jt
00115 )
00116 :
00117     equationOfState(name, jt),
00118     Tlow_(jt.Tlow_),
00119     Thigh_(jt.Thigh_),
00120     Tcommon_(jt.Tcommon_)
00121 {
00122     for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
00123     {
00124         highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
00125         lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
00126     }
00127 }
00128 
00129 
00130 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00131 
00132 // Heat capacity at constant pressure [J/(kmol K)]
00133 template<class equationOfState>
00134 inline scalar janafThermo<equationOfState>::cp
00135 (
00136     const scalar T
00137 ) const
00138 {
00139     const coeffArray& a = coeffs(T);
00140     return this->RR*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]);
00141 }
00142 
00143 
00144 // Enthalpy [J/kmol]
00145 template<class equationOfState>
00146 inline scalar janafThermo<equationOfState>::h
00147 (
00148     const scalar T
00149 ) const
00150 {
00151     const coeffArray& a = coeffs(T);
00152     return
00153     this->RR*
00154     (
00155         ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
00156       + a[5]
00157     );
00158 }
00159 
00160 
00161 // Entropy [J/(kmol K)]
00162 template<class equationOfState>
00163 inline scalar janafThermo<equationOfState>::s
00164 (
00165     const scalar T
00166 ) const
00167 {
00168     const coeffArray& a = coeffs(T);
00169     return
00170     this->RR*
00171     (
00172         (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
00173       + a[6]
00174     );
00175 }
00176 
00177 
00178 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00179 
00180 template<class equationOfState>
00181 inline void janafThermo<equationOfState>::operator+=
00182 (
00183     const janafThermo<equationOfState>& jt
00184 )
00185 {
00186     scalar molr1 = this->nMoles();
00187 
00188     equationOfState::operator+=(jt);
00189 
00190     molr1 /= this->nMoles();
00191     scalar molr2 = jt.nMoles()/this->nMoles();
00192 
00193     Tlow_ = max(Tlow_, jt.Tlow_);
00194     Thigh_ = min(Thigh_, jt.Thigh_);
00195     Tcommon_ = molr1*Tcommon_ + molr2*jt.Tcommon_;
00196 
00197     for
00198     (
00199         register label coefLabel=0;
00200         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00201         coefLabel++
00202     )
00203     {
00204         highCpCoeffs_[coefLabel] =
00205             molr1*highCpCoeffs_[coefLabel]
00206           + molr2*jt.highCpCoeffs_[coefLabel];
00207 
00208         lowCpCoeffs_[coefLabel] =
00209             molr1*lowCpCoeffs_[coefLabel]
00210           + molr2*jt.lowCpCoeffs_[coefLabel];
00211     }
00212 }
00213 
00214 
00215 template<class equationOfState>
00216 inline void janafThermo<equationOfState>::operator-=
00217 (
00218     const janafThermo<equationOfState>& jt
00219 )
00220 {
00221     scalar molr1 = this->nMoles();
00222 
00223     equationOfState::operator-=(jt);
00224 
00225     molr1 /= this->nMoles();
00226     scalar molr2 = jt.nMoles()/this->nMoles();
00227 
00228     Tlow_ = max(Tlow_, jt.Tlow_);
00229     Thigh_ = min(Thigh_, jt.Thigh_);
00230     Tcommon_ = molr1*Tcommon_ - molr2*jt.Tcommon_;
00231 
00232     for
00233     (
00234         register label coefLabel=0;
00235         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00236         coefLabel++
00237     )
00238     {
00239         highCpCoeffs_[coefLabel] =
00240             molr1*highCpCoeffs_[coefLabel]
00241           - molr2*jt.highCpCoeffs_[coefLabel];
00242 
00243         lowCpCoeffs_[coefLabel] =
00244             molr1*lowCpCoeffs_[coefLabel]
00245           - molr2*jt.lowCpCoeffs_[coefLabel];
00246     }
00247 }
00248 
00249 
00250 template<class equationOfState>
00251 inline void janafThermo<equationOfState>::operator*=
00252 (
00253     const scalar s
00254 )
00255 {
00256     equationOfState::operator*=(s);
00257 }
00258 
00259 
00260 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00261 
00262 template<class equationOfState>
00263 inline janafThermo<equationOfState> operator+
00264 (
00265     const janafThermo<equationOfState>& jt1,
00266     const janafThermo<equationOfState>& jt2
00267 )
00268 {
00269     equationOfState eofs = jt1;
00270     eofs += jt2;
00271 
00272     scalar molr1 = jt1.nMoles()/eofs.nMoles();
00273     scalar molr2 = jt2.nMoles()/eofs.nMoles();
00274 
00275     typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
00276     typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
00277 
00278     for
00279     (
00280         register label coefLabel=0;
00281         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00282         coefLabel++
00283     )
00284     {
00285         highCpCoeffs[coefLabel] =
00286             molr1*jt1.highCpCoeffs_[coefLabel]
00287           + molr2*jt2.highCpCoeffs_[coefLabel];
00288 
00289         lowCpCoeffs[coefLabel] =
00290             molr1*jt1.lowCpCoeffs_[coefLabel]
00291           + molr2*jt2.lowCpCoeffs_[coefLabel];
00292     }
00293 
00294     return janafThermo<equationOfState>
00295     (
00296         eofs,
00297         max(jt1.Tlow_, jt2.Tlow_),
00298         min(jt1.Thigh_, jt2.Thigh_),
00299         molr1*jt1.Tcommon_ + molr2*jt2.Tcommon_,
00300         highCpCoeffs,
00301         lowCpCoeffs
00302     );
00303 }
00304 
00305 
00306 template<class equationOfState>
00307 inline janafThermo<equationOfState> operator-
00308 (
00309     const janafThermo<equationOfState>& jt1,
00310     const janafThermo<equationOfState>& jt2
00311 )
00312 {
00313     equationOfState eofs = jt1;
00314     eofs -= jt2;
00315 
00316     scalar molr1 = jt1.nMoles()/eofs.nMoles();
00317     scalar molr2 = jt2.nMoles()/eofs.nMoles();
00318 
00319     typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
00320     typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
00321 
00322     for
00323     (
00324         register label coefLabel=0;
00325         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00326         coefLabel++
00327     )
00328     {
00329         highCpCoeffs[coefLabel] =
00330             molr1*jt1.highCpCoeffs_[coefLabel]
00331           - molr2*jt2.highCpCoeffs_[coefLabel];
00332 
00333         lowCpCoeffs[coefLabel] =
00334             molr1*jt1.lowCpCoeffs_[coefLabel]
00335           - molr2*jt2.lowCpCoeffs_[coefLabel];
00336     }
00337 
00338     return janafThermo<equationOfState>
00339     (
00340         eofs,
00341         max(jt1.Tlow_, jt2.Tlow_),
00342         min(jt1.Thigh_, jt2.Thigh_),
00343         molr1*jt1.Tcommon_ - molr2*jt2.Tcommon_,
00344         highCpCoeffs,
00345         lowCpCoeffs
00346     );
00347 }
00348 
00349 
00350 template<class equationOfState>
00351 inline janafThermo<equationOfState> operator*
00352 (
00353     const scalar s,
00354     const janafThermo<equationOfState>& jt
00355 )
00356 {
00357     return janafThermo<equationOfState>
00358     (
00359         s*static_cast<const equationOfState&>(jt),
00360         jt.Tlow_,
00361         jt.Thigh_,
00362         jt.Tcommon_,
00363         jt.highCpCoeffs_,
00364         jt.lowCpCoeffs_
00365     );
00366 }
00367 
00368 
00369 template<class equationOfState>
00370 inline janafThermo<equationOfState> operator==
00371 (
00372     const janafThermo<equationOfState>& jt1,
00373     const janafThermo<equationOfState>& jt2
00374 )
00375 {
00376     return jt2 - jt1;
00377 }
00378 
00379 
00380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00381 
00382 } // End namespace Foam
00383 
00384 // ************************************************************************* //
For further information go to www.openfoam.org