1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "specieThermo.H"
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 template<class thermo>
31 inline Foam::specieThermo<thermo>::specieThermo
40 template<class thermo>
41 inline Foam::scalar Foam::specieThermo<thermo>::T
45 scalar (specieThermo<thermo>::*F)(const scalar) const,
46 scalar (specieThermo<thermo>::*dFdT)(const scalar) const
52 scalar Ttol = T0*tol_;
57 // Use improved Newton method
60 - Foam::min(((this->*F)(Test) - f)/(this->*dFdT)(Test), TJump_);
61 Tnew = Test - ((this->*F)(Test) - f)*((this->*F)(Test) - f)/
62 (this->*dFdT)(Test)*(((this->*F)(Test) - f) - (this->*F)(Tbar) - f);
64 if (iter++ > maxIter_)
66 // Improvements: graceful exit with recovery. HJ, 11/Oct/2010
69 // "specieThermo<thermo>::T(scalar f, scalar T0, "
70 // "scalar (specieThermo<thermo>::*F)(const scalar) const, "
71 // "scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
73 // ) << "Maximum number of iterations exceeded."
76 // // Assume linear behavior around T0
77 Tnew = f/(this->*dFdT)(T0);
79 // - Foam::min(((this->*F)(T0) - f)/(this->*dFdT)(T0),TJump_);
80 // Tnew = T0 - ((this->*F)(T0) - f)*((this->*F)(T0) - f)/
81 // (this->*dFdT)(T0)*(((this->*F)(T0) - f) - (this->*F)(Tbar) - f);
86 } while (mag(Tnew - Test) > Ttol);
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 template<class thermo>
95 inline Foam::specieThermo<thermo>::specieThermo
98 const specieThermo& st
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 template<class thermo>
108 inline Foam::scalar Foam::specieThermo<thermo>::cv(const scalar T) const
110 return this->cp(T) - this->RR;
114 template<class thermo>
115 inline Foam::scalar Foam::specieThermo<thermo>::gamma(const scalar T) const
117 scalar CP = this->cp(T);
118 return CP/(CP - this->RR);
122 template<class thermo>
123 inline Foam::scalar Foam::specieThermo<thermo>::e(const scalar T) const
125 return this->h(T) - this->RR*(T - this->Tstd);
129 template<class thermo>
130 inline Foam::scalar Foam::specieThermo<thermo>::es(const scalar T) const
132 return this->hs(T) - this->RR*(T - this->Tstd);
136 template<class thermo>
137 inline Foam::scalar Foam::specieThermo<thermo>::g(const scalar T) const
139 return this->h(T) - T*this->s(T);
143 template<class thermo>
144 inline Foam::scalar Foam::specieThermo<thermo>::a(const scalar T) const
146 return this->e(T) - T*this->s(T);
150 template<class thermo>
151 inline Foam::scalar Foam::specieThermo<thermo>::Cp(const scalar T) const
153 return this->cp(T)/this->W();
157 template<class thermo>
158 inline Foam::scalar Foam::specieThermo<thermo>::Cv(const scalar T) const
160 return this->cv(T)/this->W();
164 template<class thermo>
165 inline Foam::scalar Foam::specieThermo<thermo>::H(const scalar T) const
167 return this->h(T)/this->W();
171 template<class thermo>
172 inline Foam::scalar Foam::specieThermo<thermo>::Hs(const scalar T) const
174 return this->hs(T)/this->W();
178 template<class thermo>
179 inline Foam::scalar Foam::specieThermo<thermo>::Hc() const
181 return this->hc()/this->W();
185 template<class thermo>
186 inline Foam::scalar Foam::specieThermo<thermo>::S(const scalar T) const
188 return this->s(T)/this->W();
192 template<class thermo>
193 inline Foam::scalar Foam::specieThermo<thermo>::E(const scalar T) const
195 return this->e(T)/this->W();
199 template<class thermo>
200 inline Foam::scalar Foam::specieThermo<thermo>::G(const scalar T) const
202 return this->g(T)/this->W();
206 template<class thermo>
207 inline Foam::scalar Foam::specieThermo<thermo>::A(const scalar T) const
209 return this->a(T)/this->W();
213 template<class thermo>
214 inline Foam::scalar Foam::specieThermo<thermo>::K(const scalar T) const
216 scalar arg = -this->nMoles()*this->g(T)/(this->RR*T);
229 template<class thermo>
230 inline Foam::scalar Foam::specieThermo<thermo>::Kp(const scalar T) const
236 template<class thermo>
237 inline Foam::scalar Foam::specieThermo<thermo>::Kc(const scalar T) const
239 if (equal(this->nMoles(), SMALL))
245 return Kp(T)*pow(this->Pstd/(this->RR*T), this->nMoles());
250 template<class thermo>
251 inline Foam::scalar Foam::specieThermo<thermo>::Kx
257 if (equal(this->nMoles(), SMALL))
263 return Kp(T)*pow(this->Pstd/p, this->nMoles());
268 template<class thermo>
269 inline Foam::scalar Foam::specieThermo<thermo>::Kn
276 if (equal(this->nMoles(), SMALL))
282 return Kp(T)*pow(n*this->Pstd/p, this->nMoles());
287 template<class thermo>
288 inline Foam::scalar Foam::specieThermo<thermo>::TH
294 return T(h, T0, &specieThermo<thermo>::H, &specieThermo<thermo>::Cp);
298 template<class thermo>
299 inline Foam::scalar Foam::specieThermo<thermo>::THs
305 return T(hs, T0, &specieThermo<thermo>::Hs, &specieThermo<thermo>::Cp);
309 template<class thermo>
310 inline Foam::scalar Foam::specieThermo<thermo>::TE
316 return T(e, T0, &specieThermo<thermo>::E, &specieThermo<thermo>::Cv);
320 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
322 template<class thermo>
323 inline void Foam::specieThermo<thermo>::operator+=
325 const specieThermo<thermo>& st
328 thermo::operator+=(st);
331 template<class thermo>
332 inline void Foam::specieThermo<thermo>::operator-=
334 const specieThermo<thermo>& st
337 thermo::operator-=(st);
340 template<class thermo>
341 inline void Foam::specieThermo<thermo>::operator*=(const scalar s)
343 thermo::operator*=(s);
347 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
349 template<class thermo>
350 inline Foam::specieThermo<thermo> Foam::operator+
352 const specieThermo<thermo>& st1,
353 const specieThermo<thermo>& st2
356 return specieThermo<thermo>
358 static_cast<const thermo&>(st1) + static_cast<const thermo&>(st2)
363 template<class thermo>
364 inline Foam::specieThermo<thermo> Foam::operator-
366 const specieThermo<thermo>& st1,
367 const specieThermo<thermo>& st2
370 return specieThermo<thermo>
372 static_cast<const thermo&>(st1) - static_cast<const thermo&>(st2)
377 template<class thermo>
378 inline Foam::specieThermo<thermo> Foam::operator*
381 const specieThermo<thermo>& st
384 return specieThermo<thermo>
386 s*static_cast<const thermo&>(st)
391 template<class thermo>
392 inline Foam::specieThermo<thermo> Foam::operator==
394 const specieThermo<thermo>& st1,
395 const specieThermo<thermo>& st2
402 // ************************************************************************* //