The following subroutine calculates the thickness of the surface boundary layer for applying an elevated viscosity. A bulk Richardson criterion or the thickness of the topmost NKML layers (with a bulk mixed layer) are currently used. The thicknesses are given in terms of fractional layers, so that this thickness will move as the thickness of the topmost layers change.
1019 type(verticalgrid_type),
intent(in) :: gv
1020 real,
dimension(SZIB_(G),SZJ_(G),SZK_(G)), &
1022 real,
dimension(SZI_(G),SZJB_(G),SZK_(G)), &
1024 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)), &
1026 type(thermo_var_ptrs),
intent(in) :: tv
1029 type(forcing),
intent(in) :: fluxes
1032 type(vertvisc_type),
intent(inout) :: visc
1034 real,
intent(in) :: dt
1035 type(set_visc_cs),
pointer :: cs
1060 real,
dimension(SZIB_(G)) :: &
1083 real,
dimension(SZIB_(G),SZJ_(G)) :: &
1086 real,
dimension(SZI_(G),SZJB_(G)) :: &
1089 real :: h_at_vel(szib_(g),szk_(g))
1092 integer :: k_massive(szib_(g))
1148 real :: h_to_m, m_to_h
1151 logical :: use_eos, do_any, do_any_shelf, do_i(szib_(g))
1152 integer :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz, k2, nkmb, nkml, n
1153 type(ocean_obc_type),
pointer :: obc => null()
1155 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1156 isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
1157 nkmb = gv%nk_rho_varies ; nkml = gv%nkml
1159 if (.not.
associated(cs))
call mom_error(fatal,
"MOM_vert_friction(visc_ML): "//&
1160 "Module must be initialized before it is used.")
1161 if (.not.(cs%dynamic_viscous_ML .or.
associated(fluxes%frac_shelf_h)))
return 1163 rho0x400_g = 400.0*(gv%Rho0/gv%g_Earth)*gv%m_to_H
1164 u_bg_sq = cs%drag_bg_vel * cs%drag_bg_vel
1165 cdrag_sqrt=sqrt(cs%cdrag)
1168 use_eos =
associated(tv%eqn_of_state)
1169 dt_rho0 = dt/gv%H_to_kg_m2
1170 h_neglect = gv%H_subroundoff
1171 h_tiny = 2.0*gv%Angstrom + h_neglect
1172 g_h_rho0 = (gv%g_Earth * gv%H_to_m) / gv%Rho0
1173 h_to_m = gv%H_to_m ; m_to_h = gv%m_to_H
1175 if (
associated(fluxes%frac_shelf_h))
then 1178 if (.not.
associated(fluxes%frac_shelf_u))
call mom_error(fatal, &
1179 "set_viscous_ML: fluxes%frac_shelf_h is associated, but " // &
1180 "fluxes%frac_shelf_u is not.")
1181 if (.not.
associated(fluxes%frac_shelf_v))
call mom_error(fatal, &
1182 "set_viscous_ML: fluxes%frac_shelf_h is associated, but " // &
1183 "fluxes%frac_shelf_v is not.")
1184 if (.not.
associated(visc%taux_shelf))
then 1185 allocate(visc%taux_shelf(g%IsdB:g%IedB,g%jsd:g%jed))
1186 visc%taux_shelf(:,:) = 0.0
1188 if (.not.
associated(visc%tauy_shelf))
then 1189 allocate(visc%tauy_shelf(g%isd:g%ied,g%JsdB:g%JedB))
1190 visc%tauy_shelf(:,:) = 0.0
1192 if (.not.
associated(visc%tbl_thick_shelf_u))
then 1193 allocate(visc%tbl_thick_shelf_u(g%IsdB:g%IedB,g%jsd:g%jed))
1194 visc%tbl_thick_shelf_u(:,:) = 0.0
1196 if (.not.
associated(visc%tbl_thick_shelf_v))
then 1197 allocate(visc%tbl_thick_shelf_v(g%isd:g%ied,g%JsdB:g%JedB))
1198 visc%tbl_thick_shelf_v(:,:) = 0.0
1200 if (.not.
associated(visc%kv_tbl_shelf_u))
then 1201 allocate(visc%kv_tbl_shelf_u(g%IsdB:g%IedB,g%jsd:g%jed))
1202 visc%kv_tbl_shelf_u(:,:) = 0.0
1204 if (.not.
associated(visc%kv_tbl_shelf_v))
then 1205 allocate(visc%kv_tbl_shelf_v(g%isd:g%ied,g%JsdB:g%JedB))
1206 visc%kv_tbl_shelf_v(:,:) = 0.0
1214 do j=js-1,je ;
do i=is-1,ie+1
1215 mask_v(i,j) = g%mask2dCv(i,j)
1218 do j=js-1,je+1 ;
do i=is-1,ie
1219 mask_u(i,j) = g%mask2dCu(i,j)
1222 if (
associated(obc))
then ;
do n=1,obc%number_of_segments
1225 if (.not. obc%segment(n)%on_pe) cycle
1227 i = obc%segment(n)%HI%IsdB ; j = obc%segment(n)%HI%JsdB
1228 if (obc%segment(n)%is_N_or_S .and. (j >= js-1) .and. (j <= je))
then 1229 do i = max(is-1,obc%segment(n)%HI%IsdB), min(ie,obc%segment(n)%HI%IedB)
1230 if (obc%segment(n)%direction == obc_direction_n) mask_u(i,j+1) = 0.0
1231 if (obc%segment(n)%direction == obc_direction_s) mask_u(i,j) = 0.0
1233 elseif (obc%segment(n)%is_E_or_W .and. (i >= is-1) .and. (i <= je))
then 1234 do j = max(js-1,obc%segment(n)%HI%JsdB), min(je,obc%segment(n)%HI%JedB)
1235 if (obc%segment(n)%direction == obc_direction_e) mask_v(i+1,j) = 0.0
1236 if (obc%segment(n)%direction == obc_direction_w) mask_v(i,j) = 0.0
1252 if (cs%dynamic_viscous_ML)
then 1256 if (g%mask2dCu(i,j) < 0.5)
then 1257 do_i(i) = .false. ; visc%nkml_visc_u(i,j) = nkml
1259 do_i(i) = .true. ; do_any = .true.
1261 thtot(i) = 0.0 ; shtot(i) = 0.0 ; rhtot(i) = 0.0
1262 uhtot(i) = dt_rho0 * fluxes%taux(i,j)
1263 vhtot(i) = 0.25 * dt_rho0 * ((fluxes%tauy(i,j) + fluxes%tauy(i+1,j-1)) + &
1264 (fluxes%tauy(i,j-1) + fluxes%tauy(i+1,j)))
1266 if (cs%omega_frac >= 1.0)
then ; absf = 2.0*cs%omega ;
else 1267 absf = 0.5*(abs(g%CoriolisBu(i,j)) + abs(g%CoriolisBu(i,j-1)))
1268 if (cs%omega_frac > 0.0) &
1269 absf = sqrt(cs%omega_frac*4.0*cs%omega**2 + (1.0-cs%omega_frac)*absf**2)
1271 u_star = max(cs%ustar_min, 0.5 * (fluxes%ustar(i,j) + fluxes%ustar(i+1,j)))
1272 idecay_len_tke(i) = ((absf / u_star) * cs%TKE_decay) * h_to_m
1276 if (do_any)
then ;
do k=1,nz
1279 if (use_eos .and. (k==nkml+1))
then 1282 press(i) = gv%H_to_Pa * htot(i)
1284 i_2hlay = 1.0 / (h(i,j,k2) + h(i+1,j,k2) + h_neglect)
1285 t_eos(i) = (h(i,j,k2)*tv%T(i,j,k2) + h(i+1,j,k2)*tv%T(i+1,j,k2)) * i_2hlay
1286 s_eos(i) = (h(i,j,k2)*tv%S(i,j,k2) + h(i+1,j,k2)*tv%S(i+1,j,k2)) * i_2hlay
1288 call calculate_density_derivs(t_eos, s_eos, press, dr_dt, dr_ds, &
1289 isq-g%IsdB+1, ieq-isq+1, tv%eqn_of_state)
1292 do i=isq,ieq ;
if (do_i(i))
then 1294 hlay = 0.5*(h(i,j,k) + h(i+1,j,k))
1295 if (hlay > h_tiny)
then 1296 i_2hlay = 1.0 / (h(i,j,k) + h(i+1,j,k))
1297 v_at_u = 0.5 * (h(i,j,k) * (v(i,j,k) + v(i,j-1,k)) + &
1298 h(i+1,j,k) * (v(i+1,j,k) + v(i+1,j-1,k))) * i_2hlay
1299 uh2 = (uhtot(i) - htot(i)*u(i,j,k))**2 + (vhtot(i) - htot(i)*v_at_u)**2
1302 t_lay = (h(i,j,k)*tv%T(i,j,k) + h(i+1,j,k)*tv%T(i+1,j,k)) * i_2hlay
1303 s_lay = (h(i,j,k)*tv%S(i,j,k) + h(i+1,j,k)*tv%S(i+1,j,k)) * i_2hlay
1304 ghprime = g_h_rho0 * (dr_dt(i) * (t_lay*htot(i) - thtot(i)) + &
1305 dr_ds(i) * (s_lay*htot(i) - shtot(i)))
1307 ghprime = g_h_rho0 * (gv%Rlay(k)*htot(i) - rhtot(i))
1310 if (ghprime > 0.0)
then 1311 ribulk = cs%bulk_Ri_ML * exp(-htot(i) * idecay_len_tke(i))
1312 if (ribulk * uh2 <= (htot(i)**2) * ghprime)
then 1313 visc%nkml_visc_u(i,j) =
real(k_massive(i))
1315 elseif (ribulk * uh2 <= (htot(i) + hlay)**2 * ghprime)
then 1316 visc%nkml_visc_u(i,j) =
real(k-1) + &
1317 ( sqrt(ribulk * uh2 / ghprime) - htot(i) ) / hlay
1324 if (do_i(i)) do_any = .true.
1327 if (.not.do_any)
exit 1330 do i=isq,ieq ;
if (do_i(i))
then 1331 htot(i) = htot(i) + 0.5 * (h(i,j,k) + h(i+1,j,k))
1332 uhtot(i) = uhtot(i) + 0.5 * (h(i,j,k) + h(i+1,j,k)) * u(i,j,k)
1333 vhtot(i) = vhtot(i) + 0.25 * (h(i,j,k) * (v(i,j,k) + v(i,j-1,k)) + &
1334 h(i+1,j,k) * (v(i+1,j,k) + v(i+1,j-1,k)))
1336 thtot(i) = thtot(i) + 0.5 * (h(i,j,k)*tv%T(i,j,k) + h(i+1,j,k)*tv%T(i+1,j,k))
1337 shtot(i) = shtot(i) + 0.5 * (h(i,j,k)*tv%S(i,j,k) + h(i+1,j,k)*tv%S(i+1,j,k))
1339 rhtot(i) = rhtot(i) + 0.5 * (h(i,j,k) + h(i+1,j,k)) * gv%Rlay(k)
1344 if (do_any)
then ;
do i=isq,ieq ;
if (do_i(i))
then 1345 visc%nkml_visc_u(i,j) = k_massive(i)
1346 endif ;
enddo ;
endif 1349 do_any_shelf = .false.
1350 if (
associated(fluxes%frac_shelf_h))
then 1352 if (fluxes%frac_shelf_u(i,j)*g%mask2dCu(i,j) == 0.0)
then 1354 visc%tbl_thick_shelf_u(i,j) = 0.0 ; visc%kv_tbl_shelf_u(i,j) = 0.0
1356 do_i(i) = .true. ; do_any_shelf = .true.
1361 if (do_any_shelf)
then 1362 do k=1,nz ;
do i=isq,ieq ;
if (do_i(i))
then 1363 if (u(i,j,k) *(h(i+1,j,k) - h(i,j,k)) >= 0)
then 1364 h_at_vel(i,k) = 2.0*h(i,j,k)*h(i+1,j,k) / &
1365 (h(i,j,k) + h(i+1,j,k) + h_neglect)
1367 h_at_vel(i,k) = 0.5 * (h(i,j,k) + h(i+1,j,k))
1370 h_at_vel(i,k) = 0.0 ; ustar(i) = 0.0
1371 endif ;
enddo ;
enddo 1373 do i=isq,ieq ;
if (do_i(i))
then 1374 htot_vel = 0.0 ; hwtot = 0.0 ; hutot = 0.0
1375 thtot(i) = 0.0 ; shtot(i) = 0.0
1376 if (use_eos .or. .not.cs%linear_drag)
then ;
do k=1,nz
1377 if (htot_vel>=cs%Htbl_shelf)
exit 1378 hweight = min(cs%Htbl_shelf - htot_vel, h_at_vel(i,k))
1379 if (hweight <= 1.5*gv%Angstrom + h_neglect) cycle
1381 htot_vel = htot_vel + h_at_vel(i,k)
1382 hwtot = hwtot + hweight
1384 if (.not.cs%linear_drag)
then 1385 v_at_u = set_v_at_u(v, h, g, i, j, k, mask_v)
1386 hutot = hutot + hweight * sqrt(u(i,j,k)**2 + &
1387 v_at_u**2 + u_bg_sq)
1390 thtot(i) = thtot(i) + hweight * 0.5 * (tv%T(i,j,k) + tv%T(i+1,j,k))
1391 shtot(i) = shtot(i) + hweight * 0.5 * (tv%S(i,j,k) + tv%S(i+1,j,k))
1395 if ((.not.cs%linear_drag) .and. (hwtot > 0.0))
then 1396 ustar(i) = cdrag_sqrt*hutot/hwtot
1398 ustar(i) = cdrag_sqrt*cs%drag_bg_vel
1401 if (use_eos)
then ;
if (hwtot > 0.0)
then 1402 t_eos(i) = thtot(i)/hwtot ; s_eos(i) = shtot(i)/hwtot
1404 t_eos(i) = 0.0 ; s_eos(i) = 0.0
1409 call calculate_density_derivs(t_eos, s_eos, fluxes%p_surf(:,j), &
1410 dr_dt, dr_ds, isq-g%IsdB+1, ieq-isq+1, tv%eqn_of_state)
1413 do i=isq,ieq ;
if (do_i(i))
then 1416 ustarsq = rho0x400_g * ustar(i)**2
1419 thtot(i) = 0.0 ; shtot(i) = 0.0
1421 if (h_at_vel(i,k) <= 0.0) cycle
1422 t_lay = 0.5 * (tv%T(i,j,k) + tv%T(i+1,j,k))
1423 s_lay = 0.5 * (tv%S(i,j,k) + tv%S(i+1,j,k))
1424 oldfn = dr_dt(i)*(t_lay*htot(i) - thtot(i)) + dr_ds(i)*(s_lay*htot(i) - shtot(i))
1425 if (oldfn >= ustarsq)
exit 1427 dfn = (dr_dt(i)*(0.5*(tv%T(i,j,k+1)+tv%T(i+1,j,k+1)) - t_lay) + &
1428 dr_ds(i)*(0.5*(tv%S(i,j,k+1)+tv%S(i+1,j,k+1)) - s_lay)) * &
1429 (h_at_vel(i,k)+htot(i))
1430 if ((oldfn + dfn) <= ustarsq)
then 1433 dh = h_at_vel(i,k) * sqrt((ustarsq-oldfn)/dfn)
1436 htot(i) = htot(i) + dh
1437 thtot(i) = thtot(i) + t_lay*dh ; shtot(i) = shtot(i) + s_lay*dh
1439 if ((oldfn < ustarsq) .and. (h_at_vel(i,nz) > 0.0))
then 1440 t_lay = 0.5*(tv%T(i,j,nz) + tv%T(i+1,j,nz))
1441 s_lay = 0.5*(tv%S(i,j,nz) + tv%S(i+1,j,nz))
1442 if (dr_dt(i)*(t_lay*htot(i) - thtot(i)) + &
1443 dr_ds(i)*(s_lay*htot(i) - shtot(i)) < ustarsq) &
1444 htot(i) = htot(i) + h_at_vel(i,nz)
1449 rlay = gv%Rlay(k) ; rlb = gv%Rlay(k+1)
1451 oldfn = rlay*htot(i) - rhtot(i)
1452 if (oldfn >= ustarsq)
exit 1454 dfn = (rlb - rlay)*(h_at_vel(i,k)+htot(i))
1455 if ((oldfn + dfn) <= ustarsq)
then 1458 dh = h_at_vel(i,k) * sqrt((ustarsq-oldfn)/dfn)
1461 htot(i) = htot(i) + dh
1462 rhtot(i) = rhtot(i) + rlay*dh
1464 if (gv%Rlay(nz)*htot(i) - rhtot(i) < ustarsq) &
1465 htot(i) = htot(i) + h_at_vel(i,nz)
1472 ustar1 = ustar(i)*m_to_h
1473 h2f2 = (htot(i)*(g%CoriolisBu(i,j-1)+g%CoriolisBu(i,j)) + h_neglect*cs%Omega)**2
1474 visc%tbl_thick_shelf_u(i,j) = max(cs%Htbl_shelf_min, &
1475 ( htot(i)*ustar1 ) / ( 0.5*ustar1 + sqrt((0.5*ustar1)**2 + h2f2 ) ) )
1476 visc%kv_tbl_shelf_u(i,j) = max(cs%KV_TBL_min, &
1477 cdrag_sqrt*ustar(i)*visc%tbl_thick_shelf_u(i,j))
1495 if (cs%dynamic_viscous_ML)
then 1499 if (g%mask2dCv(i,j) < 0.5)
then 1500 do_i(i) = .false. ; visc%nkml_visc_v(i,j) = nkml
1502 do_i(i) = .true. ; do_any = .true.
1504 thtot(i) = 0.0 ; shtot(i) = 0.0 ; rhtot(i) = 0.0
1505 vhtot(i) = dt_rho0 * fluxes%tauy(i,j)
1506 uhtot(i) = 0.25 * dt_rho0 * ((fluxes%taux(i,j) + fluxes%taux(i-1,j+1)) + &
1507 (fluxes%taux(i-1,j) + fluxes%taux(i,j+1)))
1509 if (cs%omega_frac >= 1.0)
then ; absf = 2.0*cs%omega ;
else 1510 absf = 0.5*(abs(g%CoriolisBu(i-1,j)) + abs(g%CoriolisBu(i,j)))
1511 if (cs%omega_frac > 0.0) &
1512 absf = sqrt(cs%omega_frac*4.0*cs%omega**2 + (1.0-cs%omega_frac)*absf**2)
1515 u_star = max(cs%ustar_min, 0.5 * (fluxes%ustar(i,j) + fluxes%ustar(i,j+1)))
1516 idecay_len_tke(i) = ((absf / u_star) * cs%TKE_decay) * h_to_m
1521 if (do_any)
then ;
do k=1,nz
1524 if (use_eos .and. (k==nkml+1))
then 1527 press(i) = gv%H_to_Pa * htot(i)
1529 i_2hlay = 1.0 / (h(i,j,k2) + h(i,j+1,k2) + h_neglect)
1530 t_eos(i) = (h(i,j,k2)*tv%T(i,j,k2) + h(i,j+1,k2)*tv%T(i,j+1,k2)) * i_2hlay
1531 s_eos(i) = (h(i,j,k2)*tv%S(i,j,k2) + h(i,j+1,k2)*tv%S(i,j+1,k2)) * i_2hlay
1533 call calculate_density_derivs(t_eos, s_eos, press, dr_dt, dr_ds, &
1534 is-g%IsdB+1, ie-is+1, tv%eqn_of_state)
1537 do i=is,ie ;
if (do_i(i))
then 1539 hlay = 0.5*(h(i,j,k) + h(i,j+1,k))
1540 if (hlay > h_tiny)
then 1541 i_2hlay = 1.0 / (h(i,j,k) + h(i,j+1,k))
1542 u_at_v = 0.5 * (h(i,j,k) * (u(i-1,j,k) + u(i,j,k)) + &
1543 h(i,j+1,k) * (u(i-1,j+1,k) + u(i,j+1,k))) * i_2hlay
1544 uh2 = (uhtot(i) - htot(i)*u_at_v)**2 + (vhtot(i) - htot(i)*v(i,j,k))**2
1547 t_lay = (h(i,j,k)*tv%T(i,j,k) + h(i,j+1,k)*tv%T(i,j+1,k)) * i_2hlay
1548 s_lay = (h(i,j,k)*tv%S(i,j,k) + h(i,j+1,k)*tv%S(i,j+1,k)) * i_2hlay
1549 ghprime = g_h_rho0 * (dr_dt(i) * (t_lay*htot(i) - thtot(i)) + &
1550 dr_ds(i) * (s_lay*htot(i) - shtot(i)))
1552 ghprime = g_h_rho0 * (gv%Rlay(k)*htot(i) - rhtot(i))
1555 if (ghprime > 0.0)
then 1556 ribulk = cs%bulk_Ri_ML * exp(-htot(i) * idecay_len_tke(i))
1557 if (ribulk * uh2 <= htot(i)**2 * ghprime)
then 1558 visc%nkml_visc_v(i,j) =
real(k_massive(i))
1560 elseif (ribulk * uh2 <= (htot(i) + hlay)**2 * ghprime)
then 1561 visc%nkml_visc_v(i,j) =
real(k-1) + &
1562 ( sqrt(ribulk * uh2 / ghprime) - htot(i) ) / hlay
1569 if (do_i(i)) do_any = .true.
1572 if (.not.do_any)
exit 1575 do i=is,ie ;
if (do_i(i))
then 1576 htot(i) = htot(i) + 0.5 * (h(i,j,k) + h(i,j+1,k))
1577 vhtot(i) = vhtot(i) + 0.5 * (h(i,j,k) + h(i,j+1,k)) * v(i,j,k)
1578 uhtot(i) = uhtot(i) + 0.25 * (h(i,j,k) * (u(i-1,j,k) + u(i,j,k)) + &
1579 h(i,j+1,k) * (u(i-1,j+1,k) + u(i,j+1,k)))
1581 thtot(i) = thtot(i) + 0.5 * (h(i,j,k)*tv%T(i,j,k) + h(i,j+1,k)*tv%T(i,j+1,k))
1582 shtot(i) = shtot(i) + 0.5 * (h(i,j,k)*tv%S(i,j,k) + h(i,j+1,k)*tv%S(i,j+1,k))
1584 rhtot(i) = rhtot(i) + 0.5 * (h(i,j,k) + h(i,j+1,k)) * gv%Rlay(k)
1589 if (do_any)
then ;
do i=is,ie ;
if (do_i(i))
then 1590 visc%nkml_visc_v(i,j) = k_massive(i)
1591 endif ;
enddo ;
endif 1594 do_any_shelf = .false.
1595 if (
associated(fluxes%frac_shelf_h))
then 1597 if (fluxes%frac_shelf_v(i,j)*g%mask2dCv(i,j) == 0.0)
then 1599 visc%tbl_thick_shelf_v(i,j) = 0.0 ; visc%kv_tbl_shelf_v(i,j) = 0.0
1601 do_i(i) = .true. ; do_any_shelf = .true.
1606 if (do_any_shelf)
then 1607 do k=1,nz ;
do i=is,ie ;
if (do_i(i))
then 1608 if (v(i,j,k) * (h(i,j+1,k) - h(i,j,k)) >= 0)
then 1609 h_at_vel(i,k) = 2.0*h(i,j,k)*h(i,j+1,k) / &
1610 (h(i,j,k) + h(i,j+1,k) + h_neglect)
1612 h_at_vel(i,k) = 0.5 * (h(i,j,k) + h(i,j+1,k))
1615 h_at_vel(i,k) = 0.0 ; ustar(i) = 0.0
1616 endif ;
enddo ;
enddo 1618 do i=is,ie ;
if (do_i(i))
then 1619 htot_vel = 0.0 ; hwtot = 0.0 ; hutot = 0.0
1620 thtot(i) = 0.0 ; shtot(i) = 0.0
1621 if (use_eos .or. .not.cs%linear_drag)
then ;
do k=1,nz
1622 if (htot_vel>=cs%Htbl_shelf)
exit 1623 hweight = min(cs%Htbl_shelf - htot_vel, h_at_vel(i,k))
1624 if (hweight <= 1.5*gv%Angstrom + h_neglect) cycle
1626 htot_vel = htot_vel + h_at_vel(i,k)
1627 hwtot = hwtot + hweight
1629 if (.not.cs%linear_drag)
then 1630 u_at_v = set_u_at_v(u, h, g, i, j, k, mask_u)
1631 hutot = hutot + hweight * sqrt(v(i,j,k)**2 + &
1632 u_at_v**2 + u_bg_sq)
1635 thtot(i) = thtot(i) + hweight * 0.5 * (tv%T(i,j,k) + tv%T(i,j+1,k))
1636 shtot(i) = shtot(i) + hweight * 0.5 * (tv%S(i,j,k) + tv%S(i,j+1,k))
1640 if (.not.cs%linear_drag)
then ;
if (hwtot > 0.0)
then 1641 ustar(i) = cdrag_sqrt*hutot/hwtot
1643 ustar(i) = cdrag_sqrt*cs%drag_bg_vel
1646 if (use_eos)
then ;
if (hwtot > 0.0)
then 1647 t_eos(i) = thtot(i)/hwtot ; s_eos(i) = shtot(i)/hwtot
1649 t_eos(i) = 0.0 ; s_eos(i) = 0.0
1654 call calculate_density_derivs(t_eos, s_eos, fluxes%p_surf(:,j), &
1655 dr_dt, dr_ds, is-g%IsdB+1, ie-is+1, tv%eqn_of_state)
1658 do i=is,ie ;
if (do_i(i))
then 1661 ustarsq = rho0x400_g * ustar(i)**2
1664 thtot(i) = 0.0 ; shtot(i) = 0.0
1666 if (h_at_vel(i,k) <= 0.0) cycle
1667 t_lay = 0.5 * (tv%T(i,j,k) + tv%T(i,j+1,k))
1668 s_lay = 0.5 * (tv%S(i,j,k) + tv%S(i,j+1,k))
1669 oldfn = dr_dt(i)*(t_lay*htot(i) - thtot(i)) + dr_ds(i)*(s_lay*htot(i) - shtot(i))
1670 if (oldfn >= ustarsq)
exit 1672 dfn = (dr_dt(i)*(0.5*(tv%T(i,j,k+1)+tv%T(i,j+1,k+1)) - t_lay) + &
1673 dr_ds(i)*(0.5*(tv%S(i,j,k+1)+tv%S(i,j+1,k+1)) - s_lay)) * &
1674 (h_at_vel(i,k)+htot(i))
1675 if ((oldfn + dfn) <= ustarsq)
then 1678 dh = h_at_vel(i,k) * sqrt((ustarsq-oldfn)/dfn)
1681 htot(i) = htot(i) + dh
1682 thtot(i) = thtot(i) + t_lay*dh ; shtot(i) = shtot(i) + s_lay*dh
1684 if ((oldfn < ustarsq) .and. (h_at_vel(i,nz) > 0.0))
then 1685 t_lay = 0.5*(tv%T(i,j,nz) + tv%T(i,j+1,nz))
1686 s_lay = 0.5*(tv%S(i,j,nz) + tv%S(i,j+1,nz))
1687 if (dr_dt(i)*(t_lay*htot(i) - thtot(i)) + &
1688 dr_ds(i)*(s_lay*htot(i) - shtot(i)) < ustarsq) &
1689 htot(i) = htot(i) + h_at_vel(i,nz)
1694 rlay = gv%Rlay(k) ; rlb = gv%Rlay(k+1)
1696 oldfn = rlay*htot(i) - rhtot(i)
1697 if (oldfn >= ustarsq)
exit 1699 dfn = (rlb - rlay)*(h_at_vel(i,k)+htot(i))
1700 if ((oldfn + dfn) <= ustarsq)
then 1703 dh = h_at_vel(i,k) * sqrt((ustarsq-oldfn)/dfn)
1706 htot(i) = htot(i) + dh
1707 rhtot = rhtot + rlay*dh
1709 if (gv%Rlay(nz)*htot(i) - rhtot(i) < ustarsq) &
1710 htot(i) = htot(i) + h_at_vel(i,nz)
1717 ustar1 = ustar(i)*m_to_h
1718 h2f2 = (htot(i)*(g%CoriolisBu(i-1,j)+g%CoriolisBu(i,j)) + h_neglect*cs%Omega)**2
1719 visc%tbl_thick_shelf_v(i,j) = max(cs%Htbl_shelf_min, &
1720 ( htot(i)*ustar1 ) / ( 0.5*ustar1 + sqrt((0.5*ustar1)**2 + h2f2 ) ) )
1721 visc%kv_tbl_shelf_v(i,j) = max(cs%KV_TBL_min, &
1722 cdrag_sqrt*ustar(i)*visc%tbl_thick_shelf_v(i,j))
1729 if (
associated(visc%nkml_visc_u) .and.
associated(visc%nkml_visc_v)) &
1730 call uvchksum(
"nkml_visc_[uv]", visc%nkml_visc_u, &
1731 visc%nkml_visc_v, g%HI,haloshift=0)
1733 if (cs%id_nkml_visc_u > 0) &
1734 call post_data(cs%id_nkml_visc_u, visc%nkml_visc_u, cs%diag)
1735 if (cs%id_nkml_visc_v > 0) &
1736 call post_data(cs%id_nkml_visc_v, visc%nkml_visc_v, cs%diag)
Ocean grid type. See mom_grid for details.