Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / thermophysicalModels / specie / thermo / specieThermo / specieThermoI.H
blobddd1cef7c93a5b5b0cd1d03c38a4e206f9deabd7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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
33     const thermo& sp
36     thermo(sp)
40 template<class thermo>
41 inline Foam::scalar Foam::specieThermo<thermo>::T
43     scalar f,
44     scalar T0,
45     scalar (specieThermo<thermo>::*F)(const scalar) const,
46     scalar (specieThermo<thermo>::*dFdT)(const scalar) const
47 ) const
49     scalar Test = T0;
50     scalar Tnew = T0;
51     scalar Ttol = T0*tol_();
52     int iter = 0;
54     do
55     {
56         // Limit the temperature jump in a single corrector to TJump_
57         // HJ, 12/Oct/2010
59         Test = Tnew;
60         Tnew = Test
61             - Foam::min(((this->*F)(Test) - f)/(this->*dFdT)(Test), TJump_());
63         if (iter++ > maxIter_())
64         {
65             // Improvements: graceful exit with recovery.  HJ, 11/Oct/2010
66             InfoIn
67             (
68                 "specieThermo<thermo>::T(scalar f, scalar T0, "
69                 "scalar (specieThermo<thermo>::*F)(const scalar) const, "
70                 "scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
71                 ") const"
72             )   << "Maximum number of iterations exceeded.  T0 = "
73                 << T0 << " F = " << (this->*F)(Test)
74                 << " dFdT = " << (this->*dFdT)(Test)
75                 << endl;
77             // Use value where dFdT is calculated using T0.  HJ, 11/Oct/2010
78             Tnew = f/(this->*dFdT)(T0);
80             return Tnew;
81         }
83     } while (mag(Tnew - Test) > Ttol);
85     return Tnew;
89 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
91 template<class thermo>
92 inline Foam::specieThermo<thermo>::specieThermo
94     const word& name,
95     const specieThermo& st
98     thermo(name, st)
102 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
104 template<class thermo>
105 inline Foam::scalar Foam::specieThermo<thermo>::cv(const scalar T) const
107     return this->cp(T) - this->RR();
111 template<class thermo>
112 inline Foam::scalar Foam::specieThermo<thermo>::gamma(const scalar T) const
114     scalar CP = this->cp(T);
115     return CP/(CP - this->RR());
119 template<class thermo>
120 inline Foam::scalar Foam::specieThermo<thermo>::e(const scalar T) const
122     return this->h(T) - this->RR()*(T - this->Tstd());
126 template<class thermo>
127 inline Foam::scalar Foam::specieThermo<thermo>::es(const scalar T) const
129     return this->hs(T) - this->RR()*(T - this->Tstd());
133 template<class thermo>
134 inline Foam::scalar Foam::specieThermo<thermo>::g(const scalar T) const
136     return this->h(T) - T*this->s(T);
140 template<class thermo>
141 inline Foam::scalar Foam::specieThermo<thermo>::a(const scalar T) const
143     return this->e(T) - T*this->s(T);
147 template<class thermo>
148 inline Foam::scalar Foam::specieThermo<thermo>::Cp(const scalar T) const
150     return this->cp(T)/this->W();
154 template<class thermo>
155 inline Foam::scalar Foam::specieThermo<thermo>::Cv(const scalar T) const
157     return this->cv(T)/this->W();
161 template<class thermo>
162 inline Foam::scalar Foam::specieThermo<thermo>::H(const scalar T) const
164     return this->h(T)/this->W();
168 template<class thermo>
169 inline Foam::scalar Foam::specieThermo<thermo>::Hs(const scalar T) const
171     return this->hs(T)/this->W();
175 template<class thermo>
176 inline Foam::scalar Foam::specieThermo<thermo>::Hc() const
178     return this->hc()/this->W();
182 template<class thermo>
183 inline Foam::scalar Foam::specieThermo<thermo>::S(const scalar T) const
185     return this->s(T)/this->W();
189 template<class thermo>
190 inline Foam::scalar Foam::specieThermo<thermo>::E(const scalar T) const
192     return this->e(T)/this->W();
196 template<class thermo>
197 inline Foam::scalar Foam::specieThermo<thermo>::G(const scalar T) const
199     return this->g(T)/this->W();
203 template<class thermo>
204 inline Foam::scalar Foam::specieThermo<thermo>::A(const scalar T) const
206     return this->a(T)/this->W();
210 template<class thermo>
211 inline Foam::scalar Foam::specieThermo<thermo>::K(const scalar T) const
213     scalar arg = -this->nMoles()*this->g(T)/(this->RR()*T);
215     if (arg < 600.0)
216     {
217         return ::exp(arg);
218     }
219     else
220     {
221         return VGREAT;
222     }
226 template<class thermo>
227 inline Foam::scalar Foam::specieThermo<thermo>::Kp(const scalar T) const
229     return K(T);
233 template<class thermo>
234 inline Foam::scalar Foam::specieThermo<thermo>::Kc(const scalar T) const
236     if (equal(this->nMoles(), SMALL))
237     {
238         return Kp(T);
239     }
240     else
241     {
242         return Kp(T)*pow(this->Pstd()/(this->RR()*T), this->nMoles());
243     }
247 template<class thermo>
248 inline Foam::scalar Foam::specieThermo<thermo>::Kx
250     const scalar T,
251     const scalar p
252 ) const
254     if (equal(this->nMoles(), SMALL))
255     {
256         return Kp(T);
257     }
258     else
259     {
260         return Kp(T)*pow(this->Pstd()/p, this->nMoles());
261     }
265 template<class thermo>
266 inline Foam::scalar Foam::specieThermo<thermo>::Kn
268     const scalar T,
269     const scalar p,
270     const scalar n
271 ) const
273     if (equal(this->nMoles(), SMALL))
274     {
275         return Kp(T);
276     }
277     else
278     {
279         return Kp(T)*pow(n*this->Pstd()/p, this->nMoles());
280     }
284 template<class thermo>
285 inline Foam::scalar Foam::specieThermo<thermo>::TH
287     const scalar h,
288     const scalar T0
289 ) const
291     return T(h, T0, &specieThermo<thermo>::H, &specieThermo<thermo>::Cp);
295 template<class thermo>
296 inline Foam::scalar Foam::specieThermo<thermo>::THs
298     const scalar hs,
299     const scalar T0
300 ) const
302     return T(hs, T0, &specieThermo<thermo>::Hs, &specieThermo<thermo>::Cp);
306 template<class thermo>
307 inline Foam::scalar Foam::specieThermo<thermo>::TE
309     const scalar e,
310     const scalar T0
311 ) const
313     return T(e, T0, &specieThermo<thermo>::E, &specieThermo<thermo>::Cv);
317 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
319 template<class thermo>
320 inline void Foam::specieThermo<thermo>::operator+=
322     const specieThermo<thermo>& st
325     thermo::operator+=(st);
328 template<class thermo>
329 inline void Foam::specieThermo<thermo>::operator-=
331     const specieThermo<thermo>& st
334     thermo::operator-=(st);
337 template<class thermo>
338 inline void Foam::specieThermo<thermo>::operator*=(const scalar s)
340     thermo::operator*=(s);
344 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
346 template<class thermo>
347 inline Foam::specieThermo<thermo> Foam::operator+
349     const specieThermo<thermo>& st1,
350     const specieThermo<thermo>& st2
353     return specieThermo<thermo>
354     (
355         static_cast<const thermo&>(st1) + static_cast<const thermo&>(st2)
356     );
360 template<class thermo>
361 inline Foam::specieThermo<thermo> Foam::operator-
363     const specieThermo<thermo>& st1,
364     const specieThermo<thermo>& st2
367     return specieThermo<thermo>
368     (
369         static_cast<const thermo&>(st1) - static_cast<const thermo&>(st2)
370     );
374 template<class thermo>
375 inline Foam::specieThermo<thermo> Foam::operator*
377     const scalar s,
378     const specieThermo<thermo>& st
381     return specieThermo<thermo>
382     (
383         s*static_cast<const thermo&>(st)
384     );
388 template<class thermo>
389 inline Foam::specieThermo<thermo> Foam::operator==
391     const specieThermo<thermo>& st1,
392     const specieThermo<thermo>& st2
395     return st2 - st1;
399 // ************************************************************************* //