OpenFOAM logo
Open Source CFD Toolkit

specieThermoI.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     Basic thermodynamics type based on the use of fitting functions for
00027     cp, h, s obtained from the template argument type thermo.  All other
00028     properties are derived from these primitive functions.
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #include "error.H"
00033 
00034 #include "specieThermo.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 // construct from components
00044 template<class thermo>
00045 inline specieThermo<thermo>::specieThermo
00046 (
00047     const thermo& sp
00048 )
00049 :
00050     thermo(sp)
00051 {}
00052 
00053 
00054 // return the temperature corresponding to the value of the
00055 // thermodynamic property f, given the function f = F(T) and dF(T)/dT
00056 template<class thermo>
00057 inline scalar specieThermo<thermo>::T
00058 (
00059     scalar f,
00060     scalar T0,
00061     scalar (specieThermo<thermo>::*F)(const scalar) const,
00062     scalar (specieThermo<thermo>::*dFdT)(const scalar) const
00063 ) const
00064 {
00065     scalar Test = T0;
00066     scalar Tnew = T0;
00067     scalar Ttol = T0*tol_;
00068     int    iter = 0;
00069 
00070     do
00071     {
00072         Test = Tnew;
00073         Tnew = Test - ((this->*F)(Test) - f)/(this->*dFdT)(Test);
00074 
00075         if (iter++ > maxIter_)
00076         {
00077             FatalErrorIn
00078             (
00079                 "specieThermo<thermo>::T(scalar f, scalar T0, "
00080                 "scalar (specieThermo<thermo>::*F)(const scalar) const, "
00081                 "scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
00082                 ") const"
00083             )   << "Maximum number of iterations exceeded"
00084                 << abort(FatalError);
00085         }
00086 
00087     } while (mag(Tnew - Test) > Ttol);
00088 
00089     return Tnew;
00090 }
00091 
00092 
00093 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00094 
00095 // Construct as named copy
00096 template<class thermo>
00097 inline specieThermo<thermo>::specieThermo
00098 (
00099     const word& name,
00100     const specieThermo& st
00101 )
00102 :
00103     thermo(name, st)
00104 {}
00105 
00106 
00107 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00108 
00109 // Calculate and return derived properties
00110 // (These functions need not provided in derived types)
00111 
00112 // mole specific properties
00113 
00114 // Heat capacities [J/(kmol K)]
00115 template<class thermo>
00116 inline scalar specieThermo<thermo>::cv(const scalar T) const
00117 {
00118     return this->cp(T) - this->RR;
00119 }
00120 
00121 // gamma = cp/cv []
00122 template<class thermo>
00123 inline scalar specieThermo<thermo>::gamma(const scalar T) const
00124 {
00125     scalar CP = this->cp(T);
00126     return CP/(CP - this->RR);
00127 }
00128 
00129 // Internal energy [J/kmol]
00130 template<class thermo>
00131 inline scalar specieThermo<thermo>::e(const scalar T) const
00132 {
00133     return this->h(T) - this->RR*(T - this->Tstd);
00134 }
00135 
00136 // Gibbs free energy [J/kmol]
00137 template<class thermo>
00138 inline scalar specieThermo<thermo>::g(const scalar T) const
00139 {
00140     return this->h(T) - T*this->s(T);
00141 }
00142 
00143 // Helmholtz free energy [J/kmol]
00144 template<class thermo>
00145 inline scalar specieThermo<thermo>::a(const scalar T) const
00146 {
00147     return this->e(T) - T*this->s(T);
00148 }
00149 
00150 
00151 // mass specific properties
00152 
00153 // Heat capacity at constant pressure [J/(kg K)]
00154 template<class thermo>
00155 inline scalar specieThermo<thermo>::Cp(const scalar T) const
00156 {
00157     return this->cp(T)/this->W();
00158 }
00159 
00160 // Heat capacity at constant pressure [J/(kg K)]
00161 template<class thermo>
00162 inline scalar specieThermo<thermo>::Cv(const scalar T) const
00163 {
00164     return this->cv(T)/this->W();
00165 }
00166 
00167 // Enthalpy [J/kg]
00168 template<class thermo>
00169 inline scalar specieThermo<thermo>::H(const scalar T) const
00170 {
00171     return this->h(T)/this->W();
00172 }
00173 
00174 // Entropy [J/kg]
00175 template<class thermo>
00176 inline scalar specieThermo<thermo>::S(const scalar T) const
00177 {
00178     return this->s(T)/this->W();
00179 }
00180 
00181 // Internal energy [J/kg]
00182 template<class thermo>
00183 inline scalar specieThermo<thermo>::E(const scalar T) const
00184 {
00185     return this->e(T)/this->W();
00186 }
00187 
00188 // Gibbs free energy [J/kg]
00189 template<class thermo>
00190 inline scalar specieThermo<thermo>::G(const scalar T) const
00191 {
00192     return this->g(T)/this->W();
00193 }
00194 
00195 // Helmholtz free energy [J/kg]
00196 template<class thermo>
00197 inline scalar specieThermo<thermo>::A(const scalar T) const
00198 {
00199     return this->a(T)/this->W();
00200 }
00201 
00202 
00203 // Equilibrium reaction thermodynamics
00204 
00205 // Equilibrium constant []
00206 template<class thermo>
00207 inline scalar specieThermo<thermo>::K(const scalar T) const
00208 {
00209     scalar arg = -this->nMoles()*this->g(T)/(this->RR*T);
00210 
00211     if (arg < 600.0)
00212     {
00213         return ::exp(arg);
00214     }
00215     else
00216     {
00217         return VGREAT;
00218     }
00219 }
00220 
00221 //- Equilibrium constant [] i.t.o. partial pressures
00222 //  = PIi(pi/Pstd)^nui
00223 //  For low pressures (where the gas mixture is near perfect) Kp = K
00224 template<class thermo>
00225 inline scalar specieThermo<thermo>::Kp(const scalar T) const
00226 {
00227     return K(T);
00228 }
00229 
00230 
00231 //- Equilibrium constant i.t.o. concentration
00232 //  For low pressures (where the gas mixture is near perfect)
00233 //  Kc = Kp(pstd/(RR*T))^nu
00234 template<class thermo>
00235 inline scalar specieThermo<thermo>::Kc(const scalar T) const
00236 {
00237     if (equal(this->nMoles(), SMALL))
00238     {
00239         return Kp(T);
00240     }
00241     else
00242     {
00243         return Kp(T)*pow(this->Pstd/(this->RR*T), this->nMoles());
00244     }
00245 }
00246 
00247 
00248 //- Equilibrium constant [] i.t.o. mole-fractions
00249 //  For low pressures (where the gas mixture is near perfect) 
00250 //  Kx = Kp(pstd/p)^nui
00251 template<class thermo>
00252 inline scalar specieThermo<thermo>::Kx(const scalar T, const scalar p) const
00253 {
00254     if (equal(this->nMoles(), SMALL))
00255     {
00256         return Kp(T);
00257     }
00258     else
00259     {
00260         return Kp(T)*pow(this->Pstd/p, this->nMoles());
00261     }
00262 }
00263 
00264 
00265 //- Equilibrium constant [] i.t.o. number of moles
00266 //  For low pressures (where the gas mixture is near perfect) 
00267 //  Kn = Kp(n*pstd/p)^nui where n = number of moles in mixture
00268 template<class thermo>
00269 inline scalar specieThermo<thermo>::Kn
00270 (
00271     const scalar T,
00272     const scalar p,
00273     const scalar n
00274 ) const
00275 {
00276     if (equal(this->nMoles(), SMALL))
00277     {
00278         return Kp(T);
00279     }
00280     else
00281     {
00282         return Kp(T)*pow(n*this->Pstd/p, this->nMoles());
00283     }
00284 }
00285 
00286 
00287 // Energy->temperature  inversion functions
00288 
00289 // Temperature from Enthalpy given an initial temperature T0
00290 template<class thermo>
00291 inline scalar specieThermo<thermo>::TH(const scalar h, const scalar T0) const
00292 {
00293     return T(h, T0, &specieThermo<thermo>::H, &specieThermo<thermo>::Cp);
00294 }
00295 
00296 
00297 // Temperature from internal energy given an initial temperature T0
00298 template<class thermo>
00299 inline scalar specieThermo<thermo>::TE(const scalar e, const scalar T0) const
00300 {
00301     return T(e, T0, &specieThermo<thermo>::E, &specieThermo<thermo>::Cv);
00302 }
00303 
00304 
00305 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00306 
00307 template<class thermo>
00308 inline void specieThermo<thermo>::operator+=(const specieThermo<thermo>& st)
00309 {
00310     thermo::operator+=(st);
00311 }
00312 
00313 template<class thermo>
00314 inline void specieThermo<thermo>::operator-=(const specieThermo<thermo>& st)
00315 {
00316     thermo::operator-=(st);
00317 }
00318 
00319 template<class thermo>
00320 inline void specieThermo<thermo>::operator*=(const scalar s)
00321 {
00322     thermo::operator*=(s);
00323 }
00324 
00325 
00326 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00327 
00328 template<class thermo>
00329 inline specieThermo<thermo> operator+
00330 (
00331     const specieThermo<thermo>& st1,
00332     const specieThermo<thermo>& st2
00333 )
00334 {
00335     return specieThermo<thermo>
00336     (
00337         static_cast<const thermo&>(st1) + static_cast<const thermo&>(st2)
00338     );
00339 }
00340 
00341 
00342 template<class thermo>
00343 inline specieThermo<thermo> operator-
00344 (
00345     const specieThermo<thermo>& st1,
00346     const specieThermo<thermo>& st2
00347 )
00348 {
00349     return specieThermo<thermo>
00350     (
00351         static_cast<const thermo&>(st1) - static_cast<const thermo&>(st2)
00352     );
00353 }
00354 
00355 
00356 template<class thermo>
00357 inline specieThermo<thermo> operator*
00358 (
00359     const scalar s,
00360     const specieThermo<thermo>& st
00361 )
00362 {
00363     return specieThermo<thermo>
00364     (
00365         s*static_cast<const thermo&>(st)
00366     );
00367 }
00368 
00369 
00370 template<class thermo>
00371 inline specieThermo<thermo> operator==
00372 (
00373     const specieThermo<thermo>& st1,
00374     const specieThermo<thermo>& st2
00375 )
00376 {
00377     return st2 - st1;
00378 }
00379 
00380 
00381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00382 
00383 } // End namespace Foam
00384 
00385 // ************************************************************************* //
For further information go to www.openfoam.org