00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "error.H"
00033
00034 #include "specieThermo.H"
00035
00036
00037
00038 namespace Foam
00039 {
00040
00041
00042
00043
00044 template<class thermo>
00045 inline specieThermo<thermo>::specieThermo
00046 (
00047 const thermo& sp
00048 )
00049 :
00050 thermo(sp)
00051 {}
00052
00053
00054
00055
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
00094
00095
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
00108
00109
00110
00111
00112
00113
00114
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
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
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
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
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
00152
00153
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
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
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
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
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
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
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
00204
00205
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
00222
00223
00224 template<class thermo>
00225 inline scalar specieThermo<thermo>::Kp(const scalar T) const
00226 {
00227 return K(T);
00228 }
00229
00230
00231
00232
00233
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
00249
00250
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
00266
00267
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
00288
00289
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
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
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
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 }
00384
00385