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

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-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 "specieThermo.H"
00027 
00028 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00029 
00030 template<class thermo>
00031 inline Foam::specieThermo<thermo>::specieThermo
00032 (
00033     const thermo& sp
00034 )
00035 :
00036     thermo(sp)
00037 {}
00038 
00039 
00040 template<class thermo>
00041 inline Foam::scalar Foam::specieThermo<thermo>::T
00042 (
00043     scalar f,
00044     scalar T0,
00045     scalar (specieThermo<thermo>::*F)(const scalar) const,
00046     scalar (specieThermo<thermo>::*dFdT)(const scalar) const
00047 ) const
00048 {
00049     scalar Test = T0;
00050     scalar Tnew = T0;
00051     scalar Ttol = T0*tol_;
00052     int    iter = 0;
00053 
00054     do
00055     {
00056         Test = Tnew;
00057         Tnew = Test - ((this->*F)(Test) - f)/(this->*dFdT)(Test);
00058 
00059         if (iter++ > maxIter_)
00060         {
00061             FatalErrorIn
00062             (
00063                 "specieThermo<thermo>::T(scalar f, scalar T0, "
00064                 "scalar (specieThermo<thermo>::*F)(const scalar) const, "
00065                 "scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
00066                 ") const"
00067             )   << "Maximum number of iterations exceeded"
00068                 << abort(FatalError);
00069         }
00070 
00071     } while (mag(Tnew - Test) > Ttol);
00072 
00073     return Tnew;
00074 }
00075 
00076 
00077 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00078 
00079 template<class thermo>
00080 inline Foam::specieThermo<thermo>::specieThermo
00081 (
00082     const word& name,
00083     const specieThermo& st
00084 )
00085 :
00086     thermo(name, st)
00087 {}
00088 
00089 
00090 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00091 
00092 template<class thermo>
00093 inline Foam::scalar Foam::specieThermo<thermo>::cv(const scalar T) const
00094 {
00095     return this->cp(T) - this->RR;
00096 }
00097 
00098 
00099 template<class thermo>
00100 inline Foam::scalar Foam::specieThermo<thermo>::gamma(const scalar T) const
00101 {
00102     scalar CP = this->cp(T);
00103     return CP/(CP - this->RR);
00104 }
00105 
00106 
00107 template<class thermo>
00108 inline Foam::scalar Foam::specieThermo<thermo>::e(const scalar T) const
00109 {
00110     return this->h(T) - this->RR*(T - this->Tstd);
00111 }
00112 
00113 
00114 template<class thermo>
00115 inline Foam::scalar Foam::specieThermo<thermo>::es(const scalar T) const
00116 {
00117     return this->hs(T) - this->RR*(T - this->Tstd);
00118 }
00119 
00120 
00121 template<class thermo>
00122 inline Foam::scalar Foam::specieThermo<thermo>::g(const scalar T) const
00123 {
00124     return this->h(T) - T*this->s(T);
00125 }
00126 
00127 
00128 template<class thermo>
00129 inline Foam::scalar Foam::specieThermo<thermo>::a(const scalar T) const
00130 {
00131     return this->e(T) - T*this->s(T);
00132 }
00133 
00134 
00135 template<class thermo>
00136 inline Foam::scalar Foam::specieThermo<thermo>::Cp(const scalar T) const
00137 {
00138     return this->cp(T)/this->W();
00139 }
00140 
00141 
00142 template<class thermo>
00143 inline Foam::scalar Foam::specieThermo<thermo>::Cv(const scalar T) const
00144 {
00145     return this->cv(T)/this->W();
00146 }
00147 
00148 
00149 template<class thermo>
00150 inline Foam::scalar Foam::specieThermo<thermo>::H(const scalar T) const
00151 {
00152     return this->h(T)/this->W();
00153 }
00154 
00155 
00156 template<class thermo>
00157 inline Foam::scalar Foam::specieThermo<thermo>::Hs(const scalar T) const
00158 {
00159     return this->hs(T)/this->W();
00160 }
00161 
00162 
00163 template<class thermo>
00164 inline Foam::scalar Foam::specieThermo<thermo>::Hc() const
00165 {
00166     return this->hc()/this->W();
00167 }
00168 
00169 
00170 template<class thermo>
00171 inline Foam::scalar Foam::specieThermo<thermo>::S(const scalar T) const
00172 {
00173     return this->s(T)/this->W();
00174 }
00175 
00176 
00177 template<class thermo>
00178 inline Foam::scalar Foam::specieThermo<thermo>::E(const scalar T) const
00179 {
00180     return this->e(T)/this->W();
00181 }
00182 
00183 
00184 template<class thermo>
00185 inline Foam::scalar Foam::specieThermo<thermo>::G(const scalar T) const
00186 {
00187     return this->g(T)/this->W();
00188 }
00189 
00190 
00191 template<class thermo>
00192 inline Foam::scalar Foam::specieThermo<thermo>::A(const scalar T) const
00193 {
00194     return this->a(T)/this->W();
00195 }
00196 
00197 
00198 template<class thermo>
00199 inline Foam::scalar Foam::specieThermo<thermo>::K(const scalar T) const
00200 {
00201     scalar arg = -this->nMoles()*this->g(T)/(this->RR*T);
00202 
00203     if (arg < 600.0)
00204     {
00205         return ::exp(arg);
00206     }
00207     else
00208     {
00209         return VGREAT;
00210     }
00211 }
00212 
00213 
00214 template<class thermo>
00215 inline Foam::scalar Foam::specieThermo<thermo>::Kp(const scalar T) const
00216 {
00217     return K(T);
00218 }
00219 
00220 
00221 template<class thermo>
00222 inline Foam::scalar Foam::specieThermo<thermo>::Kc(const scalar T) const
00223 {
00224     if (equal(this->nMoles(), SMALL))
00225     {
00226         return Kp(T);
00227     }
00228     else
00229     {
00230         return Kp(T)*pow(this->Pstd/(this->RR*T), this->nMoles());
00231     }
00232 }
00233 
00234 
00235 template<class thermo>
00236 inline Foam::scalar Foam::specieThermo<thermo>::Kx
00237 (
00238     const scalar T,
00239     const scalar p
00240 ) const
00241 {
00242     if (equal(this->nMoles(), SMALL))
00243     {
00244         return Kp(T);
00245     }
00246     else
00247     {
00248         return Kp(T)*pow(this->Pstd/p, this->nMoles());
00249     }
00250 }
00251 
00252 
00253 template<class thermo>
00254 inline Foam::scalar Foam::specieThermo<thermo>::Kn
00255 (
00256     const scalar T,
00257     const scalar p,
00258     const scalar n
00259 ) const
00260 {
00261     if (equal(this->nMoles(), SMALL))
00262     {
00263         return Kp(T);
00264     }
00265     else
00266     {
00267         return Kp(T)*pow(n*this->Pstd/p, this->nMoles());
00268     }
00269 }
00270 
00271 
00272 template<class thermo>
00273 inline Foam::scalar Foam::specieThermo<thermo>::TH
00274 (
00275     const scalar h,
00276     const scalar T0
00277 ) const
00278 {
00279     return T(h, T0, &specieThermo<thermo>::H, &specieThermo<thermo>::Cp);
00280 }
00281 
00282 
00283 template<class thermo>
00284 inline Foam::scalar Foam::specieThermo<thermo>::THs
00285 (
00286     const scalar hs,
00287     const scalar T0
00288 ) const
00289 {
00290     return T(hs, T0, &specieThermo<thermo>::Hs, &specieThermo<thermo>::Cp);
00291 }
00292 
00293 
00294 template<class thermo>
00295 inline Foam::scalar Foam::specieThermo<thermo>::TE
00296 (
00297     const scalar e,
00298     const scalar T0
00299 ) 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 Foam::specieThermo<thermo>::operator+=
00309 (
00310     const specieThermo<thermo>& st
00311 )
00312 {
00313     thermo::operator+=(st);
00314 }
00315 
00316 template<class thermo>
00317 inline void Foam::specieThermo<thermo>::operator-=
00318 (
00319     const specieThermo<thermo>& st
00320 )
00321 {
00322     thermo::operator-=(st);
00323 }
00324 
00325 template<class thermo>
00326 inline void Foam::specieThermo<thermo>::operator*=(const scalar s)
00327 {
00328     thermo::operator*=(s);
00329 }
00330 
00331 
00332 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00333 
00334 template<class thermo>
00335 inline Foam::specieThermo<thermo> Foam::operator+
00336 (
00337     const specieThermo<thermo>& st1,
00338     const specieThermo<thermo>& st2
00339 )
00340 {
00341     return specieThermo<thermo>
00342     (
00343         static_cast<const thermo&>(st1) + static_cast<const thermo&>(st2)
00344     );
00345 }
00346 
00347 
00348 template<class thermo>
00349 inline Foam::specieThermo<thermo> Foam::operator-
00350 (
00351     const specieThermo<thermo>& st1,
00352     const specieThermo<thermo>& st2
00353 )
00354 {
00355     return specieThermo<thermo>
00356     (
00357         static_cast<const thermo&>(st1) - static_cast<const thermo&>(st2)
00358     );
00359 }
00360 
00361 
00362 template<class thermo>
00363 inline Foam::specieThermo<thermo> Foam::operator*
00364 (
00365     const scalar s,
00366     const specieThermo<thermo>& st
00367 )
00368 {
00369     return specieThermo<thermo>
00370     (
00371         s*static_cast<const thermo&>(st)
00372     );
00373 }
00374 
00375 
00376 template<class thermo>
00377 inline Foam::specieThermo<thermo> Foam::operator==
00378 (
00379     const specieThermo<thermo>& st1,
00380     const specieThermo<thermo>& st2
00381 )
00382 {
00383     return st2 - st1;
00384 }
00385 
00386 
00387 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines