This subroutine determines the internal wave velocity structure for any mode.
This subroutine solves for the eigen vector [vertical structure, e(k)] associated with the first baroclinic mode speed [i.e., smallest eigen value (lam = 1/c^2)] of the system d2e/dz2 = -(N2/cn2)e, or (A-lam*I)e = 0, where A = -(1/N2)(d2/dz2), lam = 1/c^2, and I is the identity matrix. 2nd order discretization in the vertical lets this system be represented as
(Igu(2)+Igl(2)-lam)*e(2) - Igl(2)*e(3) = 0.0 -Igu(nz)*e(nz-1) + (Igu(nz)+Igl(nz)-lam)*e(nz) = 0.0
where, upon noting N2 = reduced gravity/layer thickness, we get Igl(k) = 1.0/(gprime(k)*H(k)) ; Igu(k) = 1.0/(gprime(k)*H(k-1))
The eigen value for this system is approximated using "wave_speed." This subroutine uses these eigen values (mode speeds) to estimate the corresponding eigen vectors (velocity structure) using the "inverse iteration with shift" method. The algorithm is
Pick a starting vector reasonably close to mode structure and with unit magnitude, b_guess For n=1,2,3,... Solve (A-lam*I)e = e_guess for e Set e_guess=e/|e| and repeat, with each iteration refining the estimate of e
92 type(ocean_grid_type),
intent(in) :: G
93 type(verticalGrid_type),
intent(in) :: GV
94 type(unit_scale_type),
intent(in) :: US
95 real,
dimension(SZI_(G),SZJ_(G),SZK_(G)),
intent(in) :: h
96 type(thermo_var_ptrs),
intent(in) :: tv
98 real,
dimension(SZI_(G),SZJ_(G)),
intent(in) :: cn
100 integer,
intent(in) :: ModeNum
101 real,
intent(in) :: freq
102 type(wave_structure_CS),
pointer :: CS
104 real,
dimension(SZI_(G),SZJ_(G)), &
105 optional,
intent(in) :: En
106 logical,
optional,
intent(in) :: full_halos
109 real,
dimension(SZK_(G)+1) :: &
111 pres, T_int, S_int, &
113 real,
dimension(SZK_(G)) :: &
116 real,
dimension(SZK_(G),SZI_(G)) :: &
118 real,
dimension(SZK_(G)) :: &
121 real,
dimension(SZI_(G),SZJ_(G)) :: &
126 real,
dimension(SZI_(G)) :: &
128 H_here, HxT_here, HxS_here, HxR_here
130 real :: I_Hnew, drxh_sum
131 real,
parameter :: tol1 = 0.0001, tol2 = 0.001
132 real,
pointer,
dimension(:,:,:) :: T => null(), s => null()
134 real :: rescale, I_rescale
135 integer :: kf(SZI_(G))
136 integer,
parameter :: max_itt = 1
137 real,
parameter :: cg_subRO = 1e-100
138 real,
parameter :: a_int = 0.5
144 real,
dimension(SZK_(G)+1) :: w_strct, u_strct, W_profile, Uavg_profile, z_int, N2
147 real,
dimension(SZK_(G)+1) :: w_strct2, u_strct2
149 real,
dimension(SZK_(G)) :: dz
150 real,
dimension(SZK_(G)+1) :: dWdz_profile
152 real :: int_dwdz2, int_w2, int_N2w2, KE_term, PE_term, W0
155 real,
dimension(SZK_(G)-1) :: lam_z
157 real,
dimension(SZK_(G)-1) :: a_diag, b_diag, c_diag
160 real,
dimension(SZK_(G)-1) :: e_guess
161 real,
dimension(SZK_(G)-1) :: e_itt
164 integer :: i, j, k, k2, itt, is, ie, js, je, nz, nzm, row, ig, jg, ig_stop, jg_stop
166 is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
170 if (.not.
associated(cs))
call mom_error(fatal,
"MOM_wave_structure: "// &
171 "Module must be initialized before it is used.")
174 if (
present(full_halos))
then ;
if (full_halos)
then
175 is = g%isd ; ie = g%ied ; js = g%jsd ; je = g%jed
180 s => tv%S ; t => tv%T
181 g_rho0 = us%L_T_to_m_s**2 * gv%g_Earth /gv%Rho0
182 use_eos =
associated(tv%eqn_of_state)
184 h_to_pres = gv%Z_to_H*gv%H_to_Pa
185 rescale = 1024.0**4 ; i_rescale = 1.0/rescale
187 min_h_frac = tol1 / real(nz)
193 do i=is,ie ; htot(i,j) = 0.0 ;
enddo
194 do k=1,nz ;
do i=is,ie ; htot(i,j) = htot(i,j) + h(i,j,k)*gv%H_to_Z ;
enddo ;
enddo
197 hmin(i) = htot(i,j)*min_h_frac ; kf(i) = 1 ; h_here(i) = 0.0
198 hxt_here(i) = 0.0 ; hxs_here(i) = 0.0 ; hxr_here(i) = 0.0
201 do k=1,nz ;
do i=is,ie
202 if ((h_here(i) > hmin(i)) .and. (h(i,j,k)*gv%H_to_Z > hmin(i)))
then
203 hf(kf(i),i) = h_here(i)
204 tf(kf(i),i) = hxt_here(i) / h_here(i)
205 sf(kf(i),i) = hxs_here(i) / h_here(i)
209 h_here(i) = h(i,j,k)*gv%H_to_Z
210 hxt_here(i) = (h(i,j,k)*gv%H_to_Z)*t(i,j,k)
211 hxs_here(i) = (h(i,j,k)*gv%H_to_Z)*s(i,j,k)
213 h_here(i) = h_here(i) + h(i,j,k)*gv%H_to_Z
214 hxt_here(i) = hxt_here(i) + (h(i,j,k)*gv%H_to_Z)*t(i,j,k)
215 hxs_here(i) = hxs_here(i) + (h(i,j,k)*gv%H_to_Z)*s(i,j,k)
218 do i=is,ie ;
if (h_here(i) > 0.0)
then
219 hf(kf(i),i) = h_here(i)
220 tf(kf(i),i) = hxt_here(i) / h_here(i)
221 sf(kf(i),i) = hxs_here(i) / h_here(i)
224 do k=1,nz ;
do i=is,ie
225 if ((h_here(i) > hmin(i)) .and. (h(i,j,k)*gv%H_to_Z > hmin(i)))
then
226 hf(kf(i),i) = h_here(i) ; rf(kf(i),i) = hxr_here(i) / h_here(i)
230 h_here(i) = h(i,j,k)*gv%H_to_Z
231 hxr_here(i) = (h(i,j,k)*gv%H_to_Z)*gv%Rlay(k)
233 h_here(i) = h_here(i) + h(i,j,k)*gv%H_to_Z
234 hxr_here(i) = hxr_here(i) + (h(i,j,k)*gv%H_to_Z)*gv%Rlay(k)
237 do i=is,ie ;
if (h_here(i) > 0.0)
then
238 hf(kf(i),i) = h_here(i) ; rf(kf(i),i) = hxr_here(i) / h_here(i)
244 do i=is,ie ;
if (cn(i,j)>0.0)
then
246 ig = i + g%idg_offset ; jg = j + g%jdg_offset
249 if (g%mask2dT(i,j) > 0.5)
then
257 pres(k) = pres(k-1) + h_to_pres*hf(k-1,i)
258 t_int(k) = 0.5*(tf(k,i)+tf(k-1,i))
259 s_int(k) = 0.5*(sf(k,i)+sf(k-1,i))
261 call calculate_density_derivs(t_int, s_int, pres, drho_dt, drho_ds, 2, &
262 kf(i)-1, tv%eqn_of_state)
268 drxh_sum = drxh_sum + 0.5*(hf(k-1,i)+hf(k,i)) * &
269 max(0.0,drho_dt(k)*(tf(k,i)-tf(k-1,i)) + &
270 drho_ds(k)*(sf(k,i)-sf(k-1,i)))
275 drxh_sum = drxh_sum + 0.5*(hf(k-1,i)+hf(k,i)) * &
276 max(0.0,rf(k,i)-rf(k-1,i))
282 if (drxh_sum >= 0.0)
then
287 hc(1) = hf(1,i) ; tc(1) = tf(1,i) ; sc(1) = sf(1,i)
289 if ((drho_dt(k)*(tf(k,i)-tc(kc)) + drho_ds(k)*(sf(k,i)-sc(kc))) * &
290 (hc(kc) + hf(k,i)) < 2.0 * tol2*drxh_sum)
then
292 i_hnew = 1.0 / (hc(kc) + hf(k,i))
293 tc(kc) = (hc(kc)*tc(kc) + hf(k,i)*tf(k,i)) * i_hnew
294 sc(kc) = (hc(kc)*sc(kc) + hf(k,i)*sf(k,i)) * i_hnew
295 hc(kc) = (hc(kc) + hf(k,i))
300 if ((drho_dt(k2)*(tc(k2)-tc(k2-1)) + drho_ds(k2)*(sc(k2)-sc(k2-1))) * &
301 (hc(k2) + hc(k2-1)) < tol2*drxh_sum)
then
303 i_hnew = 1.0 / (hc(kc) + hc(kc-1))
304 tc(kc-1) = (hc(kc)*tc(kc) + hc(kc-1)*tc(kc-1)) * i_hnew
305 sc(kc-1) = (hc(kc)*sc(kc) + hc(kc-1)*sc(kc-1)) * i_hnew
306 hc(kc-1) = (hc(kc) + hc(kc-1))
313 drho_ds(kc) = drho_ds(k) ; drho_dt(kc) = drho_dt(k)
314 tc(kc) = tf(k,i) ; sc(kc) = sf(k,i) ; hc(kc) = hf(k,i)
319 gprime(k) = g_rho0 * (drho_dt(k)*(tc(k)-tc(k-1)) + &
320 drho_ds(k)*(sc(k)-sc(k-1)))
325 hc(1) = hf(1,i) ; rc(1) = rf(1,i)
327 if ((rf(k,i) - rc(kc)) * (hc(kc) + hf(k,i)) < 2.0*tol2*drxh_sum)
then
329 rc(kc) = (hc(kc)*rc(kc) + hf(k,i)*rf(k,i)) / (hc(kc) + hf(k,i))
330 hc(kc) = (hc(kc) + hf(k,i))
335 if ((rc(k2)-rc(k2-1)) * (hc(k2)+hc(k2-1)) < tol2*drxh_sum)
then
337 rc(kc-1) = (hc(kc)*rc(kc) + hc(kc-1)*rc(kc-1)) / (hc(kc) + hc(kc-1))
338 hc(kc-1) = (hc(kc) + hc(kc-1))
345 rc(kc) = rf(k,i) ; hc(kc) = hf(k,i)
350 gprime(k) = g_rho0 * (rc(k)-rc(k-1))
362 if (kc >= modenum + 1)
then
368 igl(k) = 1.0/(gprime(k)*hc(k)) ; igu(k) = 1.0/(gprime(k)*hc(k-1))
369 z_int(k) = z_int(k-1) + hc(k-1)
370 n2(k) = us%m_to_Z**2*gprime(k)/(0.5*(hc(k)+hc(k-1)))
373 n2(1) = n2(2) ; n2(kc+1) = n2(kc)
375 z_int(kc+1) = z_int(kc)+hc(kc)
377 if (abs(z_int(kc+1)-htot(i,j)) > 1.e-14*htot(i,j))
then
378 call mom_error(fatal,
"wave_structure: mismatch in total depths")
391 gp_unscaled = us%m_to_Z*gprime(k)
392 lam_z(row) = lam*gp_unscaled
393 a_diag(row) = gp_unscaled*(-igu(k))
394 b_diag(row) = gp_unscaled*(igu(k)+igl(k)) - lam_z(row)
395 c_diag(row) = gp_unscaled*(-igl(k))
396 if (isnan(lam_z(row)))
then ; print *,
"Wave_structure: lam_z(row) is NAN" ;
endif
397 if (isnan(a_diag(row)))
then ; print *,
"Wave_structure: a(k) is NAN" ;
endif
398 if (isnan(b_diag(row)))
then ; print *,
"Wave_structure: b(k) is NAN" ;
endif
399 if (isnan(c_diag(row)))
then ; print *,
"Wave_structure: c(k) is NAN" ;
endif
403 gp_unscaled = us%m_to_Z*gprime(k)
404 lam_z(row) = lam*gp_unscaled
406 b_diag(row) = gp_unscaled*(igu(k)+igl(k)) - lam_z(row)
407 c_diag(row) = gp_unscaled*(-igl(k))
410 gp_unscaled = us%m_to_Z*gprime(k)
411 lam_z(row) = lam*gp_unscaled
412 a_diag(row) = gp_unscaled*(-igu(k))
413 b_diag(row) = gp_unscaled*(igu(k)+igl(k)) - lam_z(row)
417 e_guess(1:kc-1) = sin((z_int(2:kc)/htot(i,j)) *pi)
418 e_guess(1:kc-1) = e_guess(1:kc-1)/sqrt(sum(e_guess(1:kc-1)**2))
422 call tridiag_solver(a_diag(1:kc-1),b_diag(1:kc-1),c_diag(1:kc-1), &
423 -lam_z(1:kc-1),e_guess(1:kc-1),
"TDMA_H",e_itt)
424 e_guess(1:kc-1) = e_itt(1:kc-1)/sqrt(sum(e_itt(1:kc-1)**2))
426 w_strct(2:kc) = e_guess(1:kc-1)
431 ig_stop = 0 ; jg_stop = 0
432 if (isnan(sum(w_strct(1:kc+1))))
then
433 print *,
"Wave_structure: w_strct has a NAN at ig=", ig,
", jg=", jg
434 if (i<g%isc .or. i>g%iec .or. j<g%jsc .or. j>g%jec)
then
435 print *,
"This is occuring at a halo point."
437 ig_stop = ig ; jg_stop = jg
446 dz(k) = us%Z_to_m*hc(k)
447 w2avg = w2avg + 0.5*(w_strct(k)**2+w_strct(k+1)**2)*dz(k)
450 w2avg = w2avg / htot(i,j)
451 w_strct = w_strct / sqrt(htot(i,j)*w2avg*i_a_int)
455 u_strct(k) = 0.5*((w_strct(k-1) - w_strct(k) )/dz(k-1) + &
456 (w_strct(k) - w_strct(k+1))/dz(k))
458 u_strct(1) = (w_strct(1) - w_strct(2) )/dz(1)
459 u_strct(nzm) = (w_strct(nzm-1)- w_strct(nzm))/dz(nzm-1)
462 f2 = us%s_to_T**2 * g%CoriolisBu(i,j)**2
465 kmag2 = (freq**2 - f2) / (cn(i,j)**2 + cg_subro**2)
468 int_dwdz2 = 0.0 ; int_w2 = 0.0 ; int_n2w2 = 0.0
469 u_strct2 = u_strct(1:nzm)**2
470 w_strct2 = w_strct(1:nzm)**2
473 int_dwdz2 = int_dwdz2 + 0.5*(u_strct2(k)+u_strct2(k+1))*dz(k)
474 int_w2 = int_w2 + 0.5*(w_strct2(k)+w_strct2(k+1))*dz(k)
475 int_n2w2 = int_n2w2 + 0.5*(w_strct2(k)*n2(k)+w_strct2(k+1)*n2(k+1))*dz(k)
479 if (kmag2 > 0.0)
then
480 ke_term = 0.25*gv%Rho0*( (1+f2/freq**2)/kmag2*int_dwdz2 + int_w2 )
481 pe_term = 0.25*gv%Rho0*( int_n2w2/freq**2 )
482 if (en(i,j) >= 0.0)
then
483 w0 = sqrt( en(i,j)/(ke_term + pe_term) )
485 call mom_error(warning,
"wave_structure: En < 0.0; setting to W0 to 0.0")
486 print *,
"En(i,j)=", en(i,j),
" at ig=", ig,
", jg=", jg
490 w_profile = w0*w_strct
491 dwdz_profile = w0*u_strct
493 uavg_profile = abs(dwdz_profile) * sqrt((1+f2/freq**2)/(2.0*kmag2))
501 cs%w_strct(i,j,1:nzm) = w_strct(:)
502 cs%u_strct(i,j,1:nzm) = u_strct(:)
503 cs%W_profile(i,j,1:nzm) = w_profile(:)
504 cs%Uavg_profile(i,j,1:nzm)= uavg_profile(:)
505 cs%z_depths(i,j,1:nzm) = us%Z_to_m*z_int(:)
506 cs%N2(i,j,1:nzm) = n2(:)
507 cs%num_intfaces(i,j) = nzm
511 cs%w_strct(i,j,1:nzm) = 0.0
512 cs%u_strct(i,j,1:nzm) = 0.0
513 cs%W_profile(i,j,1:nzm) = 0.0
514 cs%Uavg_profile(i,j,1:nzm)= 0.0
515 cs%z_depths(i,j,1:nzm) = 0.0
516 cs%N2(i,j,1:nzm) = 0.0
517 cs%num_intfaces(i,j) = nzm
527 cs%w_strct(i,j,1:nzm) = 0.0
528 cs%u_strct(i,j,1:nzm) = 0.0
529 cs%W_profile(i,j,1:nzm) = 0.0
530 cs%Uavg_profile(i,j,1:nzm)= 0.0
531 cs%z_depths(i,j,1:nzm) = 0.0
532 cs%N2(i,j,1:nzm) = 0.0
533 cs%num_intfaces(i,j) = nzm