5 use simple_sat_vapor_pres_mod,
only: escomp, descomp
7 use constants_mod,
only: grav, rdgas, rvgas, kappa, latent_heat, &
8 cp_air, cp_vapor, cp_water
17 real(8),
public,
parameter ::
d622 = rdgas/rvgas
26 real(8),
intent(in),
dimension(:) :: t, q, p_full
27 real(8),
intent(in),
dimension(:) :: p_half
28 real(8),
intent(out),
dimension(:) :: z_full
29 real(8),
intent(out),
dimension(:) :: z_half
39 virtual_t = t(k) * (1. +
d608 * q(k))
40 z_half(k) = z_half(k+1) + rdgas* virtual_t *&
41 (log(p_half(k+1) / p_half(k)))
43 z_full(k) = z_half(k+1) + rdgas* virtual_t *&
44 (log(p_half(k+1) / p_full(k)))
47 virtual_t = t(1) * (1. +
d608 * q(1))
48 z_full(1) = z_half(2) + rdgas* virtual_t *&
49 (log(p_half(2) / p_full(1)))
59 real(8),
intent(in) :: t, p
60 real(8),
intent(out) :: qs
64 if (esat .le. p) qs =
d622 * esat / (p -
d378 * esat)
70 real(8),
intent(in) :: T, p
71 real(8),
intent(out):: dqs
72 real(8) :: esat, desat
74 call descomp(t, desat)
76 if ( esat .le. p) dqs =
d622 * p / (p -
d378 * esat)**2 * desat
82 real(8),
intent(in) :: T, p
83 real(8),
intent(out):: rs
87 if (esat .le. p) rs =
d622 * esat / (p - esat)
92 real(8),
intent(in) :: T, p
93 real(8),
intent(out):: drs
94 real(8) :: esat, desat
96 call descomp(t, desat)
97 if ( esat .le. p) drs =
d622 * p / (p - esat)**2 * desat
100 subroutine ff(dT, dp1, dp2, p1, p2, Dry_m, kini, x, val, lmass1,lmass2)
101 real(8),
intent(in) :: dT, dp1, dp2, p1, p2, Dry_m, kini, x
102 real(8),
intent(out):: val, lmass1, lmass2
103 real(8) :: t1n, t2n, yy, r1n, r2n, lh, rt1, rt2, &
108 call rsat(t1n, p1, r1n)
109 call rsat(t2n, p2, r2n)
110 yy = (dp1/(1.+r1n) + dp2/(1.+r2n))/dry_m -1.
111 rt1 = r1n + yy * (1.+r1n)
112 rt2 = r2n + yy * (1.+r2n)
114 dmass1 = dp1 / (1.+rt1)
115 dmass2 = dp2 / (1.+rt2)
116 lmass1 = dp1 / (1.+rt1) *(rt1 - r1n)
117 lmass2 = dp2 / (1.+rt2) *(rt2 - r2n)
120 kfin = cp_air * (dmass2*t2n+dmass1*t1n) + &
121 cp_water*(dmass2*rt2*t2n + dmass1*rt1*t1n)
122 call latent_heat(t2n, lh)
123 kfin = kfin + lh*dmass2*r2n
124 call latent_heat(t1n, lh)
125 kfin = kfin + lh*dmass1*r1n
133 q1, q2, T1, T2, p1, p2, T1new, T2new, lmass1, lmass2)
134 real(8),
intent(in) :: dT, dp1, dp2, q1, q2, T1, T2, &
136 real(8),
intent(out):: T1new, T2new, lmass1, lmass2
137 real(8) :: x, val, x1, val1, x2, val2, deriv
138 real(8) :: Dry_m, kini, lh
139 real(8) :: epss = 1.e-7
140 integer :: nmax = 100, n
143 dry_m = dp1*(1.-q1) + dp2*(1. - q2)
145 kini = cp_air * (dp2*(1-q2)*t2+dp1*(1-q1)*t1) + &
146 cp_water*(dp2*q2*t2 + dp1*q1*t1)
147 call latent_heat(t2, lh)
148 kini = kini + lh*dp2*q2
149 call latent_heat(t1, lh)
150 kini = kini + lh*dp1*q1
156 do while (abs(val) .gt. 1.e-3)
157 call ff(dt, dp1, dp2, p1, p2, dry_m, kini, x, val, lmass1,lmass2)
160 call ff(dt, dp1, dp2, p1, p2, dry_m, kini, x1, val1, lmass1,lmass2)
162 call ff(dt, dp1, dp2, p1, p2, dry_m, kini, x2, val2, lmass1,lmass2)
163 deriv = (val1 - val2) / 2./ epss
171 print *,
'does not converge', x, lmass1
179 call ff(dt, dp1, dp2, p1, p2, dry_m, kini, x, val, lmass1, lmass2)
182 call rsat(t1new, p1, val1)
183 if (val1 .le. 0) lmass1 = -1e5
190 real(8),
intent(in),
dimension(:) :: tin, qin
191 real(8),
intent(in),
dimension(:) :: phalf
192 real(8),
intent(out) :: k
197 kpum = (cp_air*(1 - qin(i)) + cp_vapor*qin(i))*tin(i)
198 k = k + kpum * (phalf(i+1) - phalf(i)) / grav
206 real(8),
intent(in) :: lnT, lnp
207 real(8),
intent(out):: slope
208 real(8) :: T, p, qs, D, rs, pa, es, A, B, C, ll
214 call latent_heat(t, ll)
221 pa = p / (rs /
d622 + 1.)
223 a = ll * rs / rdgas / t
224 b = rs * (cp_vapor / cp_air + &
225 (ll / rvgas / t-1.) * ll / cp_air / t)
226 c = 1. / (kappa * (1. + a) / (1. + b))
228 slope = (pa * c + es * d) / p
233 subroutine rk4_f(x0, y0, dx, nx, x, y)
235 real(8),
intent(in) :: x0, y0, dx
236 integer,
intent(in) :: nx
237 real(8),
intent(out),
dimension(nx+1) :: x, y
239 real(8) :: k1, k2, k3, k4
250 y(n+1) = y(n) + dx/6.*(k1+k4 + 2.*(k2+k3))
255 real(8),
intent(in) :: ts, pd
256 integer,
intent(in) :: nx
257 real(8),
intent(out):: psg
258 real(8),
intent(out),
dimension(nx+1) :: tt, lnpp, qs
260 real(8) :: psc, x1, x2, dx
261 real(8),
dimension(nx+1) :: lntlist, lnplist, lntt, pp
270 call rk4_f(x1, log(psg), dx, nx, lntlist, lnplist)
272 lntt(i) = lntlist(nx+2-i)
273 lnpp(i) = lnplist(nx+2-i)
278 call qsat(tt(i), pp(i), qs(i))
303 real(8),
intent(in) :: T, p
304 real(8),
intent(out):: slope
305 real(8) :: qs, lh, D, rs, pa, es, A, B, C
308 call latent_heat(t, lh)
315 pa = p / (rs /
d622 + 1.)
317 a = lh * rs / rdgas / t
318 b = rs * (cp_vapor / cp_air + &
319 (lh / rvgas / t-1.) * lh / cp_air / t)
320 c = 1. / (kappa * (1. + a) / (1. + b))
321 slope = (pa * c + es * d) / p
327 real(8),
intent(in) :: T1, P1, P2, PH
328 real(8),
intent(out):: T2
329 real(8) :: lr1, TH, lr2
332 th = t1 * (ph/p1)**(1./lr1)
336 t2 = t1 * (p2 / p1)**(1./lr2)
341 rain, Tref, qref, p_full, p_half, Ep, rain_profile)
343 real(8),
intent(in),
dimension(:) :: tin, qin, p_full_in
344 real(8),
intent(in),
dimension(:) :: p_half_in
345 real(8),
intent(out) :: rain, ep
346 real(8),
intent(out),
dimension(:) :: tref, qref, p_full, rain_profile
347 real(8),
intent(out),
dimension(:) :: p_half
350 real(8) :: t1, p1, p2, ph, t2
351 real(8) :: q1, q2, deltap1, deltap2, fq
352 real(8) :: cp1,cp2, cp3, cp4, deltat
353 real(8) :: dtref, t1new, t2new
354 real(8) :: dp, lmass, tcon, dpn, kappa2
355 real(8) :: lh, lmass1, lmass2
357 real(8),
allocatable,
dimension(:) :: pfulln, kappa1, zf
358 real(8),
allocatable,
dimension(:) :: phalfn, zh
360 integer :: iter1, k, i, n, j, nc
366 allocate(phalfn(n+1))
374 p_full = p_full_in *1.
375 p_half = p_half_in *1.
379 do k =
size(p_full), 2, -1
384 call convec(t1, p1, p2, ph, t2)
387 if (tref(k-1) .lt. t2)
then
388 deltap1 = p_half(k+1) - p_half(k)
389 deltap2 = p_half(k) - p_half(k-1)
393 qref(k), qref(k-1), tref(k), tref(k-1), &
394 p_full(k), p_full(k-1),t1new, t2new,lmass1,lmass2)
396 if (lmass1 .lt. 0)
then
397 call qsat(t1 ,p1, q1)
398 call qsat(t2 ,p2, q2)
399 fq = (qref(k) * deltap1 + qref(k-1)*deltap2) &
400 / (q1*deltap1 + q2 * deltap2)
403 cp2 = cp_air * deltap2 * (1 - qref(k-1)) + &
404 cp_vapor * deltap2 * qref(k-1)
405 cp1 = cp_air * deltap1 * (1 - qref(k)) + &
406 cp_vapor * deltap1 * qref(k)
407 cp4 = cp_air * deltap2 * (1 - q2) + &
408 cp_vapor * deltap2 * q2
409 cp3 = cp_air * deltap1 * (1 - q1) + &
410 cp_vapor * deltap1 * q1
411 deltat = -(cp3*t1 - cp1*tref(k) + cp4*t2 - cp2*tref(k-1)) &
413 tref(k) = t1 + deltat
414 tref(k-1) = t2 + deltat
419 if (t1new .gt. 400.) print *,
"too warm"
422 call qsat(tref(k), p_full(k), qref(k))
423 call qsat(tref(k-1), p_full(k-1), qref(k-1))
429 dp = p_half(i+1) - p_half(i)
430 kappa1 = (rdgas * (1 - qref) + rvgas * qref) &
431 / (cp_air*(1-qref) + cp_vapor* qref)
452 p_half(i+1:n+1) = p_half(i+1:n+1) - dp + dpn
453 pfulln(i) = p_full(i) - lmass* (p_full(i) - p_half(i)) / dp
455 tref(i) = tref(i) * (pfulln(i) / p_full(i))**kappa2
457 pfulln(i+1:n) = p_full(i+1:n) - dp + dpn
458 tref(i+1:n) = tref(i+1:n) * &
459 (pfulln(i+1:n) / p_full(i+1:n))**kappa1(i+1:n)
463 rain = rain + lmass / grav
465 rain_profile(i) = rain_profile(i) + lmass / grav
467 ep = ep + cp_water * tcon * lmass / grav &
468 + lmass * zf(i) / grav
474 dp = p_half(i+1) - p_half(i)
495 p_half(i+1:n+1) = p_half(i+1:n+1) - dp + dpn
496 pfulln(i) = p_full(i) - lmass* (p_full(i) - p_half(i)) / dp
498 tref(i) = tref(i) * (pfulln(i) / p_full(i))**kappa2
500 pfulln(i+1:n) = p_full(i+1:n) - dp + dpn
501 tref(i+1:n) = tref(i+1:n) * &
502 (pfulln(i+1:n) / p_full(i+1:n))**kappa1(i+1:n)
506 rain = rain + lmass / grav
508 rain_profile(i) = rain_profile(i) + lmass / grav
510 ep = ep + cp_water * tcon * lmass / grav &
511 + lmass * zf(i) / grav
529 real(8),
intent(inout),
dimension(:) :: t, q
530 real(8),
intent(in),
dimension(:) :: phalf
531 real(8),
intent(in),
dimension(:) :: pfull
532 integer,
intent(in) :: nc
538 call qsat(t(i), pfull(i), q2)
539 if (q2 .gt. q(i+1))
exit
subroutine convec(T1, P1, P2, PH, T2)
subroutine ff(dT, dp1, dp2, p1, p2, Dry_m, kini, x, val, lmass1, lmass2)
subroutine dqsatdt(T, p, dqs)
subroutine, public qsat(T, p, qs)
subroutine newtsolve_ff(dT, dp1, dp2, q1, q2, T1, T2, p1, p2, T1new, T2new, lmass1, lmass2)
subroutine, public moist_convection(tin, qin, p_full_in, p_half_in, rain, Tref, qref, p_full, p_half, Ep, rain_profile)
real(8), parameter, public d608
subroutine, public compute_k(tin, qin, phalf, k)
subroutine dlnpdlnt(T, p, slope)
subroutine dlnpdlnt_initial(lnT, lnp, slope)
subroutine cold_trap(t, q, phalf, pfull, nc)
subroutine rk4_f(x0, y0, dx, nx, x, y)
subroutine, public warm_start(ts, pd, nx, psg, tt, lnpp, qs)
subroutine rsat(T, p, rs)
real(8), parameter, public d622
subroutine drsatdt(T, p, drs)
subroutine compute_geopotential(t, q, p_half, p_full, z_full, z_half)
real(8), parameter, public d378