FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "janafThermo.H"
00027 #include <specie/specie.H>
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 template<class equationOfState>
00032 inline Foam::janafThermo<equationOfState>::janafThermo
00033 (
00034     const equationOfState& st,
00035     const scalar Tlow,
00036     const scalar Thigh,
00037     const scalar Tcommon,
00038     const typename janafThermo<equationOfState>::coeffArray& highCpCoeffs,
00039     const typename janafThermo<equationOfState>::coeffArray& lowCpCoeffs
00040 )
00041 :
00042     equationOfState(st),
00043     Tlow_(Tlow),
00044     Thigh_(Thigh),
00045     Tcommon_(Tcommon)
00046 {
00047     for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
00048     {
00049         highCpCoeffs_[coefLabel] = highCpCoeffs[coefLabel];
00050         lowCpCoeffs_[coefLabel] = lowCpCoeffs[coefLabel];
00051     }
00052 }
00053 
00054 
00055 template<class equationOfState>
00056 inline void Foam::janafThermo<equationOfState>::checkT(const scalar T) const
00057 {
00058     if (T <  Tlow_ || T > Thigh_)
00059     {
00060         FatalErrorIn
00061         (
00062             "janafThermo<equationOfState>::checkT(const scalar T) const"
00063         )   << "attempt to use janafThermo<equationOfState>"
00064                " out of temperature range "
00065             << Tlow_ << " -> " << Thigh_ << ";  T = " << T
00066             << abort(FatalError);
00067     }
00068 }
00069 
00070 
00071 template<class equationOfState>
00072 inline const typename Foam::janafThermo<equationOfState>::coeffArray&
00073 Foam::janafThermo<equationOfState>::coeffs
00074 (
00075     const scalar T
00076 ) const
00077 {
00078     checkT(T);
00079 
00080     if (T < Tcommon_)
00081     {
00082         return lowCpCoeffs_;
00083     }
00084     else
00085     {
00086         return highCpCoeffs_;
00087     }
00088 }
00089 
00090 
00091 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00092 
00093 template<class equationOfState>
00094 inline Foam::janafThermo<equationOfState>::janafThermo
00095 (
00096     const word& name,
00097     const janafThermo& jt
00098 )
00099 :
00100     equationOfState(name, jt),
00101     Tlow_(jt.Tlow_),
00102     Thigh_(jt.Thigh_),
00103     Tcommon_(jt.Tcommon_)
00104 {
00105     for (register label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
00106     {
00107         highCpCoeffs_[coefLabel] = jt.highCpCoeffs_[coefLabel];
00108         lowCpCoeffs_[coefLabel] = jt.lowCpCoeffs_[coefLabel];
00109     }
00110 }
00111 
00112 
00113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00114 
00115 template<class equationOfState>
00116 inline Foam::scalar Foam::janafThermo<equationOfState>::cp
00117 (
00118     const scalar T
00119 ) const
00120 {
00121     const coeffArray& a = coeffs(T);
00122     return this->RR*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]);
00123 }
00124 
00125 
00126 template<class equationOfState>
00127 inline Foam::scalar Foam::janafThermo<equationOfState>::h
00128 (
00129     const scalar T
00130 ) const
00131 {
00132     const coeffArray& a = coeffs(T);
00133     return this->RR*
00134     (
00135         ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T
00136       + a[5]
00137     );
00138 }
00139 
00140 
00141 template<class equationOfState>
00142 inline Foam::scalar Foam::janafThermo<equationOfState>::hs
00143 (
00144     const scalar T
00145 ) const
00146 {
00147     return h(T) - hc();
00148 }
00149 
00150 
00151 template<class equationOfState>
00152 inline Foam::scalar Foam::janafThermo<equationOfState>::hc() const
00153 {
00154     const coeffArray& a = lowCpCoeffs_;
00155     const scalar& Tstd = specie::Tstd;
00156     return this->RR*
00157     (
00158         (
00159             (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd
00160           + a[0]
00161         )*Tstd + a[5]
00162     );
00163 }
00164 
00165 
00166 template<class equationOfState>
00167 inline Foam::scalar Foam::janafThermo<equationOfState>::s
00168 (
00169     const scalar T
00170 ) const
00171 {
00172     const coeffArray& a = coeffs(T);
00173     return
00174     this->RR*
00175     (
00176         (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T)
00177       + a[6]
00178     );
00179 }
00180 
00181 
00182 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00183 
00184 template<class equationOfState>
00185 inline void Foam::janafThermo<equationOfState>::operator+=
00186 (
00187     const janafThermo<equationOfState>& jt
00188 )
00189 {
00190     scalar molr1 = this->nMoles();
00191 
00192     equationOfState::operator+=(jt);
00193 
00194     molr1 /= this->nMoles();
00195     scalar molr2 = jt.nMoles()/this->nMoles();
00196 
00197     Tlow_ = max(Tlow_, jt.Tlow_);
00198     Thigh_ = min(Thigh_, jt.Thigh_);
00199     Tcommon_ = molr1*Tcommon_ + molr2*jt.Tcommon_;
00200 
00201     for
00202     (
00203         register label coefLabel=0;
00204         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00205         coefLabel++
00206     )
00207     {
00208         highCpCoeffs_[coefLabel] =
00209             molr1*highCpCoeffs_[coefLabel]
00210           + molr2*jt.highCpCoeffs_[coefLabel];
00211 
00212         lowCpCoeffs_[coefLabel] =
00213             molr1*lowCpCoeffs_[coefLabel]
00214           + molr2*jt.lowCpCoeffs_[coefLabel];
00215     }
00216 }
00217 
00218 
00219 template<class equationOfState>
00220 inline void Foam::janafThermo<equationOfState>::operator-=
00221 (
00222     const janafThermo<equationOfState>& jt
00223 )
00224 {
00225     scalar molr1 = this->nMoles();
00226 
00227     equationOfState::operator-=(jt);
00228 
00229     molr1 /= this->nMoles();
00230     scalar molr2 = jt.nMoles()/this->nMoles();
00231 
00232     Tlow_ = max(Tlow_, jt.Tlow_);
00233     Thigh_ = min(Thigh_, jt.Thigh_);
00234     Tcommon_ = molr1*Tcommon_ - molr2*jt.Tcommon_;
00235 
00236     for
00237     (
00238         register label coefLabel=0;
00239         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00240         coefLabel++
00241     )
00242     {
00243         highCpCoeffs_[coefLabel] =
00244             molr1*highCpCoeffs_[coefLabel]
00245           - molr2*jt.highCpCoeffs_[coefLabel];
00246 
00247         lowCpCoeffs_[coefLabel] =
00248             molr1*lowCpCoeffs_[coefLabel]
00249           - molr2*jt.lowCpCoeffs_[coefLabel];
00250     }
00251 }
00252 
00253 
00254 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00255 
00256 template<class equationOfState>
00257 inline Foam::janafThermo<equationOfState> Foam::operator+
00258 (
00259     const janafThermo<equationOfState>& jt1,
00260     const janafThermo<equationOfState>& jt2
00261 )
00262 {
00263     equationOfState eofs = jt1;
00264     eofs += jt2;
00265 
00266     scalar molr1 = jt1.nMoles()/eofs.nMoles();
00267     scalar molr2 = jt2.nMoles()/eofs.nMoles();
00268 
00269     typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
00270     typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
00271 
00272     for
00273     (
00274         register label coefLabel=0;
00275         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00276         coefLabel++
00277     )
00278     {
00279         highCpCoeffs[coefLabel] =
00280             molr1*jt1.highCpCoeffs_[coefLabel]
00281           + molr2*jt2.highCpCoeffs_[coefLabel];
00282 
00283         lowCpCoeffs[coefLabel] =
00284             molr1*jt1.lowCpCoeffs_[coefLabel]
00285           + molr2*jt2.lowCpCoeffs_[coefLabel];
00286     }
00287 
00288     return janafThermo<equationOfState>
00289     (
00290         eofs,
00291         max(jt1.Tlow_, jt2.Tlow_),
00292         min(jt1.Thigh_, jt2.Thigh_),
00293         molr1*jt1.Tcommon_ + molr2*jt2.Tcommon_,
00294         highCpCoeffs,
00295         lowCpCoeffs
00296     );
00297 }
00298 
00299 
00300 template<class equationOfState>
00301 inline Foam::janafThermo<equationOfState> Foam::operator-
00302 (
00303     const janafThermo<equationOfState>& jt1,
00304     const janafThermo<equationOfState>& jt2
00305 )
00306 {
00307     equationOfState eofs = jt1;
00308     eofs -= jt2;
00309 
00310     scalar molr1 = jt1.nMoles()/eofs.nMoles();
00311     scalar molr2 = jt2.nMoles()/eofs.nMoles();
00312 
00313     typename janafThermo<equationOfState>::coeffArray highCpCoeffs;
00314     typename janafThermo<equationOfState>::coeffArray lowCpCoeffs;
00315 
00316     for
00317     (
00318         register label coefLabel=0;
00319         coefLabel<janafThermo<equationOfState>::nCoeffs_;
00320         coefLabel++
00321     )
00322     {
00323         highCpCoeffs[coefLabel] =
00324             molr1*jt1.highCpCoeffs_[coefLabel]
00325           - molr2*jt2.highCpCoeffs_[coefLabel];
00326 
00327         lowCpCoeffs[coefLabel] =
00328             molr1*jt1.lowCpCoeffs_[coefLabel]
00329           - molr2*jt2.lowCpCoeffs_[coefLabel];
00330     }
00331 
00332     return janafThermo<equationOfState>
00333     (
00334         eofs,
00335         max(jt1.Tlow_, jt2.Tlow_),
00336         min(jt1.Thigh_, jt2.Thigh_),
00337         molr1*jt1.Tcommon_ - molr2*jt2.Tcommon_,
00338         highCpCoeffs,
00339         lowCpCoeffs
00340     );
00341 }
00342 
00343 
00344 template<class equationOfState>
00345 inline Foam::janafThermo<equationOfState> Foam::operator*
00346 (
00347     const scalar s,
00348     const janafThermo<equationOfState>& jt
00349 )
00350 {
00351     return janafThermo<equationOfState>
00352     (
00353         s*static_cast<const equationOfState&>(jt),
00354         jt.Tlow_,
00355         jt.Thigh_,
00356         jt.Tcommon_,
00357         jt.highCpCoeffs_,
00358         jt.lowCpCoeffs_
00359     );
00360 }
00361 
00362 
00363 template<class equationOfState>
00364 inline Foam::janafThermo<equationOfState> Foam::operator==
00365 (
00366     const janafThermo<equationOfState>& jt1,
00367     const janafThermo<equationOfState>& jt2
00368 )
00369 {
00370     return jt2 - jt1;
00371 }
00372 
00373 
00374 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines