source: trunk/LMDZ.GENERIC/libf/phystd/phasechange_kcm.F90 @ 848

Last change on this file since 848 was 305, checked in by rwordsworth, 13 years ago

Several new files added as part of the climate evolution model
(main program kcm.F90). Some general cleanup in physiq.F90 and
callcorrk.F90. Bugs in dust radiative transfer and H2 Rayleigh
scattering corrected.

  • Property svn:executable set to *
File size: 37.1 KB
Line 
1!  ----------------------------------------------------------------
2!  Purpose: Thermodynamic data on H2O, NH3
3!  Authour: Adapted from various sources by R. Wordsworth (2011)
4
5
6! ---------------------
7! NH3
8! ---------------------
9subroutine psat_NH3 ( T, p )
10!
11!  PSAT_NH3 makes a rough estimate of the vapor pressure.
12!
13!  Interpolated from www.engineeringtoolbox.com data by RDW 21/09/11 for
14!  temperatures between 223 and 323 K.
15!
16!  Parameters:
17!
18!    Input, double precision T, the temperature, in degrees Kelvin.
19!
20!    Output, double precision P, the vapor pressure, in MegaPascals.
21!
22
23  implicit none
24
25  double precision p,T
26
27  p=exp(-1.5609d-004*T**2 + 0.1236*T - 9.1530)/1d6
28
29end subroutine psat_NH3
30
31subroutine latheat_NH3 ( T, sc, sv )
32!
33!  PSAT_NH3 makes a rough estimate of the entropies of condensation /
34!  vapourisation.
35!
36!  Interpolated from www.engineeringtoolbox.com data by RDW 21/09/11 for
37!  temperatures between 223 and 323 K.
38!
39!  Parameters:
40!
41!    Input, double precision T, the temperature, in degrees Kelvin.
42!
43!    Output, double precision sc, the entropy of condensate, in J kg^-1 K^-1.
44!            double precision sv, the entropy of gas, in J kg^-1 K^-1.
45!
46
47  implicit none
48
49  double precision T,sc,sv
50
51  sv = 0.0492*T**2 - 40.4199*T + 1.2708e+004
52  sc = -0.0215*T**2 + 28.7138*T - 5.5267e+003
53
54  !L = -11.2373*T**2 + 2.5326d+03*T + 1.4099d+06
55
56end subroutine latheat_NH3
57
58
59! ---------------------
60! H2O
61! ---------------------
62
63subroutine base ( t, rho, ab, cvb, dpdrb, dpdtb, gb, hb, pb, sb, ub )
64!
65!*******************************************************************************
66!
67!! BASE calculates quantities associated with the base Helmholtz function.
68!
69!
70!  Discussion:
71!
72!    The equation for the base Helmholtz function AB(T,RHO) is:
73!
74!      AB(T,RHO) = R * T * (
75!        - ln ( 1 - y )
76!        - ( beta - 1 ) / ( 1 - y )
77!        + ( alpha + beta + 1 ) / ( 2 * ( 1 - y )**2 )
78!        + 4 * y * ( ( Bbar / b ) - gamma )
79!        - 0.5 * ( alpha - beta + 3 )
80!        + ln ( RHO * R * T / P0 ) )
81!                                                      (Equation 2)
82!   where
83!
84!     y = b * rho / 4,
85!     alpha = 11,
86!     beta = 133/3,
87!     gamma = 7/2,
88!     P0 = 0.101325 MegaPascals = 1 atm
89!
90!   and
91!
92!     b(T) = b1 * ln(T/T0) + sum(j=0,1,3,5) b(j)*(T0/T)**j  (Equation 3)
93!
94!     Bbar(T) = sum(j=0,1,2,4) B(j)*(T0/T)**j               (Equation 4).
95!
96!   where
97!
98!     T0=647.073 K and the coefficients b(j) and B(j) are
99!   
100!     j    b(j)                         B(j)
101!    --    -----------                  ----------
102!     0    0.7478629                    1.1278334
103!     1   -0.3540782                   -0.5944001
104!     2    0                           -5.010996
105!     3    0.007159876                  0
106!     4    0                            0.63684256
107!     5   -0.003528426                  0
108!
109!  For the derived quantities, the following relations are used:
110!
111!    Pressure:                  PB      = RHO**2 * dAB/dRHO
112!    Density derivative:        DPDRB   = 2*PB/RHO + RHO**2 * d2AB/dRHO2
113!    Temperature derivative:    DPDTB   = RHO**2 * d2AB/(dRHO dT)
114!    Specific entropy:          SB      = ( UB - AB ) / T
115!    Specific internal energy:  UB      = AB + T * SB
116!    Specific enthalpy:         HB      = UB + PB / RHO
117!    Specific heat capacity
118!      at constant volume:      CVB     = - T * d2AB/dT2
119!    Specific Gibbs function:   GB      = AB + PB / RHO
120!
121!
122!  Reference:
123!
124!    Lester Haar, John Gallagher and George Kell,
125!    NBS/NRC Steam Tables:
126!    Thermodynamic and Transport Properties and Computer Programs
127!      for Vapor and Liquid States of Water in SI Units,
128!    Hemisphere Publishing Corporation, Washington, 1984,
129!    TJ270.H3
130!
131!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
132!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
133!    American Society of Mechanical Engineers, 1967.
134!
135!  Modified:
136!
137!    03 February 2002
138!
139!  Parameters:
140!
141!    Input, double precision T, the temperature, in degrees Kelvin.
142!
143!    Input, double precision RHO, the density, in G/CM3.
144!
145!    Output, double precision AB, the base value of the Helmholtz function,
146!    in KJ/kg.
147!
148!    Output, double precision CVB, the base value of the isochoric (constant
149!    volume) heat capacity, in KJ/(kg degrees Kelvin).
150!
151!    Output, double precision DPDRB, the base value of the partial
152!    derivative dP(T,RHO)/dRHO, with T held fixed, in (MegaPascals CM3)/G.
153!
154!    Output, double precision DPDTB, the base value of the partial
155!    derivative dP(T,RHO)/dT, with RHO held fixed, in
156!    MegaPascals/degrees Kelvin.
157!
158!    Output, double precision GB, the base value of the Gibbs free energy,
159!    in KJ/kg.
160!
161!    Output, double precision HB, the base value of enthalpy, in KJ/kg.
162!
163!    Output, double precision PB, the base pressure, in MegaPascals.
164!
165!    Output, double precision SB, the base value of entropy,
166!    in KJ/(kg degrees Kelvin).
167!
168!    Output, double precision UB, the base value of internal energy,
169!    in KJ/kg.
170!
171  implicit none
172!
173  double precision ab
174  double precision, parameter :: alpha = 11.0D+00
175  double precision b1
176  double precision b1t
177  double precision b1tt
178  double precision b2
179  double precision b2t
180  double precision b2tt
181  double precision, parameter :: beta = 44.333333333333D+00
182  double precision cvb
183  double precision dpdrb
184  double precision dpdtb
185  double precision dz
186  double precision dz0
187  double precision, parameter :: gamma = 3.5D+00
188  double precision gascon
189  double precision gb
190  double precision hb
191  double precision, parameter :: p_zero = 0.101325D+00
192  double precision pb
193  double precision rho
194  double precision sb
195  double precision t
196  double precision ub
197  double precision x
198  double precision y
199  double precision z
200  double precision z0
201!
202!  Refuse to handle zero or negative temperatures.
203!
204  if ( t <= 0.0 ) then
205    write ( *, '(a)' ) ' '
206    write ( *, '(a)' ) 'BASE - Fatal error!'
207    write ( *, '(a)' ) '  The input temperature T must be positive.'
208    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
209    stop
210  end if
211!
212!  Refuse to handle zero or negative density.
213!
214  if ( rho <= 0.0D+00 ) then
215    write ( *, '(a)' ) ' '
216    write ( *, '(a)' ) 'BASE - Fatal error!'
217    write ( *, '(a)' ) '  The input density RHO must be positive.'
218    write ( *, '(a,g14.6)' ) '  Input value was RHO = ', rho
219    stop
220  end if
221!
222!  Compute auxilliary quantities for Equation 2.
223!
224  call bb ( t, b1, b2, b1t, b2t, b1tt, b2tt )
225
226  y = 0.25D+00 * b1 * rho
227
228  x = 1.0D+00 - y
229!
230!  Evaluate Equation 2.
231!
232  ab =   - log ( 1.0D+00 - y ) &
233         - ( beta - 1.0D+00 ) / ( 1.0D+00 - y ) &
234         + ( alpha + beta + 1.0D+00 ) / ( 2.0D+00 * ( 1.0D+00 - y )**2 ) &
235         + 4.0D+00 * y * ( ( b2 / b1 ) - gamma ) &
236         - 0.5D+00 * ( alpha - beta + 3.0D+00 ) &
237         + log ( rho * gascon() * t / p_zero )
238!
239!  Determine quantities defined in terms of AB.
240!
241  pb = ( 1.0D+00 + alpha * y + beta * y**2 ) / ( 1.0D+00 - y )**3 &
242    + 4.0D+00 * y * ( b2 / b1 - gamma )
243
244  z0 = ( 1.0D+00 + alpha * y + beta * y**2 ) / ( 1.0D+00 - y )**3
245
246  z = z0 + 4.0D+00 * y * ( b2 / b1 - gamma )
247
248  dz0 = ( alpha + 2.0D+00 * beta * y ) / ( 1.0D+00 - y )**3 &
249    + 3.0D+00 * ( 1.0D+00 + alpha * y + beta * y**2 ) / ( 1.0D+00 - y )**4
250
251  dz = dz0 + 4.0D+00 * ( b2 / b1 - gamma )
252
253  gb = ab + pb
254
255  ub = - t * b1t * ( pb - 1.0D+00 - rho * b2 ) / b1 - rho * t * b2t
256
257  hb = pb + ub
258!
259!  An incorrect version of this equation began:
260!
261!    cvb = 2.0D+00 * ub + ( pb - 1.0D+00 ) &
262!
263!  and caused me no end of trouble.  My fault, JVB, 03 February 2002
264!
265  cvb = 2.0D+00 * ub + ( z0 - 1.0D+00 ) &
266    * ( ( t * b1t / b1 )**2 - t**2 * b1tt / b1 ) &
267    - rho * t**2 * ( b2tt - gamma * b1tt ) - ( t * b1t / b1 )**2 * y * dz0
268
269  dpdtb = pb / t + rho * ( 0.25D+00 * ( dz0 + 4.0D+00 * ( b2 / b1 - gamma ) ) &
270    * b1t + b2t - b2 / b1 * b1t )
271
272  sb = ub - ab
273
274  dpdrb = pb + y * ( dz0 + 4.0D+00 * ( b2 / b1 - gamma ) )
275!
276!  Assign dimensions.
277!
278  ab =    gascon() * t       * ab
279  cvb =   gascon()           * cvb
280  dpdrb = gascon() * t       * dpdrb
281  dpdtb = gascon() * t * rho * dpdtb
282  gb =    gascon() * t       * gb
283  hb =    gascon() * t       * hb
284  pb =    gascon() * t * rho * pb
285  sb =    gascon()           * sb
286  ub =    gascon() * t       * ub
287
288  return
289end subroutine base
290
291subroutine bb ( t, b1, b2, b1t, b2t, b1tt, b2tt )
292!
293!*******************************************************************************
294!
295!! BB calculates the B's of equations 3 and 4. 
296!
297!
298!  Discussion:
299!
300!    Here
301!
302!      b(T) = b1 * ln(T/T0) + sum(j=0,1,3,5) b(j)*(T0/T)**j  (Equation 3)
303!
304!      Bbar(T) = sum(j=0,1,2,4) B(j)*(T0/T)**j               (Equation 4).
305!
306!    where
307!
308!      T0 = 647.073 K
309!
310!    and the coefficients b(j) and B(j) are
311!   
312!      j    b(j)                         B(j)
313!     --    -----------                  ----------
314!      0    0.7478629                    1.1278334
315!      1   -0.3540782                   -0.5944001
316!      2    0                           -5.010996
317!      3    0.007159876                  0
318!      4    0                            0.63684256
319!      5   -0.003528426                  0
320!
321!
322!  Reference:
323!
324!    Lester Haar, John Gallagher and George Kell,
325!    NBS/NRC Steam Tables:
326!    Thermodynamic and Transport Properties and Computer Programs
327!      for Vapor and Liquid States of Water in SI Units,
328!    Hemisphere Publishing Corporation, Washington, 1984,
329!    TJ270.H3
330!
331!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
332!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
333!    American Society of Mechanical Engineers, 1967.
334!
335!  Parameters:
336!
337!    Input, double precision T, the temperature, in degrees Kelvin.
338!
339!    Output, double precision B1, the coefficient b from equation 3,
340!    in CM3/G.
341!
342!    Output, double precision B2, the coefficient Bbar from equation 4,
343!    in CM3/G.
344!
345!    Output, double precision B1T, the derivative dB1/dT,
346!    in (CM3)/(G Degrees Kelvin).
347!
348!    Output, double precision B2T, the derivative dB2/dT,
349!    in (CM3)/(G Degrees Kelvin).
350!
351!    Output, double precision B1TT, the second derivative of B1 with
352!    respect to T, in (CM3)/(G (Degrees Kelvin)**2 ).
353!
354!    Output, double precision B2TT, the second derivative of B2 with
355!    respect to T, in (CM3)/(G (Degrees Kelvin)**2 ).
356!
357  implicit none
358!
359  double precision b1
360  double precision b1t
361  double precision b1tt
362  double precision b2
363  double precision b2t
364  double precision b2tt
365  double precision, parameter, dimension ( 10 ) :: bp = (/ &
366    0.7478629D+00,   -0.3540782D+00,    0.0D+00,           0.0D+00, &
367    0.007159876D+00,  0.0D+00,         -0.003528426D+00,   0.0D+00, &
368    0.0D+00,          0.0D+00 /)
369  double precision, parameter, dimension ( 10 ) :: bq = (/ &
370    1.1278334D+00,    0.0D+00,         -0.5944001D+00,   -5.010996D+00, &
371    0.0D+00,          0.63684256D+00,   0.0D+00,          0.0D+00, &
372    0.0D+00,          0.0D+00 /)
373  integer i
374  double precision t
375  double precision, parameter :: t_ref = 647.073D+00
376  double precision v(10)
377!
378!  Refuse to handle zero or negative temperatures.
379!
380  if ( t <= 0.0D+00 ) then
381    write ( *, '(a)' ) ' '
382    write ( *, '(a)' ) 'BB - Fatal error!'
383    write ( *, '(a)' ) '  The input temperature T must be positive.'
384    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
385    stop
386  end if
387!
388!  Set V(I) = ( T_REF / T )**(I-1).
389!
390  v(1) = 1.0D+00
391  do i = 2, 10
392    v(i) = v(i-1) * t_ref / t
393  end do
394!
395!  Set B1, B1T, B1TT.
396!
397  b1 = bp(1) + bp(2) * log ( 1.0D+00 / v(2) )
398  b1t = bp(2) * v(2) / t_ref
399  b1tt = 0.0D+00
400  do i = 3, 10
401    b1 = b1 + bp(i) * v(i-1)
402    b1t = b1t - dble ( i - 2 ) * bp(i) * v(i-1) / t
403    b1tt = b1tt + bp(i) * dble ( i - 2 )**2 * v(i-1) / t**2
404  end do
405
406  b1tt = b1tt -  ( b1t / t )
407!
408!  Set B2, B2T, B2TT.
409!
410  b2 = bq(1)
411  b2t = 0.0D+00
412  b2tt = 0.0D+00
413  do i = 3, 10
414    b2 = b2 + bq(i) * v(i-1)
415    b2t = b2t - dble ( i - 2 ) * bq(i) * v(i-1) / t
416    b2tt = b2tt + bq(i) * dble ( i - 2 )**2 * v(i-1) / t**2
417  end do
418
419  b2tt = b2tt - ( b2t / t )
420
421  return
422end subroutine bb
423
424
425subroutine ideal ( t, ai, cpi, cvi, gi, hi, si, ui )
426!
427!*******************************************************************************
428!
429!! IDEAL computes ideal gas thermodynamic properties of water.
430!
431!
432!  Discussion:
433!
434!    Values for thermodynamic properties of water in the ideal
435!    gas state were reported by Woolley.  The formula for the ideal gas
436!    term of the Helmholtz function approximates a term by term summation of
437!    contributions from each of the rotation and vibration states. 
438!    The formula, equation #6 in the reference, is:
439!   
440!    A(ideal)(T) = -R * T * ( 1 + ( C(1)/Tr + C(2) ) * ln(Tr)
441!      + Sum ( 3 <= I <= 18) C(I) * Tr**(I-6)
442!   
443!    where Tr=T/100 K.  The C(i) are tabulated coefficients.  Equation
444!    6 can be used for temperatures below 3000 K, and is accurate to
445!    within the tolerance of the gas constant for 50<=T<=2000 K.
446!     
447!  Reference:
448!
449!    Lester Haar, John Gallagher and George Kell,
450!    NBS/NRC Steam Tables:
451!    Thermodynamic and Transport Properties and Computer Programs
452!      for Vapor and Liquid States of Water in SI Units,
453!    Hemisphere Publishing Corporation, Washington, 1984,
454!    TJ270.H3
455!
456!  Parameters:
457!
458!    Input, double precision T, the temperature, in degrees Kelvin.
459!
460!    Output, double precision AI, the Helmholtz function, in KJ/kg.
461!
462!    Output, double precision CPI, the heat capacity at constant pressure,
463!    in KJ/(kg degrees Kelvin).
464!
465!    Output, double precision CVI, the heat capacity at constant volume,
466!    in KJ/(kg degrees Kelvin).
467!
468!    Output, double precision GI, the Gibbs free energy, in KJ/kg.
469!
470!    Output, double precision HI, the enthalpy, in KJ/kg.
471!
472!    Output, double precision SI, the entropy, in KJ/(kg degrees Kelvin).
473!
474!    Output, double precision UI, the internal energy, in KJ/kg.
475!
476  implicit none
477!
478  double precision ai
479  double precision, parameter, dimension ( 18 ) :: c = (/ &
480   19.730271018D+00,      20.9662681977D+00,     -0.483429455355D+00, &
481    6.05743189245D+00,    22.56023885D+00,       -9.87532442D+00, &
482   -4.3135538513D+00,      0.458155781D+00,      -0.047754901883D+00, &
483    0.0041238460633D+00,  -0.00027929052852D+00,  0.14481695261D-04, &
484   -0.56473658748D-06,     0.16200446D-07,       -0.3303822796D-09, &
485    0.451916067368D-11,   -0.370734122708D-13,    0.137546068238D-15 /)
486  double precision cpi
487  double precision cvi
488  double precision gascon
489  double precision gi
490  double precision hi
491  integer i
492  double precision si
493  double precision t
494  double precision temp
495  double precision tt
496  double precision ui
497!
498!  Refuse to handle zero or negative temperatures.
499!
500  if ( t <= 0.0D+00 ) then
501    write ( *, '(a)' ) ' '
502    write ( *, '(a)' ) 'IDEAL - Fatal error!'
503    write ( *, '(a)' ) '  The input temperature T must be positive.'
504    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
505    stop
506  end if
507
508  tt = t / 100.0D+00
509
510  gi = - ( c(1) / tt + c(2) ) * log ( tt )
511  do i = 3, 18
512    gi = gi - c(i) * tt**(i-6)
513  end do
514
515  hi = c(2) + c(1) * ( 1.0D+00 - log ( tt ) ) / tt
516  do i = 3, 18
517    hi = hi + dble ( i - 6 ) * c(i) * tt**(i-6)
518  end do
519
520  cpi = c(2) - c(1) / tt
521  do i = 3, 18
522    cpi = cpi + dble ( ( i - 6 ) * ( i - 5 ) ) * c(i) * tt**(i-6)
523  end do
524
525  ai = gi - 1.0D+00
526  ui = hi - 1.0D+00
527  cvi = cpi - 1.0D+00
528  si = hi - gi
529!
530!  Assign dimensions.
531!
532  ai =  gascon() * t * ai
533  cpi = gascon()     * cpi
534  cvi = gascon()     * cvi
535  gi =  gascon() * t * gi
536  hi =  gascon() * t * hi
537  si =  gascon()     * si
538  ui =  gascon() * t * ui
539
540  return
541end subroutine ideal
542
543
544subroutine resid ( t, rho, ar, cvr, dpdrr, dpdtr, gr, hr, pr, sr, ur )
545!
546!*******************************************************************************
547!
548!! RESID calculates residual contributions to thermodynamic quantities.
549!
550!
551!  Discussion:
552!
553!    The residual function consists of 40 terms.  The first 36 are
554!    used in a global least squares fit to experimental data.
555!
556!    Three terms were added that contribute only in the immediate
557!    neighborhood of the critical point
558!      (tk-5) <= T <= (tk+5) C
559!      0.20   <= rho <= 0.44 g/cm3,
560!
561!    A single term was added for the region of high pressure and
562!    low temperature: T < 75 C, P > 300 MPa.
563!
564!    Except in these limited regions, the residual function is
565!    given by the first 36 terms.  The equation is
566!   
567!      A(residual)(rho,T)=
568!        sum(i=1 to 36) (g(i)/k(i)) * (T0/T)**(l(i)) (1-exp(-rho))**(k(i))
569!      + sum(i=37 to 40) g(i)*delta(i)**(k(i))
570!        * exp(-alpha(i)*delta(i)**(k(i)) - beta(i)*tau(i)**2)
571!                                                     (Equation 5)
572!   
573!    where
574!
575!      g(i) are coefficients determined by fits to data,
576!      delta(i) are reduced densities (delta(i)=((rho-rho(i))/rho(i))
577!      tau(i) are reduced temperatures (tau(i)=((T-tau(i))/tau(i))
578!      rho(i) are specified densities.
579!      tau(i) are specified temperatures.
580!      The k(i) and l(i) are specified integers.
581!   
582!  Modified:
583!
584!    22 November 1998
585!
586!  Reference:
587!
588!    Lester Haar, John Gallagher and George Kell,
589!    NBS/NRC Steam Tables:
590!    Thermodynamic and Transport Properties and Computer Programs
591!      for Vapor and Liquid States of Water in SI Units,
592!    Hemisphere Publishing Corporation, Washington, 1984,
593!    TJ270.H3
594!
595!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
596!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
597!    American Society of Mechanical Engineers, 1967.
598!
599!  Parameters:
600!
601!    Input, double precision T, the temperature, in degrees Kelvin.
602!
603!    Input, double precision RHO, the density, in G/CM3.
604!
605!    Output, double precision AR, the residual contribution to the
606!    Helmholtz function, in KJ/kg.
607!
608!    Output, double precision CVR, the residual contribution to the
609!    isochoric (constant volume) heat capacity, in KJ/(kg degrees Kelvin).
610!
611!    Output, double precision DPDRR, the residual contribution to
612!    the partial derivative dP(T,RHO)/dRHO, with T held fixed, in
613!    (MegaPascals CM3)/G.
614!
615!    Output, double precision DPDTR, the residual contribution to
616!    the partial derivative dP(T,RHO)/dT, with RHO held fixed,
617!    in MegaPascals/degrees Kelvin.
618!
619!    Output, double precision GR, the residual contribution to the Gibbs
620!    function, in KJ/kg.
621!
622!    Output, double precision HR, the residual contribution to the
623!    enthalpy, in KJ/kg.
624!
625!    Output, double precision PR, the residual contribution to the pressure,
626!    in MegaPascals.
627!
628!    Output, double precision SR, the residual contribution to the entropy,
629!    in KJ/(kg degrees Kelvin).
630!
631!    Output, double precision UR, the residual contribution to the
632!    internal energy, in KJ/kg.
633!
634  implicit none
635!
636  double precision, parameter, dimension ( 4 ) :: aad = (/ &
637    34.0D+00, 40.0D+00, 30.0D+00, 1050.0D+00 /)
638  double precision, parameter, dimension ( 4 ) :: aat = (/ &
639    20000.0D+00, 20000.0D+00, 40000.0D+00, 25.0D+00 /)
640  double precision, parameter, dimension ( 4 ) :: adz = (/ &
641    0.319D+00, 0.319D+00, 0.319D+00, 1.55D+00 /)
642  double precision ar
643  double precision att
644  double precision, parameter, dimension ( 4 ) ::  atz = (/ &
645    640.0D+00, 640.0D+00, 641.6D+00, 270.0D+00 /)
646  double precision cvr
647  double precision dadt
648  double precision ddz
649  double precision del
650  double precision dex
651  double precision dfdt
652  double precision dpdrr
653  double precision dpdtr
654  double precision e
655  double precision errtol
656  double precision ex0
657  double precision ex1
658  double precision ex2
659  double precision fct
660  double precision, parameter, dimension ( 40 ) :: g = (/ &
661    -530.62968529023D+00,  0.22744901424408D+04, 0.78779333020687D+03, &
662    -69.830527374994D+00,  0.17863832875422D+05,-0.39514731563338D+05, &
663    0.33803884280753D+05, -0.13855050202703D+05,-0.25637436613260D+06, &
664    0.48212575981415D+06, -0.34183016969660D+06, 0.12223156417448D+06, &
665    0.11797433655832D+07, -0.21734810110373D+07, 0.10829952168620D+07, &
666   -0.25441998064049D+06, -0.31377774947767D+07, 0.52911910757704D+07, &
667   -0.13802577177877D+07, -0.25109914369001D+06, 0.46561826115608D+07, &
668   -0.72752773275387D+07,  0.41774246148294D+06, 0.14016358244614D+07, &
669   -0.31555231392127D+07,  0.47929666384584D+07, 0.40912664781209D+06, &
670   -0.13626369388386D+07,  0.69625220862664D+06,-0.10834900096447D+07, &
671   -0.22722827401688D+06,  0.38365486000660D+06, 0.68833257944332D+04, &
672    0.21757245522644D+05, -0.26627944829770D+04,-0.70730418082074D+05, &
673   -0.225D+00, -1.68D+00, 0.055D+00, -93.0D+00 /)
674  double precision gascon
675  double precision gr
676  double precision hr
677  integer i
678  integer, parameter, dimension ( 40 ) :: ii = (/ &
679    0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6, &
680    8,8,8,8,2,2,0,4,2,2,2,4 /)
681  integer j
682  integer, parameter, dimension ( 40 ) :: jj = (/ &
683    2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,&
684    2,3,5,7,1,4,4,4,0,2,0,0 /)
685  integer k
686  integer l
687  integer nc
688  double precision pr
689  double precision q10
690  double precision q20
691  double precision q2a
692  double precision q5t
693  double precision qm
694  double precision qp
695  double precision qr(11)
696  double precision qt(10)
697  double precision rho
698  double precision sr
699  double precision, parameter :: s_ref = 7.6180720166752D+00
700  double precision t
701  double precision, parameter :: t_ref = 647.073D+00
702  double precision tau
703  double precision tx
704  double precision, parameter :: u_ref = - 4328.4549774261D+00
705  double precision ur
706  double precision v
707!
708  errtol = sqrt ( epsilon ( errtol ) )
709!
710!  Refuse to handle zero or negative temperatures.
711!
712  if ( t <= 0.0D+00 ) then
713    write ( *, '(a)' ) ' '
714    write ( *, '(a)' ) 'RESID - Fatal error!'
715    write ( *, '(a)' ) '  The input temperature T must be positive.'
716    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
717    stop
718  end if
719!
720!  Refuse to handle zero or negative density.
721!
722  if ( rho <= 0.0D+00 ) then
723    write ( *, '(a)' ) ' '
724    write ( *, '(a)' ) 'RESID - Fatal error!'
725    write ( *, '(a)' ) '  The input density RHO must be positive.'
726    write ( *, '(a,g14.6)' ) '  Input value was RHO = ', rho
727    stop
728  end if
729
730  nc = 36
731  dpdrr = 0.0D+00
732  pr = 0.0D+00
733  ar = 0.0D+00
734  dadt = 0.0D+00
735  cvr = 0.0D+00
736  dpdtr = 0.0D+00
737
738  ex0 = - rho
739! ex0 = max ( ex0, - 225.0D+00 )
740! ex0 = min ( ex0, 225.0D+00 )
741  e = exp ( ex0 )
742
743  q10 = rho * rho * e
744  q20 = 1.0D+00 - e
745
746  qr(1) = 0.0D+00
747  qr(2) = q10
748  do i = 2, 10
749    qr(i+1) = qr(i) * q20
750  end do
751
752  v = t_ref / t
753  qt(1) = t / t_ref
754  do i = 2, 10
755    qt(i) = qt(i-1) * v
756  end do
757
758  do i = 1, nc
759
760    k = ii(i) + 1
761    l = jj(i)
762    qp = g(i) * qr(k+1) * qt(l+1)
763    pr = pr + qp
764
765    dpdrr = dpdrr + ( 2.0D+00 / rho - ( 1.0D+00 - e * dble ( k - 1 ) / &
766      ( 1.0D+00 - e ) ) ) * qp
767
768    ar = ar + g(i) * qr(k+2) * qt(l+1) / ( rho**2 * e * dble ( k ) &
769      * gascon ( ) * t )
770
771    dfdt = ( 1.0D+00 - e )**k * dble ( 1 - l ) * qt(l+2) / t_ref / dble ( k )
772
773    dadt = dadt + g(i) * dfdt
774
775    dpdtr = dpdtr + g(i) * dfdt * rho**2 * e * dble ( k ) / ( 1.0D+00 - e )
776
777    cvr = cvr + g(i) * dble ( l ) * dfdt / gascon()
778
779  end do
780
781  qp = 0.0D+00
782  q2a = 0.0D+00
783
784  do j = 37, 40
785
786    k = ii(j)
787    ddz = adz(j-36)
788    del = rho / ddz - 1.0D+00
789
790    if ( abs ( del ) < errtol ) then
791      del = errtol
792    end if
793
794    ex1 = - aad(j-36) * del**k
795!   ex1 = max ( ex1, - 225.0D+00 )
796!   ex1 = min ( ex1, 225.0D+00 )
797    dex = exp ( ex1 ) * del**jj(j)
798
799    att = aat(j-36)
800    tx = atz(j-36)
801    tau = ( t / tx ) - 1.0D+00
802
803    ex2 = - att * tau**2
804!   ex2 = max ( ex2, - 225.0D+00 )
805!   ex2 = min ( ex2, 225.0D+00 )
806    q10 = dex * exp ( ex2 )
807
808    qm = dble ( jj(j) ) / del - dble ( k ) * aad(j-36) * del**(k-1)
809    fct = qm * rho**2 * q10 / ddz
810
811    q5t = fct * ( 2.0D+00 / rho + qm / ddz ) - ( rho / ddz )**2 * q10 * &
812      ( dble ( jj(j) ) / del**2 + dble ( k * ( k - 1 ) ) * aad(j-36) * &
813      del**(k-2) )
814
815    dpdrr = dpdrr + q5t * g(j)
816    qp = qp + g(j) * fct
817    dadt = dadt - 2.0D+00 * g(j) * att * tau * q10 / tx
818    dpdtr = dpdtr - 2.0D+00 * g(j) * att * tau * fct / tx
819
820    q2a = q2a + t * g(j) * att * ( 4.0D+00 * ex2 + 2.0D+00 ) * q10 / tx**2
821
822    ar = ar + q10 * g(j) / ( gascon() * t )
823
824  end do
825
826  cvr = cvr + q2a / gascon()
827  pr = pr + qp
828  sr = - dadt / gascon()
829  ur = ar + sr
830!
831!  Assign dimensions.
832!
833  ar =  gascon() * t *  ar
834  cvr = gascon() *     cvr
835  sr =  gascon() *      sr
836  ur =  gascon() * t *  ur
837!
838!  Adjust energies.
839!
840  ar = ar + gascon ( ) * t * s_ref - gascon ( ) * u_ref
841  sr = sr - gascon ( ) * s_ref
842  ur = ur - gascon ( ) * u_ref
843
844  gr = ar + pr / rho
845  hr = ur + pr / rho
846
847  return
848end subroutine resid
849
850subroutine psat_H2O ( t, p )
851!
852!*******************************************************************************
853!
854!! PSAT_H2O makes a rough estimate of the vapor pressure.
855!
856!
857!  Discussion:
858!
859!    The calculation agrees with tabulated data to within
860!    0.02% for temperature to within a degree or so of the critical
861!    temperature.  The approximate vapor pressure can be refined
862!    by imposing the condition that the Gibbs functions of the vapor
863!    and liquid phases be equal.
864!
865!  Modified:
866!
867!    21 November 1998
868!
869!  Reference:
870!
871!    Lester Haar, John Gallagher and George Kell,
872!    NBS/NRC Steam Tables:
873!    Thermodynamic and Transport Properties and Computer Programs
874!      for Vapor and Liquid States of Water in SI Units,
875!    Hemisphere Publishing Corporation, Washington, 1984,
876!    TJ270.H3
877!
878!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
879!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
880!    American Society of Mechanical Engineers, 1967.
881!
882!  Parameters:
883!
884!    Input, double precision T, the temperature, in degrees Kelvin.
885!
886!    Output, double precision P, the vapor pressure, in MegaPascals.
887!
888  implicit none
889!
890  double precision, parameter, dimension ( 8 ) :: a = (/ &
891    -7.8889166D+00,   2.5514255D+00,   -6.716169D+00, 33.239495D+00, &
892    -105.38479D+00,   174.35319D+00,  -148.39348D+00, 48.631602D+00 /)
893  double precision b
894  integer i
895  double precision p
896  double precision q
897  double precision t
898  double precision, parameter :: t_ref = 647.25D+00
899  double precision v
900  double precision w
901  double precision z
902!
903!  Refuse to handle zero or negative temperatures.
904!
905  if ( t <= 0.0D+00 ) then
906    write ( *, '(a)' ) ' '
907    write ( *, '(a)' ) 'PSAT_H2O - Fatal error!'
908    write ( *, '(a)' ) '  The input temperature T must be positive.'
909    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
910    stop
911  end if
912
913  if ( t <= 314.0D+00 ) then
914
915    p = 0.1D+00 * exp ( 6.3573118D+00 - 8858.843D+00 / t &
916      + 607.56335D+00 * t**( -0.6D+00 ) )
917
918  else
919
920    v = t / t_ref
921    w = abs ( 1.0D+00 - v )
922    b = 0.0D+00
923    do i = 1, 8
924      z = i
925      b = b + a(i) * w**( ( z + 1.0D+00 ) / 2.0D+00 )
926    end do
927
928    q = b / v
929    p = 22.093D+00 * exp ( q )
930
931  end if
932
933  return
934end subroutine psat_H2O
935
936
937subroutine tdpsdt ( t, dp )
938!
939!*******************************************************************************
940!
941!! TDPSDT computes the quantity T * dP(Sat)/dT.
942!
943!
944!  Discussion:
945!
946!    Here T is the temperature and P(Sat) is the vapor pressure. 
947!    It is used by TSAT_EST and TSAT.
948!
949!  Reference:
950!
951!    Lester Haar, John Gallagher and George Kell,
952!    NBS/NRC Steam Tables:
953!    Thermodynamic and Transport Properties and Computer Programs
954!      for Vapor and Liquid States of Water in SI Units,
955!    Hemisphere Publishing Corporation, Washington, 1984,
956!    TJ270.H3
957!
958!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
959!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
960!    American Society of Mechanical Engineers, 1967.
961!
962!  Parameters:
963!
964!    Input, double precision T, the temperature, in degrees Kelvin.
965!
966!    Output, double precision DP, the value T*(dP(Sat)/dT),
967!    in MegaPascals.
968!
969  implicit none
970!
971  double precision, parameter, dimension ( 8 ) :: a = (/ &
972      -7.8889166D+00,   2.5514255D+00,   -6.716169D+00, 33.239495D+00, &
973    -105.38479D+00,   174.35319D+00,   -148.39348D+00,  48.631602D+00 /)
974  double precision b
975  double precision c
976  double precision dp
977  integer i
978  double precision q
979  double precision t
980  double precision, parameter :: t_ref = 647.25D+00
981  double precision v
982  double precision w
983  double precision y
984  double precision z
985!
986!  Refuse to handle zero or negative temperatures.
987!
988  if ( t <= 0.0D+00 ) then
989    write ( *, '(a)' ) ' '
990    write ( *, '(a)' ) 'TDPSDT - Fatal error!'
991    write ( *, '(a)' ) '  The input temperature T must be positive.'
992    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
993    stop
994  end if
995
996  v = t / t_ref
997  w = 1.0D+00 - v
998  b = 0.0D+00
999  c = 0.0D+00
1000  do i = 1, 8
1001    z = dble ( i + 1 ) / 2.0D+00
1002    y = a(i) * w**z
1003    c = c + ( y / w ) * ( 0.5D+00 - 0.5D+00 * dble ( i ) - 1.0D+00 / v )
1004    b = b + y
1005  end do
1006
1007  q = b / v
1008  dp = 22.093D+00 * exp ( q ) * c
1009
1010  return
1011end subroutine tdpsdt
1012
1013
1014
1015subroutine therm ( t, rho, a, cjth, cjtt, cp, cv, dpdr, dpdt, g, h, p, s, u )
1016!
1017!*******************************************************************************
1018!
1019!! THERM calculates thermodynamic functions given temperature and density.
1020!
1021!
1022!  Discussion:
1023!
1024!    Thermodynamic values were calculated from an analytic equation
1025!    that approximates the Helmholtz function (specific Helmholtz
1026!    energy) for ordinary water and steam, of the form A=A(rho,T)
1027!    where A is the Helmholtz function, rho the density, and T
1028!    the absolute (thermodynamic) temperature.  Any thermodynamic
1029!    value for any state, liquid, vapor or metastable, may be
1030!    calculated by differentiation of this equation in accord with
1031!    the first and second laws of thermodynamics.
1032!
1033!    The International Association for the Properties of Steam
1034!    has provisionally accepted this formulation for the range
1035!    273.15 <= T <= 1273.15 degrees Kelvin, where, for 423.15 <= T,
1036!    the maximum pressure is Pmax = 1500 MPa = 15000 bar, and for
1037!    273.15 <= T < 423.15, the maximum pressure is
1038!    Pmax = 100 * (5 + (T-273.15)/15) MPa.
1039!
1040!    Close to the critical point, a small region is excluded:
1041!    Abs(T-Tk) < 1, abs((rho-rhok)/rhok) < 0.3.
1042!
1043!    The equation has a wider useful range, namely, fluid states
1044!    of pure, undissociated water and steam defined by
1045!    260 <= T <= 2500 K and 0 <= P <= 3000 MPa.
1046!
1047!    Thermodynamic property values for specific volume, density,
1048!    specific internal energy, specific enthalpy, and specific
1049!    entropy of water and steam were tabulated over the range
1050!    0 <= t <= 2000 C, 0 <= P <= 3000 MPa.  The reference
1051!    state is the liquid at the triple point, for which the
1052!    internal energy and entropy have been assigned the value zero.
1053!     
1054!    Thermodynamic quantities are determined from the Helmholtz function
1055!    A(rho,T), which is computed as the sum of three terms:
1056!
1057!      A(rho,T) = A(base)(rho,T) + A(residual)(rho,T) + A(ideal)(T)
1058!                                                       (Equation 1)
1059!
1060!    Because A(rho,T) is everywhere single valued and analytic,
1061!    we can derive closed form relations for all other properties.
1062!    In the following, unless otherwise indicated, the independent
1063!    variables are temperature T and density RHO, and differentiation
1064!    with respect to one variable is to imply that the other is fixed.
1065!
1066!    Pressure:                  P       = RHO**2 * dA/dRHO
1067!    Density derivative:        dP/dRHO = 2*P/RHO + RHO**2 * d2A/dRHO2
1068!    Temperature derivative:    dP/dT   = RHO**2 * d2A/(dRHO dT)
1069!    Specific entropy:          S       = - dA/dT
1070!    Specific internal energy:  U       = A + T*S
1071!    Specific enthalpy:         H       = U + P/RHO
1072!    Specific heat capacity
1073!      at constant volume:      Cv      = - T * d2A/dT2
1074!    Specific Gibbs function:   G       = A + P/RHO
1075!    Specific heat capacity
1076!      at constant pressure:    Cp      = Cv + (T*(dP/dT)**2)/(RHO**2*dP/dRHO)
1077!    Speed of sound:            Omega   = Sqrt ((Cp/Cv) * dP/dRHO)
1078!    Second virial coefficient: B       = 1/(2*R*T) * (d2P/dRHO2) (at RHO=0)
1079!    Isothermal Joule-Thomson
1080!      coefficient:             DeltaT  = (dH/dP) (fixed T) =
1081!                                         (1/RHO)-(T*dP/dT)/(RHO**2*dP/dRHO)
1082!    Joule-Thomson coefficient: Mu      = (dT/dP) (fixed H) = DeltaT/Cp
1083!    Isentropic temperature-
1084!      pressure coefficient:    BetaS   = (dT/dP) (fixed S) =
1085!                                         (DeltaT - 1/RHO)/Cp
1086!   
1087!  Modified:
1088!
1089!    19 November 1998
1090!
1091!  Reference:
1092!
1093!    Lester Haar, John Gallagher and George Kell,
1094!    NBS/NRC Steam Tables:
1095!    Thermodynamic and Transport Properties and Computer Programs
1096!      for Vapor and Liquid States of Water in SI Units,
1097!    Hemisphere Publishing Corporation, Washington, 1984,
1098!    TJ270.H3
1099!
1100!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
1101!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
1102!    American Society of Mechanical Engineers, 1967.
1103!
1104!  Parameters:
1105!
1106!    Input, double precision T, the temperature, in degrees Kelvin.
1107!
1108!    Input, double precision RHO, the fluid density, in G/CM3.
1109!
1110!    Output, double precision A, the Helmholtz function, in KJ/kg.
1111!
1112!    Output, double precision CJTH, the Joule-Thomson coefficient,
1113!    in K/MegaPascals.
1114!
1115!    Output, double precision CJTT, the isothermal Joule-Thomson coefficient,
1116!    in CM3/G.
1117!
1118!    Output, double precision CP, the isobaric (constant pressure) heat
1119!    capacity, in KJ/(kg degrees Kelvin).
1120!
1121!    Output, double precision CV, the isochoric (constant volume) heat capacity,
1122!    in KJ/(kg degrees Kelvin).
1123!
1124!    Output, double precision DPDR, the partial derivative
1125!    dP(T,RHO)/dRHO, with T held fixed, in MegaPascals*CM3/G.
1126!
1127!    Output, double precision DPDT, the partial derivative
1128!    dP(T,RHO)/dT, with RHO held fixed, in MegaPascals/degrees Kelvin.
1129!
1130!    Output, double precision G, the Gibbs free energy, in KJ/kg.
1131!
1132!    Output, double precision H, the enthalpy, in KJ/kg.
1133!
1134!    Output, double precision P, the pressure, in MegaPascals.
1135!
1136!    Output, double precision S, the entropy, in KJ/(kg degrees Kelvin).
1137!
1138!    Output, double precision U, the internal energy, in KJ/kg.
1139!
1140  implicit none
1141!
1142  double precision a
1143  double precision ab
1144  double precision ai
1145  double precision ar
1146  double precision cjth
1147  double precision cjtt
1148  double precision cp
1149  double precision cpi
1150  double precision cv
1151  double precision cvb
1152  double precision cvi
1153  double precision cvr
1154  logical, parameter :: debug = .false.
1155!  logical, parameter :: debug = .true.
1156  double precision dpdr
1157  double precision dpdrb
1158  double precision dpdrr
1159  double precision dpdt
1160  double precision dpdtb
1161  double precision dpdtr
1162  double precision g
1163  double precision gb
1164  double precision gi
1165  double precision gr
1166  double precision h
1167  double precision hb
1168  double precision hi
1169  double precision hr
1170  double precision p
1171  double precision pb
1172  double precision pr
1173  double precision rho
1174  double precision s
1175  double precision sb
1176  double precision si
1177  double precision sr
1178  double precision t
1179  double precision u
1180  double precision ub
1181  double precision ui
1182  double precision ur
1183!
1184!  Refuse to handle zero or negative temperatures.
1185!
1186  if ( t <= 0.0D+00 ) then
1187    write ( *, '(a)' ) ' '
1188    write ( *, '(a)' ) 'THERM - Fatal error!'
1189    write ( *, '(a)' ) '  The input temperature T must be positive.'
1190    write ( *, '(a,g14.6)' ) '  Input value was T = ', t
1191    stop
1192  end if
1193!
1194!  Refuse to handle zero or negative density.
1195!
1196  if ( rho <= 0.0D+00 ) then
1197    write ( *, '(a)' ) ' '
1198    write ( *, '(a)' ) 'THERM - Fatal error!'
1199    write ( *, '(a)' ) '  The input density RHO must be positive.'
1200    write ( *, '(a,g14.6)' ) '  Input value was RHO = ', rho
1201    stop
1202  end if
1203
1204  call ideal ( t, ai, cpi, cvi, gi, hi, si, ui )
1205
1206  call resid ( t, rho, ar, cvr, dpdrr, dpdtr, gr, hr, pr, sr, ur )
1207
1208  call base ( t, rho, ab, cvb, dpdrb, dpdtb, gb, hb, pb, sb, ub )
1209
1210  a =       ab +    ar +  ai
1211  cv =     cvb +   cvr + cvi
1212
1213  if ( debug ) then
1214    write ( *, * ) ' '
1215    write ( *, * ) 'THERM:'
1216    write ( *, * ) '  CVB = ', cvb
1217    write ( *, * ) '  CVR = ', cvr
1218    write ( *, * ) '  CVI = ', cvi
1219    write ( *, * ) '  CV  = ', cv
1220  end if
1221
1222
1223  dpdr = dpdrb + dpdrr
1224  dpdt = dpdtb + dpdtr
1225  p =       pb +    pr
1226  s =       sb +    sr +  si
1227  u =       ub +    ur +  ui
1228
1229  if ( debug ) then
1230    write ( *, * ) ' '
1231    write ( *, * ) 'THERM:'
1232    write ( *, * ) '  UB = ', ub
1233    write ( *, * ) '  UR = ', ur
1234    write ( *, * ) '  UI = ', ui
1235  end if
1236
1237  g = a + p / rho
1238  h = u + p / rho
1239  cp = cv + t * dpdt**2 / ( dpdr * rho**2 )
1240  cjtt = 1.0D+00 / rho - t * dpdt / ( dpdr * rho**2 )
1241  cjth = - cjtt / cp
1242
1243  return
1244end subroutine therm
1245
1246function gascon ( )
1247!
1248!*******************************************************************************
1249!
1250!! GASCON returns the value of the specific gas constant.
1251!
1252!
1253!  Note:
1254!
1255!    The specific gas constant R is related to the universal gas
1256!    constant R-bar = 8.31441 J/(mol degrees Kelvin) by the molar mass
1257!    M = 18.0152 g/mol:
1258!
1259!      R = R-bar / M.
1260!
1261!  Reference:
1262!
1263!    Lester Haar, John Gallagher and George Kell,
1264!    NBS/NRC Steam Tables:
1265!    Thermodynamic and Transport Properties and Computer Programs
1266!      for Vapor and Liquid States of Water in SI Units,
1267!    Hemisphere Publishing Corporation, Washington, 1984,
1268!    TJ270.H3
1269!
1270!    C A Meyer, R B McClintock, G J Silvestri, R C Spencer,
1271!    ASME Steam Tables: Thermodynamic and Transport Properties of Steam,
1272!    American Society of Mechanical Engineers, 1967.
1273!
1274!  Parameters:
1275!
1276!    Output, double precision GASCON, the value of the specific gas
1277!    constant, in J/(g degrees Kelvin).
1278!
1279  implicit none
1280!
1281  double precision gascon
1282!
1283  gascon = 0.461522D+00
1284 
1285  return
1286end function gascon
Note: See TracBrowser for help on using the repository browser.