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_new
blob29111f5c2bf887fce04bdb09e3f38dcebc56a2cf
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 Tbar = T0;
52     scalar Ttol = T0*tol_;
53     int iter = 0;
55     do
56     {
57         // Use improved Newton method
58         Test = Tnew;
59         Tbar = Test
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_)
65         {
66             // Improvements: graceful exit with recovery.  HJ, 11/Oct/2010
67             // InfoIn
68             // (
69             //     "specieThermo<thermo>::T(scalar f, scalar T0, "
70             //     "scalar (specieThermo<thermo>::*F)(const scalar) const, "
71             //     "scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
72             //     ") const"
73             // )   << "Maximum number of iterations exceeded."
74             //     << endl;
76             // // Assume linear behavior around T0
77             Tnew = f/(this->*dFdT)(T0);
78             // Tnew = 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);
83             return Tnew;
84         }
86     } while (mag(Tnew - Test) > Ttol);
88     return Tnew;
92 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
94 template<class thermo>
95 inline Foam::specieThermo<thermo>::specieThermo
97     const word& name,
98     const specieThermo& st
101     thermo(name, 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);
218     if (arg < 600.0)
219     {
220         return ::exp(arg);
221     }
222     else
223     {
224         return VGREAT;
225     }
229 template<class thermo>
230 inline Foam::scalar Foam::specieThermo<thermo>::Kp(const scalar T) const
232     return K(T);
236 template<class thermo>
237 inline Foam::scalar Foam::specieThermo<thermo>::Kc(const scalar T) const
239     if (equal(this->nMoles(), SMALL))
240     {
241         return Kp(T);
242     }
243     else
244     {
245         return Kp(T)*pow(this->Pstd/(this->RR*T), this->nMoles());
246     }
250 template<class thermo>
251 inline Foam::scalar Foam::specieThermo<thermo>::Kx
253     const scalar T,
254     const scalar p
255 ) const
257     if (equal(this->nMoles(), SMALL))
258     {
259         return Kp(T);
260     }
261     else
262     {
263         return Kp(T)*pow(this->Pstd/p, this->nMoles());
264     }
268 template<class thermo>
269 inline Foam::scalar Foam::specieThermo<thermo>::Kn
271     const scalar T,
272     const scalar p,
273     const scalar n
274 ) const
276     if (equal(this->nMoles(), SMALL))
277     {
278         return Kp(T);
279     }
280     else
281     {
282         return Kp(T)*pow(n*this->Pstd/p, this->nMoles());
283     }
287 template<class thermo>
288 inline Foam::scalar Foam::specieThermo<thermo>::TH
290     const scalar h,
291     const scalar T0
292 ) const
294     return T(h, T0, &specieThermo<thermo>::H, &specieThermo<thermo>::Cp);
298 template<class thermo>
299 inline Foam::scalar Foam::specieThermo<thermo>::THs
301     const scalar hs,
302     const scalar T0
303 ) const
305     return T(hs, T0, &specieThermo<thermo>::Hs, &specieThermo<thermo>::Cp);
309 template<class thermo>
310 inline Foam::scalar Foam::specieThermo<thermo>::TE
312     const scalar e,
313     const scalar T0
314 ) const
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>
357     (
358         static_cast<const thermo&>(st1) + static_cast<const thermo&>(st2)
359     );
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>
371     (
372         static_cast<const thermo&>(st1) - static_cast<const thermo&>(st2)
373     );
377 template<class thermo>
378 inline Foam::specieThermo<thermo> Foam::operator*
380     const scalar s,
381     const specieThermo<thermo>& st
384     return specieThermo<thermo>
385     (
386         s*static_cast<const thermo&>(st)
387     );
391 template<class thermo>
392 inline Foam::specieThermo<thermo> Foam::operator==
394     const specieThermo<thermo>& st1,
395     const specieThermo<thermo>& st2
398     return st2 - st1;
402 // ************************************************************************* //