Calculates the acceleration due to the horizontal viscosity.
A combination of biharmonic and Laplacian forms can be used. The coefficient may either be a constant or a shear-dependent form. The biharmonic is determined by twice taking the divergence of an appropriately defined stress tensor. The Laplacian is determined by doing so once.
To work, the following fields must be set outside of the usual is:ie range before this subroutine is called: u[is-2:ie+2,js-2:je+2] v[is-2:ie+2,js-2:je+2] h[is-1:ie+1,js-1:je+1]
217 type(ocean_grid_type),
intent(in) :: g
218 type(verticalgrid_type),
intent(in) :: gv
219 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
221 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
223 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)), &
225 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
228 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
231 type(meke_type),
pointer :: meke
233 type(varmix_cs),
pointer :: varmix
235 type(unit_scale_type),
intent(in) :: us
236 type(hor_visc_cs),
pointer :: cs
238 type(ocean_obc_type),
optional,
pointer :: obc
239 type(barotropic_cs),
optional,
pointer :: bt
241 type(thickness_diffuse_cs),
optional,
pointer :: td
243 type(accel_diag_ptrs),
optional,
pointer :: adp
246 real,
dimension(SZIB_(G),SZJ_(G)) :: &
252 real,
dimension(SZI_(G),SZJB_(G)) :: &
258 real,
dimension(SZI_(G),SZJ_(G)) :: &
270 grad_vort_mag_h_2d, &
279 real,
allocatable,
dimension(:,:) :: hf_diffu_2d
280 real,
allocatable,
dimension(:,:) :: hf_diffv_2d
282 real,
dimension(SZIB_(G),SZJB_(G)) :: &
284 ddel2vdx, ddel2udy, &
295 grad_vort_mag_q_2d, &
304 real,
dimension(SZIB_(G),SZJB_(G),SZK_(G)) :: &
309 gme_coeff_q, & !< GME coeff. at q-points [L2 T-1 ~> m2 s-1]
312 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)+1) :: &
314 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)+1) :: &
316 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)) :: &
324 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)) :: &
325 grid_re_kh, & !< Grid Reynolds number for Laplacian horizontal viscosity at h points [nondim]
326 grid_re_ah, & !< Grid Reynolds number for Biharmonic horizontal viscosity at h points [nondim]
336 real :: vert_vort_mag
346 real :: visc_bound_rem
355 real :: gme_coeff_limiter
362 real :: backscat_subround
367 logical :: rescale_kh, legacy_bound
368 logical :: find_frictwork
369 logical :: apply_obc = .false.
370 logical :: use_meke_ku
371 logical :: use_meke_au
372 integer :: is, ie, js, je, isq, ieq, jsq, jeq, nz
373 integer :: i, j, k, n
374 real :: inv_pi3, inv_pi2, inv_pi6
375 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
376 isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
378 h_neglect = gv%H_subroundoff
379 h_neglect3 = h_neglect**3
380 inv_pi3 = 1.0/((4.0*atan(1.0))**3)
381 inv_pi2 = 1.0/((4.0*atan(1.0))**2)
382 inv_pi6 = inv_pi3 * inv_pi3
387 if (
present(obc))
then ;
if (
associated(obc))
then ;
if (obc%OBC_pe)
then 388 apply_obc = obc%Flather_u_BCs_exist_globally .or. obc%Flather_v_BCs_exist_globally
390 endif ;
endif ;
endif 392 if (.not.
associated(cs))
call mom_error(fatal, &
393 "MOM_hor_visc: Module must be initialized before it is used.")
394 if (.not.(cs%Laplacian .or. cs%biharmonic))
return 396 find_frictwork = (cs%id_FrictWork > 0)
397 if (cs%id_FrictWorkIntz > 0) find_frictwork = .true.
398 if (
associated(meke))
then 399 if (
associated(meke%mom_src)) find_frictwork = .true.
400 backscat_subround = 0.0
401 if (find_frictwork .and.
associated(meke%mom_src) .and. (meke%backscatter_Ro_c > 0.0) .and. &
402 (meke%backscatter_Ro_Pow /= 0.0)) &
403 backscat_subround = (1.0e-16/meke%backscatter_Ro_c)**(1.0/meke%backscatter_Ro_Pow)
407 if (
associated(varmix))
then 408 rescale_kh = varmix%Resoln_scaled_Kh
409 if (rescale_kh .and. &
410 (.not.
associated(varmix%Res_fn_h) .or. .not.
associated(varmix%Res_fn_q))) &
411 call mom_error(fatal,
"MOM_hor_visc: VarMix%Res_fn_h and " //&
412 "VarMix%Res_fn_q both need to be associated with Resoln_scaled_Kh.")
414 legacy_bound = (cs%Smagorinsky_Kh .or. cs%Leith_Kh) .and. &
415 (cs%bound_Kh .and. .not.cs%better_bound_Kh)
418 use_meke_ku =
associated(meke%Ku)
419 use_meke_au =
associated(meke%Au)
422 do j=jsq-1,jeq+2 ;
do i=isq-1,ieq+2
423 boundary_mask_h(i,j) = (g%mask2dCu(i,j) * g%mask2dCv(i,j) * g%mask2dCu(i-1,j) * g%mask2dCv(i,j-1))
426 do j=js-2,jeq+1 ;
do i=is-2,ieq+1
427 boundary_mask_q(i,j) = (g%mask2dCv(i,j) * g%mask2dCv(i+1,j) * g%mask2dCu(i,j) * g%mask2dCu(i,j-1))
431 gme_coeff_h(:,:,:) = 0.0
432 gme_coeff_q(:,:,:) = 0.0
433 str_xx_gme(:,:) = 0.0
434 str_xy_gme(:,:) = 0.0
437 call barotropic_get_tav(bt, ubtav, vbtav, g, us)
438 call pass_vector(ubtav, vbtav, g%Domain)
440 do j=js-1,je+2 ;
do i=is-1,ie+2
441 dudx_bt(i,j) = cs%DY_dxT(i,j)*(g%IdyCu(i,j) * ubtav(i,j) - &
442 g%IdyCu(i-1,j) * ubtav(i-1,j))
443 dvdy_bt(i,j) = cs%DX_dyT(i,j)*(g%IdxCv(i,j) * vbtav(i,j) - &
444 g%IdxCv(i,j-1) * vbtav(i,j-1))
447 do j=jsq,jeq+1 ;
do i=isq,ieq+1
448 sh_xx_bt(i,j) = dudx_bt(i,j) - dvdy_bt(i,j)
452 do j=js-2,jeq+1 ;
do i=is-2,ieq+1
453 dvdx_bt(i,j) = cs%DY_dxBu(i,j)*(vbtav(i+1,j)*g%IdyCv(i+1,j) &
454 - vbtav(i,j)*g%IdyCv(i,j))
455 dudy_bt(i,j) = cs%DX_dyBu(i,j)*(ubtav(i,j+1)*g%IdxCu(i,j+1) &
456 - ubtav(i,j)*g%IdxCu(i,j))
459 call pass_vector(dudx_bt, dvdy_bt, g%Domain, stagger=bgrid_ne)
460 call pass_vector(dvdx_bt, dudy_bt, g%Domain, stagger=agrid)
463 do j=js-1,jeq ;
do i=is-1,ieq
464 sh_xy_bt(i,j) = (2.0-g%mask2dBu(i,j)) * ( dvdx_bt(i,j) + dudy_bt(i,j) )
467 do j=js-1,jeq ;
do i=is-1,ieq
468 sh_xy_bt(i,j) = g%mask2dBu(i,j) * ( dvdx_bt(i,j) + dudy_bt(i,j) )
472 do j=jsq-1,jeq+2 ;
do i=isq-1,ieq+2
473 grad_vel_mag_bt_h(i,j) = boundary_mask_h(i,j) * (dudx_bt(i,j)**2 + dvdy_bt(i,j)**2 + &
474 (0.25*((dvdx_bt(i,j)+dvdx_bt(i-1,j-1))+(dvdx_bt(i,j-1)+dvdx_bt(i-1,j))))**2 + &
475 (0.25*((dudy_bt(i,j)+dudy_bt(i-1,j-1))+(dudy_bt(i,j-1)+dudy_bt(i-1,j))))**2)
478 do j=js-2,jeq+1 ;
do i=is-2,ieq+1
479 grad_vel_mag_bt_q(i,j) = boundary_mask_q(i,j) * (dvdx_bt(i,j)**2 + dudy_bt(i,j)**2 + &
480 (0.25*((dudx_bt(i,j)+dudx_bt(i+1,j+1))+(dudx_bt(i,j+1)+dudx_bt(i+1,j))))**2 + &
481 (0.25*((dvdy_bt(i,j)+dvdy_bt(i+1,j+1))+(dvdy_bt(i,j+1)+dvdy_bt(i+1,j))))**2)
521 do j=jsq-1,jeq+2 ;
do i=isq-1,ieq+2
522 dudx(i,j) = cs%DY_dxT(i,j)*(g%IdyCu(i,j) * u(i,j,k) - &
523 g%IdyCu(i-1,j) * u(i-1,j,k))
524 dvdy(i,j) = cs%DX_dyT(i,j)*(g%IdxCv(i,j) * v(i,j,k) - &
525 g%IdxCv(i,j-1) * v(i,j-1,k))
526 sh_xx(i,j) = dudx(i,j) - dvdy(i,j)
530 do j=jsq-2,jeq+2 ;
do i=isq-2,ieq+2
531 dvdx(i,j) = cs%DY_dxBu(i,j)*(v(i+1,j,k)*g%IdyCv(i+1,j) - v(i,j,k)*g%IdyCv(i,j))
532 dudy(i,j) = cs%DX_dyBu(i,j)*(u(i,j+1,k)*g%IdxCu(i,j+1) - u(i,j,k)*g%IdxCu(i,j))
540 if (cs%use_land_mask)
then 541 do j=js-2,je+2 ;
do i=isq-1,ieq+1
542 h_u(i,j) = 0.5 * (g%mask2dT(i,j)*h(i,j,k) + g%mask2dT(i+1,j)*h(i+1,j,k))
544 do j=jsq-1,jeq+1 ;
do i=is-2,ie+2
545 h_v(i,j) = 0.5 * (g%mask2dT(i,j)*h(i,j,k) + g%mask2dT(i,j+1)*h(i,j+1,k))
548 do j=js-2,je+2 ;
do i=isq-1,ieq+1
549 h_u(i,j) = 0.5 * (h(i,j,k) + h(i+1,j,k))
551 do j=jsq-1,jeq+1 ;
do i=is-2,ie+2
552 h_v(i,j) = 0.5 * (h(i,j,k) + h(i,j+1,k))
558 if (apply_obc)
then ;
do n=1,obc%number_of_segments
559 j = obc%segment(n)%HI%JsdB ; i = obc%segment(n)%HI%IsdB
560 if (obc%zero_strain .or. obc%freeslip_strain .or. obc%computed_strain)
then 561 if (obc%segment(n)%is_N_or_S .and. (j >= js-2) .and. (j <= jeq+1))
then 562 do i=obc%segment(n)%HI%IsdB,obc%segment(n)%HI%IedB
563 if (obc%zero_strain)
then 564 dvdx(i,j) = 0. ; dudy(i,j) = 0.
565 elseif (obc%freeslip_strain)
then 567 elseif (obc%computed_strain)
then 568 if (obc%segment(n)%direction == obc_direction_n)
then 569 dudy(i,j) = 2.0*cs%DX_dyBu(i,j)* &
570 (obc%segment(n)%tangential_vel(i,j,k) - u(i,j,k))*g%IdxCu(i,j)
572 dudy(i,j) = 2.0*cs%DX_dyBu(i,j)* &
573 (u(i,j+1,k) - obc%segment(n)%tangential_vel(i,j,k))*g%IdxCu(i,j+1)
575 elseif (obc%specified_strain)
then 576 if (obc%segment(n)%direction == obc_direction_n)
then 577 dudy(i,j) = cs%DX_dyBu(i,j)*obc%segment(n)%tangential_grad(i,j,k)*g%IdxCu(i,j)*g%dxBu(i,j)
579 dudy(i,j) = cs%DX_dyBu(i,j)*obc%segment(n)%tangential_grad(i,j,k)*g%IdxCu(i,j+1)*g%dxBu(i,j)
583 elseif (obc%segment(n)%is_E_or_W .and. (i >= is-2) .and. (i <= ieq+1))
then 584 do j=obc%segment(n)%HI%JsdB,obc%segment(n)%HI%JedB
585 if (obc%zero_strain)
then 586 dvdx(i,j) = 0. ; dudy(i,j) = 0.
587 elseif (obc%freeslip_strain)
then 589 elseif (obc%computed_strain)
then 590 if (obc%segment(n)%direction == obc_direction_e)
then 591 dvdx(i,j) = 2.0*cs%DY_dxBu(i,j)* &
592 (obc%segment(n)%tangential_vel(i,j,k) - v(i,j,k))*g%IdyCv(i,j)
594 dvdx(i,j) = 2.0*cs%DY_dxBu(i,j)* &
595 (v(i+1,j,k) - obc%segment(n)%tangential_vel(i,j,k))*g%IdyCv(i+1,j)
597 elseif (obc%specified_strain)
then 598 if (obc%segment(n)%direction == obc_direction_e)
then 599 dvdx(i,j) = cs%DY_dxBu(i,j)*obc%segment(n)%tangential_grad(i,j,k)*g%IdyCv(i,j)*g%dxBu(i,j)
601 dvdx(i,j) = cs%DY_dxBu(i,j)*obc%segment(n)%tangential_grad(i,j,k)*g%IdyCv(i+1,j)*g%dxBu(i,j)
609 if (obc%segment(n)%direction == obc_direction_n)
then 614 if ((j >= jsq-1) .and. (j <= jeq+1))
then 615 do i = max(is-2,obc%segment(n)%HI%isd), min(ie+2,obc%segment(n)%HI%ied)
619 elseif (obc%segment(n)%direction == obc_direction_s)
then 620 if ((j >= jsq-1) .and. (j <= jeq+1))
then 621 do i = max(is-2,obc%segment(n)%HI%isd), min(ie+2,obc%segment(n)%HI%ied)
622 h_v(i,j) = h(i,j+1,k)
625 elseif (obc%segment(n)%direction == obc_direction_e)
then 626 if ((i >= isq-1) .and. (i <= ieq+1))
then 627 do j = max(js-2,obc%segment(n)%HI%jsd), min(je+2,obc%segment(n)%HI%jed)
631 elseif (obc%segment(n)%direction == obc_direction_w)
then 632 if ((i >= isq-1) .and. (i <= ieq+1))
then 633 do j = max(js-2,obc%segment(n)%HI%jsd), min(je+2,obc%segment(n)%HI%jed)
634 h_u(i,j) = h(i+1,j,k)
640 if (apply_obc)
then ;
do n=1,obc%number_of_segments
641 j = obc%segment(n)%HI%JsdB ; i = obc%segment(n)%HI%IsdB
642 if (obc%segment(n)%direction == obc_direction_n)
then 643 if ((j >= js-2) .and. (j <= je))
then 644 do i = max(isq-1,obc%segment(n)%HI%IsdB), min(ieq+1,obc%segment(n)%HI%IedB)
645 h_u(i,j+1) = h_u(i,j)
648 elseif (obc%segment(n)%direction == obc_direction_s)
then 649 if ((j >= js-1) .and. (j <= je+1))
then 650 do i = max(isq-1,obc%segment(n)%HI%isd), min(ieq+1,obc%segment(n)%HI%ied)
651 h_u(i,j) = h_u(i,j+1)
654 elseif (obc%segment(n)%direction == obc_direction_e)
then 655 if ((i >= is-2) .and. (i <= ie))
then 656 do j = max(jsq-1,obc%segment(n)%HI%jsd), min(jeq+1,obc%segment(n)%HI%jed)
657 h_v(i+1,j) = h_v(i,j)
660 elseif (obc%segment(n)%direction == obc_direction_w)
then 661 if ((i >= is-1) .and. (i <= ie+1))
then 662 do j = max(jsq-1,obc%segment(n)%HI%jsd), min(jeq+1,obc%segment(n)%HI%jed)
663 h_v(i,j) = h_v(i+1,j)
672 do j=js-2,jeq+1 ;
do i=is-2,ieq+1
673 sh_xy(i,j) = (2.0-g%mask2dBu(i,j)) * ( dvdx(i,j) + dudy(i,j) )
676 do j=js-2,jeq+1 ;
do i=is-2,ieq+1
677 sh_xy(i,j) = g%mask2dBu(i,j) * ( dvdx(i,j) + dudy(i,j) )
682 if (cs%biharmonic)
then 683 do j=js-1,jeq+1 ;
do i=isq-1,ieq+1
684 del2u(i,j) = cs%Idxdy2u(i,j)*(cs%dy2h(i+1,j)*sh_xx(i+1,j) - cs%dy2h(i,j)*sh_xx(i,j)) + &
685 cs%Idx2dyCu(i,j)*(cs%dx2q(i,j)*sh_xy(i,j) - cs%dx2q(i,j-1)*sh_xy(i,j-1))
687 do j=jsq-1,jeq+1 ;
do i=is-1,ieq+1
688 del2v(i,j) = cs%Idxdy2v(i,j)*(cs%dy2q(i,j)*sh_xy(i,j) - cs%dy2q(i-1,j)*sh_xy(i-1,j)) - &
689 cs%Idx2dyCv(i,j)*(cs%dx2h(i,j+1)*sh_xx(i,j+1) - cs%dx2h(i,j)*sh_xx(i,j))
691 if (apply_obc) then;
if (obc%zero_biharmonic)
then 692 do n=1,obc%number_of_segments
693 i = obc%segment(n)%HI%IsdB ; j = obc%segment(n)%HI%JsdB
694 if (obc%segment(n)%is_N_or_S .and. (j >= jsq-1) .and. (j <= jeq+1))
then 695 do i=obc%segment(n)%HI%isd,obc%segment(n)%HI%ied
698 elseif (obc%segment(n)%is_E_or_W .and. (i >= isq-1) .and. (i <= ieq+1))
then 699 do j=obc%segment(n)%HI%jsd,obc%segment(n)%HI%jed
709 do j=jsq-2,jeq+2 ;
do i=isq-2,ieq+2
710 vort_xy(i,j) = (2.0-g%mask2dBu(i,j)) * ( dvdx(i,j) - dudy(i,j) )
713 do j=jsq-2,jeq+2 ;
do i=isq-2,ieq+2
714 vort_xy(i,j) = g%mask2dBu(i,j) * ( dvdx(i,j) - dudy(i,j) )
719 do j=jsq-1,jeq+2 ;
do i=isq-1,ieq+2
720 div_xx(i,j) = dudx(i,j) + dvdy(i,j)
723 if ((cs%Leith_Kh) .or. (cs%Leith_Ah))
then 726 do j=jsq-1,jeq+1 ;
do i=isq-1,ieq+2
727 dy_dxbu = g%dyBu(i,j) * g%IdxBu(i,j)
728 vort_xy_dx(i,j) = dy_dxbu * (vort_xy(i,j) * g%IdyCu(i,j) - vort_xy(i-1,j) * g%IdyCu(i-1,j))
731 do j=jsq-1,jeq+2 ;
do i=isq-1,ieq+1
732 dx_dybu = g%dxBu(i,j) * g%IdyBu(i,j)
733 vort_xy_dy(i,j) = dx_dybu * (vort_xy(i,j) * g%IdxCv(i,j) - vort_xy(i,j-1) * g%IdxCv(i,j-1))
737 do j=jsq-1,jeq+1 ;
do i=isq-1,ieq+1
738 dy_dxbu = g%dyBu(i,j) * g%IdxBu(i,j)
739 dx_dybu = g%dxBu(i,j) * g%IdyBu(i,j)
741 del2vort_q(i,j) = dy_dxbu * (vort_xy_dx(i+1,j) * g%IdyCv(i+1,j) - vort_xy_dx(i,j) * g%IdyCv(i,j)) + &
742 dx_dybu * (vort_xy_dy(i,j+1) * g%IdyCu(i,j+1) - vort_xy_dy(i,j) * g%IdyCu(i,j))
744 do j=jsq,jeq+1 ;
do i=isq,ieq+1
745 del2vort_h(i,j) = 0.25*(del2vort_q(i,j) + del2vort_q(i-1,j) + del2vort_q(i,j-1) + del2vort_q(i-1,j-1))
748 if (cs%modified_Leith)
then 751 do j=jsq-1,jeq+2 ;
do i=isq-1,ieq+1
752 div_xx_dx(i,j) = g%IdxCu(i,j)*(div_xx(i+1,j) - div_xx(i,j))
754 do j=jsq-1,jeq+1 ;
do i=isq-1,ieq+2
755 div_xx_dy(i,j) = g%IdyCv(i,j)*(div_xx(i,j+1) - div_xx(i,j))
759 do j=jsq,jeq+1 ;
do i=isq,ieq+1
760 grad_div_mag_h(i,j) =sqrt((0.5*(div_xx_dx(i,j) + div_xx_dx(i-1,j)))**2 + &
761 (0.5 * (div_xx_dy(i,j) + div_xx_dy(i,j-1)))**2)
764 do j=jsq-1,jeq+1 ;
do i=isq-1,ieq+1
765 grad_div_mag_q(i,j) =sqrt((0.5*(div_xx_dx(i,j) + div_xx_dx(i,j+1)))**2 + &
766 (0.5 * (div_xx_dy(i,j) + div_xx_dy(i+1,j)))**2)
771 do j=jsq-1,jeq+2 ;
do i=is-2,ieq+1
774 do j=jsq-1,jeq+1 ;
do i=isq-1,ieq+2
777 do j=jsq,jeq+1 ;
do i=isq,ieq+1
778 grad_div_mag_h(i,j) = 0.0
780 do j=jsq-1,jeq+1 ;
do i=isq-1,ieq+1
781 grad_div_mag_q(i,j) = 0.0
787 if (cs%use_beta_in_Leith)
then 788 do j=js-2,jeq+1 ;
do i=is-1,ieq+1
789 vort_xy_dx(i,j) = vort_xy_dx(i,j) + 0.5 * ( g%dF_dx(i,j) + g%dF_dx(i,j+1))
791 do j=js-1,jeq+1 ;
do i=is-2,ieq+1
792 vort_xy_dy(i,j) = vort_xy_dy(i,j) + 0.5 * ( g%dF_dy(i,j) + g%dF_dy(i+1,j))
796 if (cs%use_QG_Leith_visc)
then 798 do j=jsq,jeq+1 ;
do i=isq,ieq+1
799 grad_vort_mag_h_2d(i,j) = sqrt((0.5*(vort_xy_dx(i,j) + vort_xy_dx(i,j-1)))**2 + &
800 (0.5*(vort_xy_dy(i,j) + vort_xy_dy(i-1,j)))**2 )
802 do j=js-1,jeq ;
do i=is-1,ieq
803 grad_vort_mag_q_2d(i,j) = sqrt((0.5*(vort_xy_dx(i,j) + vort_xy_dx(i+1,j)))**2 + &
804 (0.5*(vort_xy_dy(i,j) + vort_xy_dy(i,j+1)))**2 )
808 call calc_qg_leith_viscosity(varmix, g, gv, us, h, k, div_xx_dx, div_xx_dy, &
809 vort_xy_dx, vort_xy_dy)
813 do j=jsq,jeq+1 ;
do i=isq,ieq+1
814 grad_vort_mag_h(i,j) = sqrt((0.5*(vort_xy_dx(i,j) + vort_xy_dx(i,j-1)))**2 + &
815 (0.5*(vort_xy_dy(i,j) + vort_xy_dy(i-1,j)))**2 )
817 do j=js-1,jeq ;
do i=is-1,ieq
818 grad_vort_mag_q(i,j) = sqrt((0.5*(vort_xy_dx(i,j) + vort_xy_dx(i+1,j)))**2 + &
819 (0.5*(vort_xy_dy(i,j) + vort_xy_dy(i,j+1)))**2 )
826 do j=jsq,jeq+1 ;
do i=isq,ieq+1
827 if ((cs%Smagorinsky_Kh) .or. (cs%Smagorinsky_Ah))
then 828 shear_mag = sqrt(sh_xx(i,j)*sh_xx(i,j) + &
829 0.25*((sh_xy(i-1,j-1)*sh_xy(i-1,j-1) + sh_xy(i,j)*sh_xy(i,j)) + &
830 (sh_xy(i-1,j)*sh_xy(i-1,j) + sh_xy(i,j-1)*sh_xy(i,j-1))))
832 if ((cs%Leith_Kh) .or. (cs%Leith_Ah))
then 833 if (cs%use_QG_Leith_visc)
then 834 vert_vort_mag = min(grad_vort_mag_h(i,j) + grad_div_mag_h(i,j),3.*grad_vort_mag_h_2d(i,j))
836 vert_vort_mag = (grad_vort_mag_h(i,j) + grad_div_mag_h(i,j))
839 if (cs%better_bound_Ah .or. cs%better_bound_Kh)
then 840 hrat_min = min(1.0, min(h_u(i,j), h_u(i-1,j), h_v(i,j), h_v(i,j-1)) / &
841 (h(i,j,k) + h_neglect) )
845 if (cs%Laplacian)
then 848 kh = cs%Kh_bg_xx(i,j)
849 if (cs%add_LES_viscosity)
then 850 if (cs%Smagorinsky_Kh) kh = kh + cs%Laplac2_const_xx(i,j) * shear_mag
851 if (cs%Leith_Kh) kh = kh + cs%Laplac3_const_xx(i,j) * vert_vort_mag*inv_pi3
853 if (cs%Smagorinsky_Kh) kh = max( kh, cs%Laplac2_const_xx(i,j) * shear_mag )
854 if (cs%Leith_Kh) kh = max( kh, cs%Laplac3_const_xx(i,j) * vert_vort_mag*inv_pi3)
857 if (rescale_kh) kh = varmix%Res_fn_h(i,j) * kh
858 if (cs%res_scale_MEKE) meke_res_fn = varmix%Res_fn_h(i,j)
860 if (legacy_bound) kh = min(kh, cs%Kh_Max_xx(i,j))
861 kh = max( kh, cs%Kh_bg_min )
863 kh = kh + meke%Ku(i,j) * meke_res_fn
864 if (cs%anisotropic) kh = kh + cs%Kh_aniso * ( 1. - cs%n1n2_h(i,j)**2 )
868 if (cs%better_bound_Kh)
then 869 if (kh >= hrat_min*cs%Kh_Max_xx(i,j))
then 871 kh = hrat_min*cs%Kh_Max_xx(i,j)
873 visc_bound_rem = 1.0 - kh / (hrat_min*cs%Kh_Max_xx(i,j))
877 if ((cs%id_Kh_h>0) .or. find_frictwork .or. cs%debug) kh_h(i,j,k) = kh
879 if (cs%id_grid_Re_Kh>0)
then 880 ke = 0.125*((u(i,j,k)+u(i-1,j,k))**2 + (v(i,j,k)+v(i,j-1,k))**2)
881 grid_re_kh(i,j,k) = (sqrt(ke) * sqrt(cs%grid_sp_h2(i,j))) &
882 / max(kh, cs%min_grid_Kh)
885 if (cs%id_div_xx_h>0) div_xx_h(i,j,k) = div_xx(i,j)
886 if (cs%id_sh_xx_h>0) sh_xx_h(i,j,k) = sh_xx(i,j)
888 str_xx(i,j) = -kh * sh_xx(i,j)
893 if (cs%anisotropic)
then 895 local_strain = 0.25 * ( (sh_xy(i,j) + sh_xy(i-1,j-1)) + (sh_xy(i-1,j) + sh_xy(i,j-1)) )
897 str_xx(i,j) = str_xx(i,j) - cs%Kh_aniso * cs%n1n2_h(i,j) * cs%n1n1_m_n2n2_h(i,j) * local_strain
900 if (cs%biharmonic)
then 903 ahsm = 0.0; ahlth = 0.0
904 if ((cs%Smagorinsky_Ah) .or. (cs%Leith_Ah))
then 905 if (cs%Smagorinsky_Ah)
then 906 if (cs%bound_Coriolis)
then 907 ahsm = shear_mag * (cs%Biharm_const_xx(i,j) + &
908 cs%Biharm_const2_xx(i,j)*shear_mag)
910 ahsm = cs%Biharm_const_xx(i,j) * shear_mag
913 if (cs%Leith_Ah) ahlth = cs%Biharm6_const_xx(i,j) * abs(del2vort_h(i,j)) * inv_pi6
914 ah = max(max(cs%Ah_bg_xx(i,j), ahsm), ahlth)
915 if (cs%bound_Ah .and. .not.cs%better_bound_Ah) &
916 ah = min(ah, cs%Ah_Max_xx(i,j))
918 ah = cs%Ah_bg_xx(i,j)
921 if (use_meke_au) ah = ah + meke%Au(i,j)
923 if (cs%Re_Ah > 0.0)
then 924 ke = 0.125*((u(i,j,k)+u(i-1,j,k))**2 + (v(i,j,k)+v(i,j-1,k))**2)
925 ah = sqrt(ke) * cs%Re_Ah_const_xx(i,j)
928 if (cs%better_bound_Ah)
then 929 ah = min(ah, visc_bound_rem*hrat_min*cs%Ah_Max_xx(i,j))
932 if ((cs%id_Ah_h>0) .or. find_frictwork .or. cs%debug) ah_h(i,j,k) = ah
934 if (cs%id_grid_Re_Ah>0)
then 935 ke = 0.125*((u(i,j,k)+u(i-1,j,k))**2 + (v(i,j,k)+v(i,j-1,k))**2)
936 grid_re_ah(i,j,k) = (sqrt(ke) * cs%grid_sp_h3(i,j)) &
937 / max(ah, cs%min_grid_Ah)
940 str_xx(i,j) = str_xx(i,j) + ah * &
941 (cs%DY_dxT(i,j) * (g%IdyCu(i,j)*del2u(i,j) - g%IdyCu(i-1,j)*del2u(i-1,j)) - &
942 cs%DX_dyT(i,j) * (g%IdxCv(i,j)*del2v(i,j) - g%IdxCv(i,j-1)*del2v(i,j-1)))
945 bhstr_xx(i,j) = ah * &
946 (cs%DY_dxT(i,j) * (g%IdyCu(i,j)*del2u(i,j) - g%IdyCu(i-1,j)*del2u(i-1,j)) - &
947 cs%DX_dyT(i,j) * (g%IdxCv(i,j)*del2v(i,j) - g%IdxCv(i,j-1)*del2v(i,j-1)))
948 bhstr_xx(i,j) = bhstr_xx(i,j) * (h(i,j,k) * cs%reduction_xx(i,j))
954 if (cs%biharmonic)
then 956 do j=js-1,jeq ;
do i=is-1,ieq
957 ddel2vdx(i,j) = cs%DY_dxBu(i,j)*(del2v(i+1,j)*g%IdyCv(i+1,j) - del2v(i,j)*g%IdyCv(i,j))
958 ddel2udy(i,j) = cs%DX_dyBu(i,j)*(del2u(i,j+1)*g%IdxCu(i,j+1) - del2u(i,j)*g%IdxCu(i,j))
961 if (apply_obc)
then ;
if (obc%zero_strain .or. obc%freeslip_strain)
then 962 do n=1,obc%number_of_segments
963 j = obc%segment(n)%HI%JsdB ; i = obc%segment(n)%HI%IsdB
964 if (obc%segment(n)%is_N_or_S .and. (j >= js-1) .and. (j <= jeq))
then 965 do i=obc%segment(n)%HI%IsdB,obc%segment(n)%HI%IedB
966 if (obc%zero_strain)
then 967 ddel2vdx(i,j) = 0. ; ddel2udy(i,j) = 0.
968 elseif (obc%freeslip_strain)
then 972 elseif (obc%segment(n)%is_E_or_W .and. (i >= is-1) .and. (i <= ieq))
then 973 do j=obc%segment(n)%HI%JsdB,obc%segment(n)%HI%JedB
974 if (obc%zero_strain)
then 975 ddel2vdx(i,j) = 0. ; ddel2udy(i,j) = 0.
976 elseif (obc%freeslip_strain)
then 987 do j=js-1,jeq ;
do i=is-1,ieq
988 if ((cs%Smagorinsky_Kh) .or. (cs%Smagorinsky_Ah))
then 989 shear_mag = sqrt(sh_xy(i,j)*sh_xy(i,j) + &
990 0.25*((sh_xx(i,j)*sh_xx(i,j) + sh_xx(i+1,j+1)*sh_xx(i+1,j+1)) + &
991 (sh_xx(i,j+1)*sh_xx(i,j+1) + sh_xx(i+1,j)*sh_xx(i+1,j))))
993 if ((cs%Leith_Kh) .or. (cs%Leith_Ah))
then 994 if (cs%use_QG_Leith_visc)
then 995 vert_vort_mag = min(grad_vort_mag_q(i,j) + grad_div_mag_q(i,j), 3.*grad_vort_mag_q_2d(i,j))
997 vert_vort_mag = (grad_vort_mag_q(i,j) + grad_div_mag_q(i,j))
1000 h2uq = 4.0 * h_u(i,j) * h_u(i,j+1)
1001 h2vq = 4.0 * h_v(i,j) * h_v(i+1,j)
1002 hq(i,j) = 2.0 * h2uq * h2vq / (h_neglect3 + (h2uq + h2vq) * &
1003 ((h_u(i,j) + h_u(i,j+1)) + (h_v(i,j) + h_v(i+1,j))))
1005 if (cs%better_bound_Ah .or. cs%better_bound_Kh)
then 1006 hrat_min = min(1.0, min(h_u(i,j), h_u(i,j+1), h_v(i,j), h_v(i+1,j)) / &
1007 (hq(i,j) + h_neglect) )
1008 visc_bound_rem = 1.0
1011 if (cs%no_slip .and. (g%mask2dBu(i,j) < 0.5))
then 1012 if ((g%mask2dCu(i,j) + g%mask2dCu(i,j+1)) + &
1013 (g%mask2dCv(i,j) + g%mask2dCv(i+1,j)) > 0.0)
then 1016 hu = g%mask2dCu(i,j) * h_u(i,j) + g%mask2dCu(i,j+1) * h_u(i,j+1)
1017 hv = g%mask2dCv(i,j) * h_v(i,j) + g%mask2dCv(i+1,j) * h_v(i+1,j)
1018 if ((g%mask2dCu(i,j) + g%mask2dCu(i,j+1)) * &
1019 (g%mask2dCv(i,j) + g%mask2dCv(i+1,j)) == 0.0)
then 1025 hq(i,j) = 2.0 * (hu * hv) / ((hu + hv) + h_neglect)
1026 hrat_min = min(1.0, min(hu, hv) / (hq(i,j) + h_neglect) )
1031 if (cs%Laplacian)
then 1034 kh = cs%Kh_bg_xy(i,j)
1035 if (cs%add_LES_viscosity)
then 1036 if (cs%Smagorinsky_Kh) kh = kh + cs%Laplac2_const_xx(i,j) * shear_mag
1037 if (cs%Leith_Kh) kh = kh + cs%Laplac3_const_xx(i,j) * vert_vort_mag*inv_pi3
1039 if (cs%Smagorinsky_Kh) kh = max( kh, cs%Laplac2_const_xy(i,j) * shear_mag )
1040 if (cs%Leith_Kh) kh = max( kh, cs%Laplac3_const_xy(i,j) * vert_vort_mag*inv_pi3)
1043 if (rescale_kh) kh = varmix%Res_fn_q(i,j) * kh
1044 if (cs%res_scale_MEKE) meke_res_fn = varmix%Res_fn_q(i,j)
1046 if (legacy_bound) kh = min(kh, cs%Kh_Max_xy(i,j))
1047 kh = max( kh, cs%Kh_bg_min )
1048 if (use_meke_ku)
then 1049 kh = kh + 0.25*( (meke%Ku(i,j) + meke%Ku(i+1,j+1)) + &
1050 (meke%Ku(i+1,j) + meke%Ku(i,j+1)) ) * meke_res_fn
1053 if (cs%anisotropic) kh = kh + cs%Kh_aniso * cs%n1n2_q(i,j)**2
1057 if (cs%better_bound_Kh)
then 1058 if (kh >= hrat_min*cs%Kh_Max_xy(i,j))
then 1059 visc_bound_rem = 0.0
1060 kh = hrat_min*cs%Kh_Max_xy(i,j)
1061 elseif (cs%Kh_Max_xy(i,j)>0.)
then 1062 visc_bound_rem = 1.0 - kh / (hrat_min*cs%Kh_Max_xy(i,j))
1066 if (cs%id_Kh_q>0 .or. cs%debug) kh_q(i,j,k) = kh
1067 if (cs%id_vort_xy_q>0) vort_xy_q(i,j,k) = vort_xy(i,j)
1068 if (cs%id_sh_xy_q>0) sh_xy_q(i,j,k) = sh_xy(i,j)
1070 str_xy(i,j) = -kh * sh_xy(i,j)
1075 if (cs%anisotropic)
then 1077 local_strain = 0.25 * ( (sh_xx(i,j) + sh_xx(i+1,j+1)) + (sh_xx(i+1,j) + sh_xx(i,j+1)) )
1079 str_xy(i,j) = str_xy(i,j) - cs%Kh_aniso * cs%n1n2_q(i,j) * cs%n1n1_m_n2n2_q(i,j) * local_strain
1082 if (cs%biharmonic)
then 1085 ahsm = 0.0 ; ahlth = 0.0
1086 if (cs%Smagorinsky_Ah .or. cs%Leith_Ah)
then 1087 if (cs%Smagorinsky_Ah)
then 1088 if (cs%bound_Coriolis)
then 1089 ahsm = shear_mag * (cs%Biharm_const_xy(i,j) + &
1090 cs%Biharm_const2_xy(i,j)*shear_mag)
1092 ahsm = cs%Biharm_const_xy(i,j) * shear_mag
1095 if (cs%Leith_Ah) ahlth = cs%Biharm6_const_xy(i,j) * abs(del2vort_q(i,j)) * inv_pi6
1096 ah = max(max(cs%Ah_bg_xy(i,j), ahsm), ahlth)
1097 if (cs%bound_Ah .and. .not.cs%better_bound_Ah) &
1098 ah = min(ah, cs%Ah_Max_xy(i,j))
1100 ah = cs%Ah_bg_xy(i,j)
1103 if (use_meke_au)
then 1104 ah = ah + 0.25*( (meke%Au(i,j) + meke%Au(i+1,j+1)) + &
1105 (meke%Au(i+1,j) + meke%Au(i,j+1)) )
1108 if (cs%Re_Ah > 0.0)
then 1109 ke = 0.125*((u(i,j,k)+u(i,j+1,k))**2 + (v(i,j,k)+v(i+1,j,k))**2)
1110 ah = sqrt(ke) * cs%Re_Ah_const_xy(i,j)
1113 if (cs%better_bound_Ah)
then 1114 ah = min(ah, visc_bound_rem*hrat_min*cs%Ah_Max_xy(i,j))
1117 if (cs%id_Ah_q>0 .or. cs%debug) ah_q(i,j,k) = ah
1119 str_xy(i,j) = str_xy(i,j) + ah * ( ddel2vdx(i,j) + ddel2udy(i,j) )
1122 bhstr_xy(i,j) = ah * ( ddel2vdx(i,j) + ddel2udy(i,j) ) * &
1123 (hq(i,j) * g%mask2dBu(i,j) * cs%reduction_xy(i,j))
1129 if (cs%use_GME)
then 1130 call thickness_diffuse_get_kh(td, kh_u_gme, kh_v_gme, g)
1131 call pass_vector(kh_u_gme, kh_v_gme, g%Domain)
1133 do j=jsq,jeq+1 ;
do i=isq,ieq+1
1134 if (grad_vel_mag_bt_h(i,j)>0)
then 1135 gme_coeff = cs%GME_efficiency * (min(g%bathyT(i,j)/cs%GME_h0,1.0)**2) * &
1136 (0.25*(kh_u_gme(i,j,k)+kh_u_gme(i-1,j,k)+kh_v_gme(i,j,k)+kh_v_gme(i,j-1,k)))
1142 gme_coeff = gme_coeff * boundary_mask_h(i,j)
1143 gme_coeff = min(gme_coeff, cs%GME_limiter)
1145 if ((cs%id_GME_coeff_h>0) .or. find_frictwork) gme_coeff_h(i,j,k) = gme_coeff
1146 str_xx_gme(i,j) = gme_coeff * sh_xx_bt(i,j)
1150 do j=js-1,jeq ;
do i=is-1,ieq
1151 if (grad_vel_mag_bt_q(i,j)>0)
then 1152 gme_coeff = cs%GME_efficiency * (min(g%bathyT(i,j)/cs%GME_h0,1.0)**2) * &
1153 (0.25*(kh_u_gme(i,j,k)+kh_u_gme(i,j+1,k)+kh_v_gme(i,j,k)+kh_v_gme(i+1,j,k)))
1159 gme_coeff = gme_coeff * boundary_mask_q(i,j)
1160 gme_coeff = min(gme_coeff, cs%GME_limiter)
1162 if (cs%id_GME_coeff_q>0) gme_coeff_q(i,j,k) = gme_coeff
1163 str_xy_gme(i,j) = gme_coeff * sh_xy_bt(i,j)
1168 call smooth_gme(cs,g,gme_flux_h=str_xx_gme)
1169 call smooth_gme(cs,g,gme_flux_q=str_xy_gme)
1171 do j=jsq,jeq+1 ;
do i=isq,ieq+1
1172 str_xx(i,j) = (str_xx(i,j) + str_xx_gme(i,j)) * (h(i,j,k) * cs%reduction_xx(i,j))
1175 do j=js-1,jeq ;
do i=is-1,ieq
1177 if (cs%no_slip)
then 1178 str_xy(i,j) = (str_xy(i,j) + str_xy_gme(i,j)) * (hq(i,j) * cs%reduction_xy(i,j))
1180 str_xy(i,j) = (str_xy(i,j) + str_xy_gme(i,j)) * (hq(i,j) * g%mask2dBu(i,j) * cs%reduction_xy(i,j))
1184 if (
associated(meke%GME_snk))
then 1185 do j=js,je ;
do i=is,ie
1186 frictwork_gme(i,j,k) = gme_coeff_h(i,j,k) * h(i,j,k) * gv%H_to_kg_m2 * grad_vel_mag_bt_h(i,j)
1191 do j=jsq,jeq+1 ;
do i=isq,ieq+1
1192 str_xx(i,j) = str_xx(i,j) * (h(i,j,k) * cs%reduction_xx(i,j))
1195 do j=js-1,jeq ;
do i=is-1,ieq
1196 if (cs%no_slip)
then 1197 str_xy(i,j) = str_xy(i,j) * (hq(i,j) * cs%reduction_xy(i,j))
1199 str_xy(i,j) = str_xy(i,j) * (hq(i,j) * g%mask2dBu(i,j) * cs%reduction_xy(i,j))
1206 do j=js,je ;
do i=isq,ieq
1207 diffu(i,j,k) = ((g%IdyCu(i,j)*(cs%dy2h(i,j) *str_xx(i,j) - &
1208 cs%dy2h(i+1,j)*str_xx(i+1,j)) + &
1209 g%IdxCu(i,j)*(cs%dx2q(i,j-1)*str_xy(i,j-1) - &
1210 cs%dx2q(i,j) *str_xy(i,j))) * &
1211 g%IareaCu(i,j)) / (h_u(i,j) + h_neglect)
1217 do n=1,obc%number_of_segments
1218 if (obc%segment(n)%is_E_or_W)
then 1219 i = obc%segment(n)%HI%IsdB
1220 do j=obc%segment(n)%HI%jsd,obc%segment(n)%HI%jed
1228 do j=jsq,jeq ;
do i=is,ie
1229 diffv(i,j,k) = ((g%IdyCv(i,j)*(cs%dy2q(i-1,j)*str_xy(i-1,j) - &
1230 cs%dy2q(i,j) *str_xy(i,j)) - &
1231 g%IdxCv(i,j)*(cs%dx2h(i,j) *str_xx(i,j) - &
1232 cs%dx2h(i,j+1)*str_xx(i,j+1))) * &
1233 g%IareaCv(i,j)) / (h_v(i,j) + h_neglect)
1238 do n=1,obc%number_of_segments
1239 if (obc%segment(n)%is_N_or_S)
then 1240 j = obc%segment(n)%HI%JsdB
1241 do i=obc%segment(n)%HI%isd,obc%segment(n)%HI%ied
1248 if (find_frictwork)
then ;
do j=js,je ;
do i=is,ie
1251 frictwork(i,j,k) = gv%H_to_RZ * ( &
1252 (str_xx(i,j)*(u(i,j,k)-u(i-1,j,k))*g%IdxT(i,j) &
1253 -str_xx(i,j)*(v(i,j,k)-v(i,j-1,k))*g%IdyT(i,j)) &
1254 +0.25*((str_xy(i,j)*( &
1255 (u(i,j+1,k)-u(i,j,k))*g%IdyBu(i,j) &
1256 +(v(i+1,j,k)-v(i,j,k))*g%IdxBu(i,j) ) &
1257 +str_xy(i-1,j-1)*( &
1258 (u(i-1,j,k)-u(i-1,j-1,k))*g%IdyBu(i-1,j-1) &
1259 +(v(i,j-1,k)-v(i-1,j-1,k))*g%IdxBu(i-1,j-1) )) &
1261 (u(i-1,j+1,k)-u(i-1,j,k))*g%IdyBu(i-1,j) &
1262 +(v(i,j,k)-v(i-1,j,k))*g%IdxBu(i-1,j) ) &
1264 (u(i,j,k)-u(i,j-1,k))*g%IdyBu(i,j-1) &
1265 +(v(i+1,j-1,k)-v(i,j-1,k))*g%IdxBu(i,j-1) )) ) )
1266 enddo ;
enddo ;
endif 1271 if (find_frictwork .and.
associated(meke))
then ;
if (
associated(meke%mom_src))
then 1273 do j=js,je ;
do i=is,ie
1274 meke%mom_src(i,j) = 0.
1276 if (
associated(meke%GME_snk))
then 1277 do j=js,je ;
do i=is,ie
1278 meke%GME_snk(i,j) = 0.
1282 if (meke%backscatter_Ro_c /= 0.)
then 1283 do j=js,je ;
do i=is,ie
1284 fath = 0.25*( (abs(g%CoriolisBu(i-1,j-1)) + abs(g%CoriolisBu(i,j))) + &
1285 (abs(g%CoriolisBu(i-1,j)) + abs(g%CoriolisBu(i,j-1))) )
1286 shear_mag = sqrt(sh_xx(i,j)*sh_xx(i,j) + &
1287 0.25*((sh_xy(i-1,j-1)*sh_xy(i-1,j-1) + sh_xy(i,j)*sh_xy(i,j)) + &
1288 (sh_xy(i-1,j)*sh_xy(i-1,j) + sh_xy(i,j-1)*sh_xy(i,j-1))))
1289 if (cs%answers_2018)
then 1290 fath = (us%s_to_T*fath)**meke%backscatter_Ro_pow
1293 shear_mag = ( ( (us%s_to_T*shear_mag)**meke%backscatter_Ro_pow ) + 1.e-30 ) &
1294 * meke%backscatter_Ro_c
1297 roscl = shear_mag / ( fath + shear_mag )
1299 if (fath <= backscat_subround*shear_mag)
then 1302 sh_f_pow = meke%backscatter_Ro_c * (shear_mag / fath)**meke%backscatter_Ro_pow
1303 roscl = sh_f_pow / (1.0 + sh_f_pow)
1308 meke%mom_src(i,j) = meke%mom_src(i,j) + gv%H_to_RZ * ( &
1309 ((str_xx(i,j)-roscl*bhstr_xx(i,j))*(u(i,j,k)-u(i-1,j,k))*g%IdxT(i,j) &
1310 -(str_xx(i,j)-roscl*bhstr_xx(i,j))*(v(i,j,k)-v(i,j-1,k))*g%IdyT(i,j)) &
1311 +0.25*(((str_xy(i,j)-roscl*bhstr_xy(i,j))*( &
1312 (u(i,j+1,k)-u(i,j,k))*g%IdyBu(i,j) &
1313 +(v(i+1,j,k)-v(i,j,k))*g%IdxBu(i,j) ) &
1314 +(str_xy(i-1,j-1)-roscl*bhstr_xy(i-1,j-1))*( &
1315 (u(i-1,j,k)-u(i-1,j-1,k))*g%IdyBu(i-1,j-1) &
1316 +(v(i,j-1,k)-v(i-1,j-1,k))*g%IdxBu(i-1,j-1) )) &
1317 +((str_xy(i-1,j)-roscl*bhstr_xy(i-1,j))*( &
1318 (u(i-1,j+1,k)-u(i-1,j,k))*g%IdyBu(i-1,j) &
1319 +(v(i,j,k)-v(i-1,j,k))*g%IdxBu(i-1,j) ) &
1320 +(str_xy(i,j-1)-roscl*bhstr_xy(i,j-1))*( &
1321 (u(i,j,k)-u(i,j-1,k))*g%IdyBu(i,j-1) &
1322 +(v(i+1,j-1,k)-v(i,j-1,k))*g%IdxBu(i,j-1) )) ) )
1326 do j=js,je ;
do i=is,ie
1327 meke%mom_src(i,j) = meke%mom_src(i,j) + frictwork(i,j,k)
1330 if (cs%use_GME .and.
associated(meke))
then ;
if (
associated(meke%GME_snk))
then 1331 do j=js,je ;
do i=is,ie
1332 meke%GME_snk(i,j) = meke%GME_snk(i,j) + frictwork_gme(i,j,k)
1341 if (cs%id_diffu>0)
call post_data(cs%id_diffu, diffu, cs%diag)
1342 if (cs%id_diffv>0)
call post_data(cs%id_diffv, diffv, cs%diag)
1343 if (cs%id_FrictWork>0)
call post_data(cs%id_FrictWork, frictwork, cs%diag)
1344 if (cs%id_FrictWork_GME>0)
call post_data(cs%id_FrictWork_GME, frictwork_gme, cs%diag)
1345 if (cs%id_Ah_h>0)
call post_data(cs%id_Ah_h, ah_h, cs%diag)
1346 if (cs%id_grid_Re_Ah>0)
call post_data(cs%id_grid_Re_Ah, grid_re_ah, cs%diag)
1347 if (cs%id_div_xx_h>0)
call post_data(cs%id_div_xx_h, div_xx_h, cs%diag)
1348 if (cs%id_vort_xy_q>0)
call post_data(cs%id_vort_xy_q, vort_xy_q, cs%diag)
1349 if (cs%id_sh_xx_h>0)
call post_data(cs%id_sh_xx_h, sh_xx_h, cs%diag)
1350 if (cs%id_sh_xy_q>0)
call post_data(cs%id_sh_xy_q, sh_xy_q, cs%diag)
1351 if (cs%id_Ah_q>0)
call post_data(cs%id_Ah_q, ah_q, cs%diag)
1352 if (cs%id_Kh_h>0)
call post_data(cs%id_Kh_h, kh_h, cs%diag)
1353 if (cs%id_grid_Re_Kh>0)
call post_data(cs%id_grid_Re_Kh, grid_re_kh, cs%diag)
1354 if (cs%id_Kh_q>0)
call post_data(cs%id_Kh_q, kh_q, cs%diag)
1355 if (cs%id_GME_coeff_h > 0)
call post_data(cs%id_GME_coeff_h, gme_coeff_h, cs%diag)
1356 if (cs%id_GME_coeff_q > 0)
call post_data(cs%id_GME_coeff_q, gme_coeff_q, cs%diag)
1359 if (cs%Laplacian)
then 1360 call hchksum(kh_h,
"Kh_h", g%HI, haloshift=0, scale=us%L_to_m**2*us%s_to_T)
1361 call bchksum(kh_q,
"Kh_q", g%HI, haloshift=0, scale=us%L_to_m**2*us%s_to_T)
1363 if (cs%biharmonic)
call hchksum(ah_h,
"Ah_h", g%HI, haloshift=0, scale=us%L_to_m**4*us%s_to_T)
1364 if (cs%biharmonic)
call bchksum(ah_q,
"Ah_q", g%HI, haloshift=0, scale=us%L_to_m**4*us%s_to_T)
1367 if (cs%id_FrictWorkIntz > 0)
then 1369 do i=is,ie ; frictworkintz(i,j) = frictwork(i,j,1) ;
enddo 1370 do k=2,nz ;
do i=is,ie
1371 frictworkintz(i,j) = frictworkintz(i,j) + frictwork(i,j,k)
1374 call post_data(cs%id_FrictWorkIntz, frictworkintz, cs%diag)
1393 if (
present(adp) .and. (cs%id_hf_diffu_2d > 0))
then 1394 allocate(hf_diffu_2d(g%IsdB:g%IedB,g%jsd:g%jed))
1395 hf_diffu_2d(:,:) = 0.0
1396 do k=1,nz ;
do j=js,je ;
do i=isq,ieq
1397 hf_diffu_2d(i,j) = hf_diffu_2d(i,j) + diffu(i,j,k) * adp%diag_hfrac_u(i,j,k)
1398 enddo ;
enddo ;
enddo 1399 call post_data(cs%id_hf_diffu_2d, hf_diffu_2d, cs%diag)
1400 deallocate(hf_diffu_2d)
1402 if (
present(adp) .and. (cs%id_hf_diffv_2d > 0))
then 1403 allocate(hf_diffv_2d(g%isd:g%ied,g%JsdB:g%JedB))
1404 hf_diffv_2d(:,:) = 0.0
1405 do k=1,nz ;
do j=jsq,jeq ;
do i=is,ie
1406 hf_diffv_2d(i,j) = hf_diffv_2d(i,j) + diffv(i,j,k) * adp%diag_hfrac_v(i,j,k)
1407 enddo ;
enddo ;
enddo 1408 call post_data(cs%id_hf_diffv_2d, hf_diffv_2d, cs%diag)
1409 deallocate(hf_diffv_2d)