17 implicit none ;
private 19 public diapyc_energy_req_init, diapyc_energy_req_calc, diapyc_energy_req_test, diapyc_energy_req_end
28 logical :: initialized = .false.
30 real :: test_kh_scaling
32 logical :: use_test_kh_profile
38 integer :: id_ert=-1, id_erb=-1, id_erc=-1, id_erh=-1, id_kddt=-1, id_kd=-1
39 integer :: id_chct=-1, id_chcb=-1, id_chcc=-1, id_chch=-1
40 integer :: id_t0=-1, id_tf=-1, id_s0=-1, id_sf=-1, id_n2_0=-1, id_n2_f=-1
41 integer :: id_h=-1, id_zint=-1
49 subroutine diapyc_energy_req_test(h_3d, dt, tv, G, GV, US, CS, Kd_int)
53 real,
dimension(G%isd:G%ied,G%jsd:G%jed,GV%ke), &
58 real,
intent(in) :: dt
60 real,
dimension(G%isd:G%ied,G%jsd:G%jed,GV%ke+1), &
61 optional,
intent(in) :: kd_int
64 real,
dimension(GV%ke) :: &
67 real,
dimension(GV%ke+1) :: &
70 real :: ustar, absf, htot
73 integer :: i, j, k, is, ie, js, je, nz, itt
75 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
77 if (.not.
associated(cs))
call mom_error(fatal,
"diapyc_energy_req_test: "// &
78 "Module must be initialized before it is used.")
81 do j=js,je ;
do i=is,ie ;
if (g%mask2dT(i,j) > 0.5)
then 82 if (
present(kd_int) .and. .not.cs%use_test_Kh_profile)
then 83 do k=1,nz+1 ; kd(k) = cs%test_Kh_scaling*kd_int(i,j,k) ;
enddo 85 htot = 0.0 ; h_top(1) = 0.0
87 t0(k) = tv%T(i,j,k) ; s0(k) = tv%S(i,j,k)
88 h_col(k) = h_3d(i,j,k)
89 h_top(k+1) = h_top(k) + h_col(k)
94 h_bot(k) = h_bot(k+1) + h_col(k)
97 ustar = 0.01*us%m_to_Z*us%T_to_s
98 absf = 0.25*((abs(g%CoriolisBu(i-1,j-1)) + abs(g%CoriolisBu(i,j))) + &
99 (abs(g%CoriolisBu(i-1,j-1)) + abs(g%CoriolisBu(i,j))))
100 kd(1) = 0.0 ; kd(nz+1) = 0.0
102 tmp1 = h_top(k) * h_bot(k) * gv%H_to_Z
103 kd(k) = cs%test_Kh_scaling * &
104 ustar * 0.41 * (tmp1*ustar) / (absf*tmp1 + htot*ustar)
107 may_print = is_root_pe() .and. (i==ie) .and. (j==je)
108 call diapyc_energy_req_calc(h_col, t0, s0, kd, energy_kd, dt, tv, g, gv, us, &
109 may_print=may_print, cs=cs)
110 endif ;
enddo ;
enddo 112 end subroutine diapyc_energy_req_test
120 subroutine diapyc_energy_req_calc(h_in, T_in, S_in, Kd, energy_Kd, dt, tv, &
121 G, GV, US, may_print, CS)
125 real,
dimension(GV%ke),
intent(in) :: h_in
127 real,
dimension(GV%ke),
intent(in) :: t_in
128 real,
dimension(GV%ke),
intent(in) :: s_in
129 real,
dimension(GV%ke+1),
intent(in) :: kd
131 real,
intent(in) :: dt
132 real,
intent(out) :: energy_kd
137 logical,
optional,
intent(in) :: may_print
140 optional,
pointer :: cs
149 real,
dimension(GV%ke) :: &
197 real,
dimension(GV%ke+1) :: &
211 real,
dimension(GV%ke+1,4) :: &
242 real :: dte_t2, dt_km1_t2, dt_k_t2
243 real :: dse_t2, ds_km1_t2, ds_k_t2
247 real,
dimension(GV%ke) :: &
249 real,
dimension(GV%ke+1) :: &
250 dpea_dkd, dpea_dkd_est, dpea_dkd_err, dpea_dkd_trunc, dpea_dkd_err_norm, &
251 dpeb_dkd, dpeb_dkd_est, dpeb_dkd_err, dpeb_dkd_trunc, dpeb_dkd_err_norm
252 real :: pe_chg_tot1a, pe_chg_tot2a, t_chg_tota
253 real :: pe_chg_tot1b, pe_chg_tot2b, t_chg_totb
254 real :: pe_chg_tot1c, pe_chg_tot2c, t_chg_totc
255 real :: pe_chg_tot1d, pe_chg_tot2d, t_chg_totd
256 real,
dimension(GV%ke+1) :: dpechg_dkd
258 real,
dimension(6) :: dt_k_itt, ds_k_itt, dt_km1_itt, ds_km1_itt
260 integer :: k, nz, itt, max_itt, k_cent
261 logical :: surface_bl, bottom_bl, central, halves, debug
262 logical :: old_pe_calc
264 h_neglect = gv%H_subroundoff
268 surface_bl = .true. ; bottom_bl = .true. ; halves = .true.
269 central = .true. ; k_cent = nz/2
271 do_print = .false. ;
if (
present(may_print) .and.
present(cs)) do_print = may_print
273 dpea_dkd(:) = 0.0 ; dpea_dkd_est(:) = 0.0 ; dpea_dkd_err(:) = 0.0
274 dpea_dkd_err_norm(:) = 0.0 ; dpea_dkd_trunc(:) = 0.0
275 dpeb_dkd(:) = 0.0 ; dpeb_dkd_est(:) = 0.0 ; dpeb_dkd_err(:) = 0.0
276 dpeb_dkd_err_norm(:) = 0.0 ; dpeb_dkd_trunc(:) = 0.0
278 htot = 0.0 ; pres(1) = 0.0 ; pres_z(1) = 0.0 ; z_int(1) = 0.0
280 t0(k) = t_in(k) ; s0(k) = s_in(k)
282 htot = htot + h_tr(k)
283 pres(k+1) = pres(k) + (gv%g_Earth * gv%H_to_RZ) * h_tr(k)
284 pres_z(k+1) = pres(k+1)
285 p_lay(k) = 0.5*(pres(k) + pres(k+1))
286 z_int(k+1) = z_int(k) - h_tr(k)
289 h_tr(k) = max(h_tr(k), 1e-15*htot)
294 kddt_h(1) = 0.0 ; kddt_h(nz+1) = 0.0
296 kddt_h(k) = min((gv%Z_to_H**2*dt)*kd(k) / (0.5*(h_tr(k-1) + h_tr(k))), 1e3*htot)
304 dmass = gv%H_to_RZ * h_tr(k)
305 dpres = (gv%g_Earth * gv%H_to_RZ) * h_tr(k)
306 dt_to_dpe(k) = (dmass * (pres(k) + 0.5*dpres)) * dsv_dt(k)
307 ds_to_dpe(k) = (dmass * (pres(k) + 0.5*dpres)) * dsv_ds(k)
308 dt_to_dcolht(k) = dmass * dsv_dt(k) * cs%ColHt_scaling
309 ds_to_dcolht(k) = dmass * dsv_ds(k) * cs%ColHt_scaling
314 pe_chg_k(:,:) = 0.0 ; colht_cor_k(:,:) = 0.0
318 old_pe_calc = .false.
322 hp_a(k) = h_tr(k) ; hp_b(k) = h_tr(k)
323 dt_to_dpe_a(k) = dt_to_dpe(k) ; ds_to_dpe_a(k) = ds_to_dpe(k)
324 dt_to_dpe_b(k) = dt_to_dpe(k) ; ds_to_dpe_b(k) = ds_to_dpe(k)
325 dt_to_dcolht_a(k) = dt_to_dcolht(k) ; ds_to_dcolht_a(k) = ds_to_dcolht(k)
326 dt_to_dcolht_b(k) = dt_to_dcolht(k) ; ds_to_dcolht_b(k) = ds_to_dcolht(k)
334 if (old_pe_calc)
then 336 dt_km1_t2 = (t0(k)-t0(k-1))
337 ds_km1_t2 = (s0(k)-s0(k-1))
338 dte_t2 = 0.0 ; dse_t2 = 0.0
340 dte_t2 = kddt_h(k-1) * ((t0(k-2) - t0(k-1)) + dte(k-2))
341 dse_t2 = kddt_h(k-1) * ((s0(k-2) - s0(k-1)) + dse(k-2))
342 dt_km1_t2 = (t0(k)-t0(k-1)) - &
343 (kddt_h(k-1) / hp_a(k-1)) * ((t0(k-2) - t0(k-1)) + dte(k-2))
344 ds_km1_t2 = (s0(k)-s0(k-1)) - &
345 (kddt_h(k-1) / hp_a(k-1)) * ((s0(k-2) - s0(k-1)) + dse(k-2))
347 dte_term = dte_t2 + hp_a(k-1) * (t0(k-1)-t0(k))
348 dse_term = dse_t2 + hp_a(k-1) * (s0(k-1)-s0(k))
351 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
353 th_a(k-1) = h_tr(k-1) * t0(k-1) + kddt_h(k-1) * te(k-2)
354 sh_a(k-1) = h_tr(k-1) * s0(k-1) + kddt_h(k-1) * se(k-2)
356 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
362 kddt_h_guess = kddt_h(k)
363 if (old_pe_calc)
then 364 call find_pe_chg_orig(kddt_h_guess, h_tr(k), hp_a(k-1), &
365 dte_term, dse_term, dt_km1_t2, ds_km1_t2, &
366 dt_to_dpe(k), ds_to_dpe(k), dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), &
367 pres_z(k), dt_to_dcolht(k), ds_to_dcolht(k), &
368 dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
369 pe_chg_k(k,1), dpea_dkd(k))
371 call find_pe_chg(0.0, kddt_h_guess, hp_a(k-1), hp_b(k), &
372 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
373 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
374 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
375 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
376 pe_chg=pe_chg_k(k,1), dpec_dkd=dpea_dkd(k), &
377 colht_cor=colht_cor_k(k,1))
382 kddt_h_guess = (1.0+0.01*(itt-3))*kddt_h(k)
384 if (old_pe_calc)
then 385 call find_pe_chg_orig(kddt_h_guess, h_tr(k), hp_a(k-1), &
386 dte_term, dse_term, dt_km1_t2, ds_km1_t2, &
387 dt_to_dpe(k), ds_to_dpe(k), dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), &
388 pres_z(k), dt_to_dcolht(k), ds_to_dcolht(k), &
389 dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
392 call find_pe_chg(0.0, kddt_h_guess, hp_a(k-1), hp_b(k), &
393 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
394 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
395 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
396 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
401 dpea_dkd_est(k) = (4.0*(pe_chg(4)-pe_chg(2))/(0.02*kddt_h(k)) - &
402 (pe_chg(5)-pe_chg(1))/(0.04*kddt_h(k))) / 3.0
403 dpea_dkd_trunc(k) = (pe_chg(4)-pe_chg(2))/(0.02*kddt_h(k)) - &
404 (pe_chg(5)-pe_chg(1))/(0.04*kddt_h(k))
405 dpea_dkd_err(k) = (dpea_dkd_est(k) - dpea_dkd(k))
406 dpea_dkd_err_norm(k) = (dpea_dkd_est(k) - dpea_dkd(k)) / &
407 (abs(dpea_dkd_est(k)) + abs(dpea_dkd(k)) + 1e-100*us%RZ_to_kg_m2*us%L_T_to_m_s**2)
413 b1 = 1.0 / (hp_a(k-1) + kddt_h(k))
414 c1_a(k) = kddt_h(k) * b1
416 te(1) = b1*(h_tr(1)*t0(1))
417 se(1) = b1*(h_tr(1)*s0(1))
419 te(k-1) = b1 * (h_tr(k-1) * t0(k-1) + kddt_h(k-1) * te(k-2))
420 se(k-1) = b1 * (h_tr(k-1) * s0(k-1) + kddt_h(k-1) * se(k-2))
422 if (old_pe_calc)
then 423 dte(k-1) = b1 * ( kddt_h(k)*(t0(k)-t0(k-1)) + dte_t2 )
424 dse(k-1) = b1 * ( kddt_h(k)*(s0(k)-s0(k-1)) + dse_t2 )
427 hp_a(k) = h_tr(k) + (hp_a(k-1) * b1) * kddt_h(k)
428 dt_to_dpe_a(k) = dt_to_dpe(k) + c1_a(k)*dt_to_dpe_a(k-1)
429 ds_to_dpe_a(k) = ds_to_dpe(k) + c1_a(k)*ds_to_dpe_a(k-1)
430 dt_to_dcolht_a(k) = dt_to_dcolht(k) + c1_a(k)*dt_to_dcolht_a(k-1)
431 ds_to_dcolht_a(k) = ds_to_dcolht(k) + c1_a(k)*ds_to_dcolht_a(k-1)
435 b1 = 1.0 / (hp_a(nz))
436 tf(nz) = b1 * (h_tr(nz) * t0(nz) + kddt_h(nz) * te(nz-1))
437 sf(nz) = b1 * (h_tr(nz) * s0(nz) + kddt_h(nz) * se(nz-1))
438 if (old_pe_calc)
then 439 dte(nz) = b1 * kddt_h(nz) * ((t0(nz-1)-t0(nz)) + dte(nz-1))
440 dse(nz) = b1 * kddt_h(nz) * ((s0(nz-1)-s0(nz)) + dse(nz-1))
444 tf(k) = te(k) + c1_a(k+1)*tf(k+1)
445 sf(k) = se(k) + c1_a(k+1)*sf(k+1)
449 do k=1,nz ; ta(k) = tf(k) ; sa(k) = sf(k) ;
enddo 450 pe_chg_tot1a = 0.0 ; pe_chg_tot2a = 0.0 ; t_chg_tota = 0.0
452 pe_chg_tot1a = pe_chg_tot1a + (dt_to_dpe(k) * (tf(k) - t0(k)) + &
453 ds_to_dpe(k) * (sf(k) - s0(k)))
454 t_chg_tota = t_chg_tota + h_tr(k) * (tf(k) - t0(k))
457 pe_chg_tot2a = pe_chg_tot2a + (pe_chg_k(k,1) - colht_cor_k(k,1))
464 old_pe_calc = .false.
468 hp_a(k) = h_tr(k) ; hp_b(k) = h_tr(k)
469 dt_to_dpe_a(k) = dt_to_dpe(k) ; ds_to_dpe_a(k) = ds_to_dpe(k)
470 dt_to_dpe_b(k) = dt_to_dpe(k) ; ds_to_dpe_b(k) = ds_to_dpe(k)
471 dt_to_dcolht_a(k) = dt_to_dcolht(k) ; ds_to_dcolht_a(k) = ds_to_dcolht(k)
472 dt_to_dcolht_b(k) = dt_to_dcolht(k) ; ds_to_dcolht_b(k) = ds_to_dcolht(k)
480 if (old_pe_calc)
then 482 dt_k_t2 = (t0(k-1)-t0(k))
483 ds_k_t2 = (s0(k-1)-s0(k))
484 dte_t2 = 0.0 ; dse_t2 = 0.0
486 dte_t2 = kddt_h(k+1) * ((t0(k+1) - t0(k)) + dte(k+1))
487 dse_t2 = kddt_h(k+1) * ((s0(k+1) - s0(k)) + dse(k+1))
488 dt_k_t2 = (t0(k-1)-t0(k)) - &
489 (kddt_h(k+1)/ hp_b(k)) * ((t0(k+1) - t0(k)) + dte(k+1))
490 ds_k_t2 = (s0(k-1)-s0(k)) - &
491 (kddt_h(k+1)/ hp_b(k)) * ((s0(k+1) - s0(k)) + dse(k+1))
493 dte_term = dte_t2 + hp_b(k) * (t0(k)-t0(k-1))
494 dse_term = dse_t2 + hp_b(k) * (s0(k)-s0(k-1))
496 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
498 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
500 th_b(k) = h_tr(k) * t0(k) + kddt_h(k+1) * te(k+1)
501 sh_b(k) = h_tr(k) * s0(k) + kddt_h(k+1) * se(k+1)
506 kddt_h_guess = kddt_h(k)
508 if (old_pe_calc)
then 509 call find_pe_chg_orig(kddt_h_guess, h_tr(k-1), hp_b(k), &
510 dte_term, dse_term, dt_k_t2, ds_k_t2, &
511 dt_to_dpe(k-1), ds_to_dpe(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
512 pres_z(k), dt_to_dcolht(k-1), ds_to_dcolht(k-1), &
513 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
514 pe_chg=pe_chg_k(k,2), dpec_dkd=dpeb_dkd(k))
516 call find_pe_chg(0.0, kddt_h_guess, hp_a(k-1), hp_b(k), &
517 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
518 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
519 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
520 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
521 pe_chg=pe_chg_k(k,2), dpec_dkd=dpeb_dkd(k), &
522 colht_cor=colht_cor_k(k,2))
528 kddt_h_guess = (1.0+0.01*(itt-3))*kddt_h(k)
530 if (old_pe_calc)
then 531 call find_pe_chg_orig(kddt_h_guess, h_tr(k-1), hp_b(k), &
532 dte_term, dse_term, dt_k_t2, ds_k_t2, &
533 dt_to_dpe(k-1), ds_to_dpe(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
534 pres_z(k), dt_to_dcolht(k-1), ds_to_dcolht(k-1), &
535 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
538 call find_pe_chg(0.0, kddt_h_guess, hp_a(k-1), hp_b(k), &
539 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
540 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
541 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
542 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
547 dpeb_dkd_est(k) = (4.0*(pe_chg(4)-pe_chg(2))/(0.02*kddt_h(k)) - &
548 (pe_chg(5)-pe_chg(1))/(0.04*kddt_h(k))) / 3.0
549 dpeb_dkd_trunc(k) = (pe_chg(4)-pe_chg(2))/(0.02*kddt_h(k)) - &
550 (pe_chg(5)-pe_chg(1))/(0.04*kddt_h(k))
551 dpeb_dkd_err(k) = (dpeb_dkd_est(k) - dpeb_dkd(k))
552 dpeb_dkd_err_norm(k) = (dpeb_dkd_est(k) - dpeb_dkd(k)) / &
553 (abs(dpeb_dkd_est(k)) + abs(dpeb_dkd(k)) + 1e-100*us%RZ_to_kg_m2*us%L_T_to_m_s**2)
559 b1 = 1.0 / (hp_b(k) + kddt_h(k))
560 c1_b(k) = kddt_h(k) * b1
562 te(nz) = b1* (h_tr(nz)*t0(nz))
563 se(nz) = b1* (h_tr(nz)*s0(nz))
565 te(k) = b1 * (h_tr(k) * t0(k) + kddt_h(k+1) * te(k+1))
566 se(k) = b1 * (h_tr(k) * s0(k) + kddt_h(k+1) * se(k+1))
568 if (old_pe_calc)
then 569 dte(k) = b1 * ( kddt_h(k)*(t0(k-1)-t0(k)) + dte_t2 )
570 dse(k) = b1 * ( kddt_h(k)*(s0(k-1)-s0(k)) + dse_t2 )
573 hp_b(k-1) = h_tr(k-1) + (hp_b(k) * b1) * kddt_h(k)
574 dt_to_dpe_b(k-1) = dt_to_dpe(k-1) + c1_b(k)*dt_to_dpe_b(k)
575 ds_to_dpe_b(k-1) = ds_to_dpe(k-1) + c1_b(k)*ds_to_dpe_b(k)
576 dt_to_dcolht_b(k-1) = dt_to_dcolht(k-1) + c1_b(k)*dt_to_dcolht_b(k)
577 ds_to_dcolht_b(k-1) = ds_to_dcolht(k-1) + c1_b(k)*ds_to_dcolht_b(k)
582 tf(1) = b1 * (h_tr(1) * t0(1) + kddt_h(2) * te(2))
583 sf(1) = b1 * (h_tr(1) * s0(1) + kddt_h(2) * se(2))
584 if (old_pe_calc)
then 585 dte(1) = b1 * kddt_h(2) * ((t0(2)-t0(1)) + dte(2))
586 dse(1) = b1 * kddt_h(2) * ((s0(2)-s0(1)) + dse(2))
590 tf(k) = te(k) + c1_b(k)*tf(k-1)
591 sf(k) = se(k) + c1_b(k)*sf(k-1)
595 do k=1,nz ; tb(k) = tf(k) ; sb(k) = sf(k) ;
enddo 596 pe_chg_tot1b = 0.0 ; pe_chg_tot2b = 0.0 ; t_chg_totb = 0.0
598 pe_chg_tot1b = pe_chg_tot1b + (dt_to_dpe(k) * (tf(k) - t0(k)) + &
599 ds_to_dpe(k) * (sf(k) - s0(k)))
600 t_chg_totb = t_chg_totb + h_tr(k) * (tf(k) - t0(k))
603 pe_chg_tot2b = pe_chg_tot2b + (pe_chg_k(k,2) - colht_cor_k(k,2))
613 hp_a(k) = h_tr(k) ; hp_b(k) = h_tr(k)
614 dt_to_dpe_a(k) = dt_to_dpe(k) ; ds_to_dpe_a(k) = ds_to_dpe(k)
615 dt_to_dpe_b(k) = dt_to_dpe(k) ; ds_to_dpe_b(k) = ds_to_dpe(k)
616 dt_to_dcolht_a(k) = dt_to_dcolht(k) ; ds_to_dcolht_a(k) = ds_to_dcolht(k)
617 dt_to_dcolht_b(k) = dt_to_dcolht(k) ; ds_to_dcolht_b(k) = ds_to_dcolht(k)
626 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
628 th_a(k-1) = h_tr(k-1) * t0(k-1) + kddt_h(k-1) * te_a(k-2)
629 sh_a(k-1) = h_tr(k-1) * s0(k-1) + kddt_h(k-1) * se_a(k-2)
631 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
633 kddt_h_a(k) = 0.0 ;
if (k < k_cent) kddt_h_a(k) = kddt_h(k)
636 call find_pe_chg(kd0, dkd, hp_a(k-1), hp_b(k), &
637 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
638 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
639 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
640 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
641 pe_chg=pe_change, colht_cor=colht_cor)
642 pe_chg_k(k,3) = pe_change
643 colht_cor_k(k,3) = colht_cor
645 b1 = 1.0 / (hp_a(k-1) + kddt_h_a(k))
646 c1_a(k) = kddt_h_a(k) * b1
648 te_a(1) = b1*(h_tr(1)*t0(1))
649 se_a(1) = b1*(h_tr(1)*s0(1))
651 te_a(k-1) = b1 * (h_tr(k-1) * t0(k-1) + kddt_h_a(k-1) * te_a(k-2))
652 se_a(k-1) = b1 * (h_tr(k-1) * s0(k-1) + kddt_h_a(k-1) * se_a(k-2))
655 hp_a(k) = h_tr(k) + (hp_a(k-1) * b1) * kddt_h_a(k)
656 dt_to_dpe_a(k) = dt_to_dpe(k) + c1_a(k)*dt_to_dpe_a(k-1)
657 ds_to_dpe_a(k) = ds_to_dpe(k) + c1_a(k)*ds_to_dpe_a(k-1)
658 dt_to_dcolht_a(k) = dt_to_dcolht(k) + c1_a(k)*dt_to_dcolht_a(k-1)
659 ds_to_dcolht_a(k) = ds_to_dcolht(k) + c1_a(k)*ds_to_dcolht_a(k-1)
668 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
674 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
676 th_b(k) = h_tr(k) * t0(k) + kddt_h(k+1) * te_b(k+1)
677 sh_b(k) = h_tr(k) * s0(k) + kddt_h(k+1) * se_b(k+1)
680 kddt_h_b(k) = 0.0 ;
if (k > k_cent) kddt_h_b(k) = kddt_h(k)
683 call find_pe_chg(kd0, dkd, hp_a(k-1), hp_b(k), &
684 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
685 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
686 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
687 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
688 pe_chg=pe_change, colht_cor=colht_cor)
689 pe_chg_k(k,3) = pe_chg_k(k,3) + pe_change
690 colht_cor_k(k,3) = colht_cor_k(k,3) + colht_cor
692 b1 = 1.0 / (hp_b(k) + kddt_h_b(k))
693 c1_b(k) = kddt_h_b(k) * b1
695 te_b(k) = b1 * (h_tr(k)*t0(k))
696 se_b(k) = b1 * (h_tr(k)*s0(k))
698 te_b(k) = b1 * (h_tr(k) * t0(k) + kddt_h_b(k+1) * te_b(k+1))
699 se_b(k) = b1 * (h_tr(k) * s0(k) + kddt_h_b(k+1) * se_b(k+1))
702 hp_b(k-1) = h_tr(k-1) + (hp_b(k) * b1) * kddt_h_b(k)
703 dt_to_dpe_b(k-1) = dt_to_dpe(k-1) + c1_b(k)*dt_to_dpe_b(k)
704 ds_to_dpe_b(k-1) = ds_to_dpe(k-1) + c1_b(k)*ds_to_dpe_b(k)
705 dt_to_dcolht_b(k-1) = dt_to_dcolht(k-1) + c1_b(k)*dt_to_dcolht_b(k)
706 ds_to_dcolht_b(k-1) = ds_to_dcolht(k-1) + c1_b(k)*ds_to_dcolht_b(k)
716 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
718 th_a(k-1) = h_tr(k-1) * t0(k-1) + kddt_h(k-1) * te_a(k-2)
719 sh_a(k-1) = h_tr(k-1) * s0(k-1) + kddt_h(k-1) * se_a(k-2)
722 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
724 th_b(k) = h_tr(k) * t0(k) + kddt_h(k+1) * te_b(k+1)
725 sh_b(k) = h_tr(k) * s0(k) + kddt_h(k+1) * se_b(k+1)
730 call find_pe_chg(kd0, dkd, hp_a(k-1), hp_b(k), &
731 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
732 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
733 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
734 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
735 pe_chg=pe_change, colht_cor=colht_cor)
736 pe_chg_k(k,3) = pe_chg_k(k,3) + pe_change
737 colht_cor_k(k,3) = colht_cor_k(k,3) + colht_cor
752 b1 = 1.0 / (hp_a(k-1)*hp_b(k) + kddt_h(k)*(hp_a(k-1) + hp_b(k)))
753 tf(k-1) = ((hp_b(k) + kddt_h(k)) * th_a(k-1) + kddt_h(k) * th_b(k) ) * b1
754 sf(k-1) = ((hp_b(k) + kddt_h(k)) * sh_a(k-1) + kddt_h(k) * sh_b(k) ) * b1
755 tf(k) = (kddt_h(k) * th_a(k-1) + (hp_a(k-1) + kddt_h(k)) * th_b(k) ) * b1
756 sf(k) = (kddt_h(k) * sh_a(k-1) + (hp_a(k-1) + kddt_h(k)) * sh_b(k) ) * b1
758 c1_a(k) = kddt_h(k) / (hp_a(k-1) + kddt_h(k))
759 c1_b(k) = kddt_h(k) / (hp_b(k) + kddt_h(k))
764 tf(k) = te_a(k) + c1_a(k+1)*tf(k+1)
765 sf(k) = se_a(k) + c1_a(k+1)*sf(k+1)
768 tf(k) = te_b(k) + c1_b(k)*tf(k-1)
769 sf(k) = se_b(k) + c1_b(k)*sf(k-1)
773 pe_chg_tot1c = 0.0 ; pe_chg_tot2c = 0.0 ; t_chg_totc = 0.0
775 pe_chg_tot1c = pe_chg_tot1c + (dt_to_dpe(k) * (tf(k) - t0(k)) + &
776 ds_to_dpe(k) * (sf(k) - s0(k)))
777 t_chg_totc = t_chg_totc + h_tr(k) * (tf(k) - t0(k))
780 pe_chg_tot2c = pe_chg_tot2c + (pe_chg_k(k,3) - colht_cor_k(k,3))
790 hp_a(k) = h_tr(k) ; hp_b(k) = h_tr(k)
791 dt_to_dpe_a(k) = dt_to_dpe(k) ; ds_to_dpe_a(k) = ds_to_dpe(k)
792 dt_to_dpe_b(k) = dt_to_dpe(k) ; ds_to_dpe_b(k) = ds_to_dpe(k)
793 dt_to_dcolht_a(k) = dt_to_dcolht(k) ; ds_to_dcolht_a(k) = ds_to_dcolht(k)
794 dt_to_dcolht_b(k) = dt_to_dcolht(k) ; ds_to_dcolht_b(k) = ds_to_dcolht(k)
806 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
808 th_a(k-1) = h_tr(k-1) * t0(k-1) + kd_so_far(k-1) * te(k-2)
809 sh_a(k-1) = h_tr(k-1) * s0(k-1) + kd_so_far(k-1) * se(k-2)
811 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
813 dkd = 0.5 * kddt_h(k) - kd_so_far(k)
815 call find_pe_chg(kd0, dkd, hp_a(k-1), hp_b(k), &
816 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
817 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
818 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
819 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
820 pe_chg=pe_change, colht_cor=colht_cor)
822 pe_chg_k(k,4) = pe_change
823 colht_cor_k(k,4) = colht_cor
825 kd_so_far(k) = kd_so_far(k) + dkd
827 b1 = 1.0 / (hp_a(k-1) + kd_so_far(k))
828 c1_a(k) = kd_so_far(k) * b1
830 te(1) = b1*(h_tr(1)*t0(1))
831 se(1) = b1*(h_tr(1)*s0(1))
833 te(k-1) = b1 * (h_tr(k-1) * t0(k-1) + kd_so_far(k-1) * te(k-2))
834 se(k-1) = b1 * (h_tr(k-1) * s0(k-1) + kd_so_far(k-1) * se(k-2))
837 hp_a(k) = h_tr(k) + (hp_a(k-1) * b1) * kd_so_far(k)
838 dt_to_dpe_a(k) = dt_to_dpe(k) + c1_a(k)*dt_to_dpe_a(k-1)
839 ds_to_dpe_a(k) = ds_to_dpe(k) + c1_a(k)*ds_to_dpe_a(k-1)
840 dt_to_dcolht_a(k) = dt_to_dcolht(k) + c1_a(k)*dt_to_dcolht_a(k-1)
841 ds_to_dcolht_a(k) = ds_to_dcolht(k) + c1_a(k)*ds_to_dcolht_a(k-1)
849 th_a(k-1) = h_tr(k-1) * t0(k-1) ; sh_a(k-1) = h_tr(k-1) * s0(k-1)
851 th_a(k-1) = h_tr(k-1) * t0(k-1) + kd_so_far(k-1) * te(k-2)
852 sh_a(k-1) = h_tr(k-1) * s0(k-1) + kd_so_far(k-1) * se(k-2)
855 th_b(k) = h_tr(k) * t0(k) ; sh_b(k) = h_tr(k) * s0(k)
857 th_b(k) = h_tr(k) * t0(k) + kd_so_far(k+1) * te(k+1)
858 sh_b(k) = h_tr(k) * s0(k) + kd_so_far(k+1) * se(k+1)
861 dkd = kddt_h(k) - kd_so_far(k)
863 call find_pe_chg(kd0, dkd, hp_a(k-1), hp_b(k), &
864 th_a(k-1), sh_a(k-1), th_b(k), sh_b(k), &
865 dt_to_dpe_a(k-1), ds_to_dpe_a(k-1), dt_to_dpe_b(k), ds_to_dpe_b(k), &
866 pres_z(k), dt_to_dcolht_a(k-1), ds_to_dcolht_a(k-1), &
867 dt_to_dcolht_b(k), ds_to_dcolht_b(k), &
868 pe_chg=pe_change, colht_cor=colht_cor)
870 pe_chg_k(k,4) = pe_chg_k(k,4) + pe_change
871 colht_cor_k(k,4) = colht_cor_k(k,4) + colht_cor
874 kd_so_far(k) = kd_so_far(k) + dkd
876 b1 = 1.0 / (hp_b(k) + kd_so_far(k))
877 c1_b(k) = kd_so_far(k) * b1
879 te(k) = b1 * (h_tr(k)*t0(k))
880 se(k) = b1 * (h_tr(k)*s0(k))
882 te(k) = b1 * (h_tr(k) * t0(k) + kd_so_far(k+1) * te(k+1))
883 se(k) = b1 * (h_tr(k) * s0(k) + kd_so_far(k+1) * se(k+1))
886 hp_b(k-1) = h_tr(k-1) + (hp_b(k) * b1) * kd_so_far(k)
887 dt_to_dpe_b(k-1) = dt_to_dpe(k-1) + c1_b(k)*dt_to_dpe_b(k)
888 ds_to_dpe_b(k-1) = ds_to_dpe(k-1) + c1_b(k)*ds_to_dpe_b(k)
889 dt_to_dcolht_b(k-1) = dt_to_dcolht(k-1) + c1_b(k)*dt_to_dcolht_b(k)
890 ds_to_dcolht_b(k-1) = ds_to_dcolht(k-1) + c1_b(k)*ds_to_dcolht_b(k)
897 tf(1) = b1 * (h_tr(1) * t0(1) + kddt_h(2) * te(2))
898 sf(1) = b1 * (h_tr(1) * s0(1) + kddt_h(2) * se(2))
900 tf(k) = te(k) + c1_b(k)*tf(k-1)
901 sf(k) = se(k) + c1_b(k)*sf(k-1)
905 pe_chg_tot1d = 0.0 ; pe_chg_tot2d = 0.0 ; t_chg_totd = 0.0
907 pe_chg_tot1d = pe_chg_tot1d + (dt_to_dpe(k) * (tf(k) - t0(k)) + &
908 ds_to_dpe(k) * (sf(k) - s0(k)))
909 t_chg_totd = t_chg_totd + h_tr(k) * (tf(k) - t0(k))
912 pe_chg_tot2d = pe_chg_tot2d + (pe_chg_k(k,4) - colht_cor_k(k,4))
918 energy_kd = 0.0 ;
do k=2,nz ; energy_kd = energy_kd + pe_chg_k(k,1) ;
enddo 919 energy_kd = energy_kd / dt
922 if (cs%id_ERt>0)
call post_data(cs%id_ERt, pe_chg_k(:,1), cs%diag)
923 if (cs%id_ERb>0)
call post_data(cs%id_ERb, pe_chg_k(:,2), cs%diag)
924 if (cs%id_ERc>0)
call post_data(cs%id_ERc, pe_chg_k(:,3), cs%diag)
925 if (cs%id_ERh>0)
call post_data(cs%id_ERh, pe_chg_k(:,4), cs%diag)
926 if (cs%id_Kddt>0)
call post_data(cs%id_Kddt, kddt_h, cs%diag)
927 if (cs%id_Kd>0)
call post_data(cs%id_Kd, kd, cs%diag)
928 if (cs%id_h>0)
call post_data(cs%id_h, h_tr, cs%diag)
929 if (cs%id_zInt>0)
call post_data(cs%id_zInt, z_int, cs%diag)
930 if (cs%id_CHCt>0)
call post_data(cs%id_CHCt, colht_cor_k(:,1), cs%diag)
931 if (cs%id_CHCb>0)
call post_data(cs%id_CHCb, colht_cor_k(:,2), cs%diag)
932 if (cs%id_CHCc>0)
call post_data(cs%id_CHCc, colht_cor_k(:,3), cs%diag)
933 if (cs%id_CHCh>0)
call post_data(cs%id_CHCh, colht_cor_k(:,4), cs%diag)
934 if (cs%id_T0>0)
call post_data(cs%id_T0, t0, cs%diag)
935 if (cs%id_Tf>0)
call post_data(cs%id_Tf, tf, cs%diag)
936 if (cs%id_S0>0)
call post_data(cs%id_S0, s0, cs%diag)
937 if (cs%id_Sf>0)
call post_data(cs%id_Sf, sf, cs%diag)
938 if (cs%id_N2_0>0)
then 939 n2(1) = 0.0 ; n2(nz+1) = 0.0
942 pres(k), rho_here, tv%eqn_of_state)
943 n2(k) = ((us%L_to_Z**2*gv%g_Earth) * rho_here / (0.5*gv%H_to_Z*(h_tr(k-1) + h_tr(k)))) * &
944 ( 0.5*(dsv_dt(k-1) + dsv_dt(k)) * (t0(k-1) - t0(k)) + &
945 0.5*(dsv_ds(k-1) + dsv_ds(k)) * (s0(k-1) - s0(k)) )
949 if (cs%id_N2_f>0)
then 950 n2(1) = 0.0 ; n2(nz+1) = 0.0
953 pres(k), rho_here, tv%eqn_of_state)
954 n2(k) = ((us%L_to_Z**2*gv%g_Earth) * rho_here / (0.5*gv%H_to_Z*(h_tr(k-1) + h_tr(k)))) * &
955 ( 0.5*(dsv_dt(k-1) + dsv_dt(k)) * (tf(k-1) - tf(k)) + &
956 0.5*(dsv_ds(k-1) + dsv_ds(k)) * (sf(k-1) - sf(k)) )
962 end subroutine diapyc_energy_req_calc
966 subroutine find_pe_chg(Kddt_h0, dKddt_h, hp_a, hp_b, Th_a, Sh_a, Th_b, Sh_b, &
967 dT_to_dPE_a, dS_to_dPE_a, dT_to_dPE_b, dS_to_dPE_b, &
968 pres_Z, dT_to_dColHt_a, dS_to_dColHt_a, dT_to_dColHt_b, dS_to_dColHt_b, &
969 PE_chg, dPEc_dKd, dPE_max, dPEc_dKd_0, ColHt_cor)
970 real,
intent(in) :: Kddt_h0
973 real,
intent(in) :: dKddt_h
976 real,
intent(in) :: hp_a
980 real,
intent(in) :: hp_b
984 real,
intent(in) :: Th_a
987 real,
intent(in) :: Sh_a
990 real,
intent(in) :: Th_b
993 real,
intent(in) :: Sh_b
996 real,
intent(in) :: dT_to_dPE_a
1000 real,
intent(in) :: dS_to_dPE_a
1004 real,
intent(in) :: dT_to_dPE_b
1008 real,
intent(in) :: dS_to_dPE_b
1012 real,
intent(in) :: pres_Z
1015 real,
intent(in) :: dT_to_dColHt_a
1019 real,
intent(in) :: dS_to_dColHt_a
1023 real,
intent(in) :: dT_to_dColHt_b
1027 real,
intent(in) :: dS_to_dColHt_b
1032 real,
optional,
intent(out) :: PE_chg
1034 real,
optional,
intent(out) :: dPEc_dKd
1036 real,
optional,
intent(out) :: dPE_max
1039 real,
optional,
intent(out) :: dPEc_dKd_0
1041 real,
optional,
intent(out) :: ColHt_cor
1064 bdt1 = hp_a * hp_b + kddt_h0 * hps
1065 dt_c = hp_a * th_b - hp_b * th_a
1066 ds_c = hp_a * sh_b - hp_b * sh_a
1067 pec_core = hp_b * (dt_to_dpe_a * dt_c + ds_to_dpe_a * ds_c) - &
1068 hp_a * (dt_to_dpe_b * dt_c + ds_to_dpe_b * ds_c)
1069 colht_core = hp_b * (dt_to_dcolht_a * dt_c + ds_to_dcolht_a * ds_c) - &
1070 hp_a * (dt_to_dcolht_b * dt_c + ds_to_dcolht_b * ds_c)
1072 if (
present(pe_chg))
then 1075 y1 = dkddt_h / (bdt1 * (bdt1 + dkddt_h * hps))
1076 pe_chg = pec_core * y1
1077 colht_chg = colht_core * y1
1078 if (colht_chg < 0.0) pe_chg = pe_chg - pres_z * colht_chg
1079 if (
present(colht_cor)) colht_cor = -pres_z * min(colht_chg, 0.0)
1080 elseif (
present(colht_cor))
then 1081 y1 = dkddt_h / (bdt1 * (bdt1 + dkddt_h * hps))
1082 colht_cor = -pres_z * min(colht_core * y1, 0.0)
1085 if (
present(dpec_dkd))
then 1087 y1 = 1.0 / (bdt1 + dkddt_h * hps)**2
1088 dpec_dkd = pec_core * y1
1089 colht_chg = colht_core * y1
1090 if (colht_chg < 0.0) dpec_dkd = dpec_dkd - pres_z * colht_chg
1093 if (
present(dpe_max))
then 1095 y1 = 1.0 / (bdt1 * hps)
1096 dpe_max = pec_core * y1
1097 colht_chg = colht_core * y1
1098 if (colht_chg < 0.0) dpe_max = dpe_max - pres_z * colht_chg
1101 if (
present(dpec_dkd_0))
then 1104 dpec_dkd_0 = pec_core * y1
1105 colht_chg = colht_core * y1
1106 if (colht_chg < 0.0) dpec_dkd_0 = dpec_dkd_0 - pres_z * colht_chg
1109 end subroutine find_pe_chg
1115 subroutine find_pe_chg_orig(Kddt_h, h_k, b_den_1, dTe_term, dSe_term, &
1116 dT_km1_t2, dS_km1_t2, dT_to_dPE_k, dS_to_dPE_k, &
1117 dT_to_dPEa, dS_to_dPEa, pres_Z, dT_to_dColHt_k, &
1118 dS_to_dColHt_k, dT_to_dColHta, dS_to_dColHta, &
1119 PE_chg, dPEc_dKd, dPE_max, dPEc_dKd_0)
1120 real,
intent(in) :: Kddt_h
1123 real,
intent(in) :: h_k
1124 real,
intent(in) :: b_den_1
1128 real,
intent(in) :: dTe_term
1130 real,
intent(in) :: dSe_term
1132 real,
intent(in) :: dT_km1_t2
1134 real,
intent(in) :: dS_km1_t2
1136 real,
intent(in) :: pres_Z
1139 real,
intent(in) :: dT_to_dPE_k
1143 real,
intent(in) :: dS_to_dPE_k
1147 real,
intent(in) :: dT_to_dPEa
1151 real,
intent(in) :: dS_to_dPEa
1155 real,
intent(in) :: dT_to_dColHt_k
1159 real,
intent(in) :: dS_to_dColHt_k
1163 real,
intent(in) :: dT_to_dColHta
1167 real,
intent(in) :: dS_to_dColHta
1172 real,
optional,
intent(out) :: PE_chg
1174 real,
optional,
intent(out) :: dPEc_dKd
1176 real,
optional,
intent(out) :: dPE_max
1179 real,
optional,
intent(out) :: dPEc_dKd_0
1196 real :: dT_k, dT_km1
1197 real :: dS_k, dS_km1
1200 real :: ddT_k_dKd, ddT_km1_dKd
1201 real :: ddS_k_dKd, ddS_km1_dKd
1203 b1 = 1.0 / (b_den_1 + kddt_h)
1211 i_kr_denom = 1.0 / (h_k*b_den_1 + (b_den_1 + h_k)*kddt_h)
1213 dt_k = (kddt_h*i_kr_denom) * dte_term
1214 ds_k = (kddt_h*i_kr_denom) * dse_term
1216 if (
present(pe_chg))
then 1219 dt_km1 = b1kd * ( dt_k + dt_km1_t2 )
1220 ds_km1 = b1kd * ( ds_k + ds_km1_t2 )
1222 pe_chg = (dt_to_dpe_k * dt_k + dt_to_dpea * dt_km1) + &
1223 (ds_to_dpe_k * ds_k + ds_to_dpea * ds_km1)
1224 colht_chg = (dt_to_dcolht_k * dt_k + dt_to_dcolhta * dt_km1) + &
1225 (ds_to_dcolht_k * ds_k + ds_to_dcolhta * ds_km1)
1226 if (colht_chg < 0.0) pe_chg = pe_chg - pres_z * colht_chg
1229 if (
present(dpec_dkd))
then 1231 dkr_dkd = (h_k*b_den_1) * i_kr_denom**2
1233 ddt_k_dkd = dkr_dkd * dte_term
1234 dds_k_dkd = dkr_dkd * dse_term
1235 ddt_km1_dkd = (b1**2 * b_den_1) * ( dt_k + dt_km1_t2 ) + b1kd * ddt_k_dkd
1236 dds_km1_dkd = (b1**2 * b_den_1) * ( ds_k + ds_km1_t2 ) + b1kd * dds_k_dkd
1239 dpec_dkd = (dt_to_dpe_k * ddt_k_dkd + dt_to_dpea * ddt_km1_dkd) + &
1240 (ds_to_dpe_k * dds_k_dkd + ds_to_dpea * dds_km1_dkd)
1241 dcolht_dkd = (dt_to_dcolht_k * ddt_k_dkd + dt_to_dcolhta * ddt_km1_dkd) + &
1242 (ds_to_dcolht_k * dds_k_dkd + ds_to_dcolhta * dds_km1_dkd)
1243 if (dcolht_dkd < 0.0) dpec_dkd = dpec_dkd - pres_z * dcolht_dkd
1246 if (
present(dpe_max))
then 1248 dpe_max = (dt_to_dpea * dt_km1_t2 + ds_to_dpea * ds_km1_t2) + &
1249 ((dt_to_dpe_k + dt_to_dpea) * dte_term + &
1250 (ds_to_dpe_k + ds_to_dpea) * dse_term) / (b_den_1 + h_k)
1251 dcolht_max = (dt_to_dcolhta * dt_km1_t2 + ds_to_dcolhta * ds_km1_t2) + &
1252 ((dt_to_dcolht_k + dt_to_dcolhta) * dte_term + &
1253 (ds_to_dcolht_k + ds_to_dcolhta) * dse_term) / (b_den_1 + h_k)
1254 if (dcolht_max < 0.0) dpe_max = dpe_max - pres_z*dcolht_max
1257 if (
present(dpec_dkd_0))
then 1259 dpec_dkd_0 = (dt_to_dpea * dt_km1_t2 + ds_to_dpea * ds_km1_t2) / (b_den_1) + &
1260 (dt_to_dpe_k * dte_term + ds_to_dpe_k * dse_term) / (h_k*b_den_1)
1261 dcolht_dkd = (dt_to_dcolhta * dt_km1_t2 + ds_to_dcolhta * ds_km1_t2) / (b_den_1) + &
1262 (dt_to_dcolht_k * dte_term + ds_to_dcolht_k * dse_term) / (h_k*b_den_1)
1263 if (dcolht_dkd < 0.0) dpec_dkd_0 = dpec_dkd_0 - pres_z*dcolht_dkd
1266 end subroutine find_pe_chg_orig
1269 subroutine diapyc_energy_req_init(Time, G, GV, US, param_file, diag, CS)
1270 type(time_type),
intent(in) :: time
1275 type(
diag_ctrl),
target,
intent(inout) :: diag
1278 integer,
save :: init_calls = 0
1280 #include "version_variable.h" 1281 character(len=40) :: mdl =
"MOM_diapyc_energy_req" 1282 character(len=256) :: mesg
1284 if (.not.
associated(cs))
then ;
allocate(cs)
1285 else ;
return ;
endif 1287 cs%initialized = .true.
1292 call get_param(param_file, mdl,
"ENERGY_REQ_KH_SCALING", cs%test_Kh_scaling, &
1293 "A scaling factor for the diapycnal diffusivity used in "//&
1294 "testing the energy requirements.", default=1.0, units=
"nondim")
1295 call get_param(param_file, mdl,
"ENERGY_REQ_COL_HT_SCALING", cs%ColHt_scaling, &
1296 "A scaling factor for the column height change correction "//&
1297 "used in testing the energy requirements.", default=1.0, units=
"nondim")
1298 call get_param(param_file, mdl,
"ENERGY_REQ_USE_TEST_PROFILE", &
1299 cs%use_test_Kh_profile, &
1300 "If true, use the internal test diffusivity profile in "//&
1301 "place of any that might be passed in as an argument.", default=.false.)
1303 cs%id_ERt = register_diag_field(
'ocean_model',
'EnReqTest_ERt', diag%axesZi, time, &
1304 "Diffusivity Energy Requirements, top-down", &
1305 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1306 cs%id_ERb = register_diag_field(
'ocean_model',
'EnReqTest_ERb', diag%axesZi, time, &
1307 "Diffusivity Energy Requirements, bottom-up", &
1308 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1309 cs%id_ERc = register_diag_field(
'ocean_model',
'EnReqTest_ERc', diag%axesZi, time, &
1310 "Diffusivity Energy Requirements, center-last", &
1311 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1312 cs%id_ERh = register_diag_field(
'ocean_model',
'EnReqTest_ERh', diag%axesZi, time, &
1313 "Diffusivity Energy Requirements, halves", &
1314 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1315 cs%id_Kddt = register_diag_field(
'ocean_model',
'EnReqTest_Kddt', diag%axesZi, time, &
1316 "Implicit diffusive coupling coefficient",
"m", conversion=gv%H_to_m)
1317 cs%id_Kd = register_diag_field(
'ocean_model',
'EnReqTest_Kd', diag%axesZi, time, &
1318 "Diffusivity in test",
"m2 s-1", conversion=us%Z_to_m**2)
1319 cs%id_h = register_diag_field(
'ocean_model',
'EnReqTest_h_lay', diag%axesZL, time, &
1320 "Test column layer thicknesses",
"m", conversion=gv%H_to_m)
1321 cs%id_zInt = register_diag_field(
'ocean_model',
'EnReqTest_z_int', diag%axesZi, time, &
1322 "Test column layer interface heights",
"m", conversion=gv%H_to_m)
1323 cs%id_CHCt = register_diag_field(
'ocean_model',
'EnReqTest_CHCt', diag%axesZi, time, &
1324 "Column Height Correction to Energy Requirements, top-down", &
1325 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1326 cs%id_CHCb = register_diag_field(
'ocean_model',
'EnReqTest_CHCb', diag%axesZi, time, &
1327 "Column Height Correction to Energy Requirements, bottom-up", &
1328 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1329 cs%id_CHCc = register_diag_field(
'ocean_model',
'EnReqTest_CHCc', diag%axesZi, time, &
1330 "Column Height Correction to Energy Requirements, center-last", &
1331 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1332 cs%id_CHCh = register_diag_field(
'ocean_model',
'EnReqTest_CHCh', diag%axesZi, time, &
1333 "Column Height Correction to Energy Requirements, halves", &
1334 "J m-2", conversion=us%RZ_to_kg_m2*us%L_T_to_m_s**2)
1335 cs%id_T0 = register_diag_field(
'ocean_model',
'EnReqTest_T0', diag%axesZL, time, &
1336 "Temperature before mixing",
"deg C")
1337 cs%id_Tf = register_diag_field(
'ocean_model',
'EnReqTest_Tf', diag%axesZL, time, &
1338 "Temperature after mixing",
"deg C")
1339 cs%id_S0 = register_diag_field(
'ocean_model',
'EnReqTest_S0', diag%axesZL, time, &
1340 "Salinity before mixing",
"g kg-1")
1341 cs%id_Sf = register_diag_field(
'ocean_model',
'EnReqTest_Sf', diag%axesZL, time, &
1342 "Salinity after mixing",
"g kg-1")
1343 cs%id_N2_0 = register_diag_field(
'ocean_model',
'EnReqTest_N2_0', diag%axesZi, time, &
1344 "Squared buoyancy frequency before mixing",
"second-2", conversion=us%s_to_T**2)
1345 cs%id_N2_f = register_diag_field(
'ocean_model',
'EnReqTest_N2_f', diag%axesZi, time, &
1346 "Squared buoyancy frequency after mixing",
"second-2", conversion=us%s_to_T**2)
1348 end subroutine diapyc_energy_req_init
1351 subroutine diapyc_energy_req_end(CS)
1354 if (
associated(cs))
deallocate(cs)
1355 end subroutine diapyc_energy_req_end
Calculate the derivatives of specific volume with temperature and salinity from T,...
Ocean grid type. See mom_grid for details.
Calculates density of sea water from T, S and P.
A structure that can be parsed to read and document run-time parameters.
Provides the ocean grid type.
The MOM6 facility to parse input files for runtime parameters.
Make a diagnostic available for averaging or output.
Describes various unit conversion factors.
Provides a transparent unit rescaling type to facilitate dimensional consistency testing.
This control structure holds parameters for the MOM_diapyc_energy_req module.
Calculates the energy requirements of mixing.
Routines for error handling and I/O management.
Provides subroutines for quantities specific to the equation of state.
An overloaded interface to log version information about modules.
Describes the vertical ocean grid, including unit conversion factors.
Pointers to an assortment of thermodynamic fields that may be available, including potential temperat...
Provides a transparent vertical ocean grid type and supporting routines.
Provides transparent structures with groups of MOM6 variables and supporting routines.
An overloaded interface to read and log the values of various types of parameters.