Skip to content

Commit 83efb99

Browse files
c2xuHallberg-NOAA
authored andcommitted
Streaming Filter
The filters and their target frequencies are no longer hard-coded. Instead, multiple filters with tidal or arbitrary frequencies as their target frequencies can be turned on. The filter names are specified in MOM_input and must consist of two letters/numbers. If the name of a filter is the same as the name of a tidal constituent, then the corresponding tidal frequency will be used as its target frequency. Otherwise, the user must specify the target frequency by "FILTER_${FILTER_NAME}_OMEGA" in MOM_input. The restarting capability has also been implemented. Because the filtering is a point-wise operation, all variables are considered as fields, even if they are velocity components.
1 parent 54feb6f commit 83efb99

File tree

2 files changed

+181
-127
lines changed

2 files changed

+181
-127
lines changed

src/core/MOM_barotropic.F90

+30-66
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ module MOM_barotropic
2626
use MOM_restart, only : query_initialized, MOM_restart_CS
2727
use MOM_self_attr_load, only : scalar_SAL_sensitivity
2828
use MOM_self_attr_load, only : SAL_CS
29-
use MOM_streaming_filter, only : Filt_register, Filt_accum, Filter_CS
30-
use MOM_tidal_forcing, only : tidal_frequency
29+
use MOM_streaming_filter, only : Filt_register, Filt_init, Filt_accum, Filter_CS
3130
use MOM_time_manager, only : time_type, real_to_time, operator(+), operator(-)
3231
use MOM_unit_scaling, only : unit_scale_type
3332
use MOM_variables, only : BT_cont_type, alloc_bt_cont_type
@@ -250,10 +249,8 @@ module MOM_barotropic
250249
logical :: linearized_BT_PV !< If true, the PV and interface thicknesses used
251250
!! in the barotropic Coriolis calculation is time
252251
!! invariant and linearized.
253-
logical :: use_filter_m2 !< If true, apply streaming band-pass filter for detecting
254-
!! instantaneous tidal signals.
255-
logical :: use_filter_k1 !< If true, apply streaming band-pass filter for detecting
256-
!! instantaneous tidal signals.
252+
logical :: use_filter !< If true, use streaming band-pass filter to detect the
253+
!! instantaneous tidal signals in the simulation.
257254
logical :: use_wide_halos !< If true, use wide halos and march in during the
258255
!! barotropic time stepping for efficiency.
259256
logical :: clip_velocity !< If true, limit any velocity components that are
@@ -297,10 +294,8 @@ module MOM_barotropic
297294
type(hor_index_type), pointer :: debug_BT_HI => NULL() !< debugging copy of horizontal index_type
298295
type(SAL_CS), pointer :: SAL_CSp => NULL() !< Control structure for SAL
299296
type(harmonic_analysis_CS), pointer :: HA_CSp => NULL() !< Control structure for harmonic analysis
300-
type(Filter_CS) :: Filt_CS_um2, & !< Control structures for the M2 streaming filter
301-
Filt_CS_vm2, & !< Control structures for the M2 streaming filter
302-
Filt_CS_uk1, & !< Control structures for the K1 streaming filter
303-
Filt_CS_vk1 !< Control structures for the K1 streaming filter
297+
type(Filter_CS) :: Filt_CS_u, & !< Control structures for the streaming band-pass filter of ubt
298+
Filt_CS_v !< Control structures for the streaming band-pass filter of vbt
304299
logical :: module_is_initialized = .false. !< If true, module has been initialized
305300

306301
integer :: isdw !< The lower i-memory limit for the wide halo arrays.
@@ -608,8 +603,8 @@ subroutine btstep(U_in, V_in, eta_in, dt, bc_accel_u, bc_accel_v, forces, pbce,
608603
DCor_v, & ! An averaged total thickness at v points [H ~> m or kg m-2].
609604
Datv ! Basin depth at v-velocity grid points times the x-grid
610605
! spacing [H L ~> m2 or kg m-1].
611-
real, dimension(:,:), pointer :: um2, uk1, vm2, vk1
612-
! M2 and K1 velocities from the output of streaming filters [m s-1]
606+
real, dimension(:,:,:), pointer :: ufilt, vfilt
607+
! Filtered velocities from the output of streaming filters [m s-1]
613608
real, target, dimension(SZIW_(CS),SZJW_(CS)) :: &
614609
eta, & ! The barotropic free surface height anomaly or column mass
615610
! anomaly [H ~> m or kg m-2]
@@ -1598,15 +1593,11 @@ subroutine btstep(U_in, V_in, eta_in, dt, bc_accel_u, bc_accel_v, forces, pbce,
15981593
endif ; enddo ; enddo
15991594
endif
16001595

1601-
! Here is an example of how the filter equations are time stepped to determine the M2 and K1 velocities.
1602-
! The filters are initialized and registered in subroutine barotropic_init.
1603-
if (CS%use_filter_m2) then
1604-
call Filt_accum(ubt, um2, CS%Time, US, CS%Filt_CS_um2)
1605-
call Filt_accum(vbt, vm2, CS%Time, US, CS%Filt_CS_vm2)
1606-
endif
1607-
if (CS%use_filter_k1) then
1608-
call Filt_accum(ubt, uk1, CS%Time, US, CS%Filt_CS_uk1)
1609-
call Filt_accum(vbt, vk1, CS%Time, US, CS%Filt_CS_vk1)
1596+
! Note that the filtered velocities are only updated during the current predictor step,
1597+
! and are calculated using the barotropic velocity from the previous correction step.
1598+
if (CS%use_filter) then
1599+
call Filt_accum(ubt, ufilt, CS%Time, US, CS%Filt_CS_u)
1600+
call Filt_accum(vbt, vfilt, CS%Time, US, CS%Filt_CS_v)
16101601
endif
16111602

16121603
! Zero out the arrays for various time-averaged quantities.
@@ -4979,6 +4970,12 @@ subroutine barotropic_init(u, v, h, eta, Time, G, GV, US, param_file, diag, CS,
49794970
endif ! len_trim(wave_drag_file) > 0
49804971
endif ! CS%linear_wave_drag
49814972

4973+
! Initialize streaming band-pass filters
4974+
if (CS%use_filter) then
4975+
call Filt_init(param_file, US, CS%Filt_CS_u, restart_CS)
4976+
call Filt_init(param_file, US, CS%Filt_CS_v, restart_CS)
4977+
endif
4978+
49824979
CS%dtbt_fraction = 0.98 ; if (dtbt_input < 0.0) CS%dtbt_fraction = -dtbt_input
49834980

49844981
dtbt_tmp = -1.0
@@ -5263,9 +5260,8 @@ subroutine register_barotropic_restarts(HI, GV, US, param_file, CS, restart_CS)
52635260
! Local variables
52645261
type(vardesc) :: vd(3)
52655262
character(len=40) :: mdl = "MOM_barotropic" ! This module's name.
5263+
integer :: n_filters !< Number of streaming band-pass filters to be used in the simulation.
52665264
integer :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB
5267-
real :: am2, ak1 !< Bandwidth parameters of the M2 and K1 streaming filters [nondim]
5268-
real :: om2, ok1 !< Target frequencies of the M2 and K1 streaming filters [rad T-1 ~> rad s-1]
52695265

52705266
isd = HI%isd ; ied = HI%ied ; jsd = HI%jsd ; jed = HI%jed
52715267
IsdB = HI%IsdB ; IedB = HI%IedB ; JsdB = HI%JsdB ; JedB = HI%JedB
@@ -5278,33 +5274,6 @@ subroutine register_barotropic_restarts(HI, GV, US, param_file, CS, restart_CS)
52785274
"sum(u dh_dt) while also correcting for truncation errors.", &
52795275
default=.false., do_not_log=.true.)
52805276

5281-
call get_param(param_file, mdl, "STREAMING_FILTER_M2", CS%use_filter_m2, &
5282-
"If true, turn on streaming band-pass filter for detecting "//&
5283-
"instantaneous tidal signals.", default=.false.)
5284-
call get_param(param_file, mdl, "STREAMING_FILTER_K1", CS%use_filter_k1, &
5285-
"If true, turn on streaming band-pass filter for detecting "//&
5286-
"instantaneous tidal signals.", default=.false.)
5287-
call get_param(param_file, mdl, "FILTER_ALPHA_M2", am2, &
5288-
"Bandwidth parameter of the streaming filter targeting the M2 frequency. "//&
5289-
"Must be positive. To turn off filtering, set FILTER_ALPHA_M2 <= 0.0.", &
5290-
default=0.0, units="nondim", do_not_log=.not.CS%use_filter_m2)
5291-
call get_param(param_file, mdl, "FILTER_ALPHA_K1", ak1, &
5292-
"Bandwidth parameter of the streaming filter targeting the K1 frequency. "//&
5293-
"Must be positive. To turn off filtering, set FILTER_ALPHA_K1 <= 0.0.", &
5294-
default=0.0, units="nondim", do_not_log=.not.CS%use_filter_k1)
5295-
call get_param(param_file, mdl, "TIDE_M2_FREQ", om2, &
5296-
"Frequency of the M2 tidal constituent. "//&
5297-
"This is only used if TIDES and TIDE_M2"// &
5298-
" are true, or if OBC_TIDE_N_CONSTITUENTS > 0 and M2"// &
5299-
" is in OBC_TIDE_CONSTITUENTS.", units="rad s-1", default=tidal_frequency("M2"), &
5300-
scale=US%T_to_s, do_not_log=.true.)
5301-
call get_param(param_file, mdl, "TIDE_K1_FREQ", ok1, &
5302-
"Frequency of the K1 tidal constituent. "//&
5303-
"This is only used if TIDES and TIDE_K1"// &
5304-
" are true, or if OBC_TIDE_N_CONSTITUENTS > 0 and K1"// &
5305-
" is in OBC_TIDE_CONSTITUENTS.", units="rad s-1", default=tidal_frequency("K1"), &
5306-
scale=US%T_to_s, do_not_log=.true.)
5307-
53085277
ALLOC_(CS%ubtav(IsdB:IedB,jsd:jed)) ; CS%ubtav(:,:) = 0.0
53095278
ALLOC_(CS%vbtav(isd:ied,JsdB:JedB)) ; CS%vbtav(:,:) = 0.0
53105279
if (CS%gradual_BT_ICs) then
@@ -5333,22 +5302,17 @@ subroutine register_barotropic_restarts(HI, GV, US, param_file, CS, restart_CS)
53335302
call register_restart_field(CS%dtbt, "DTBT", .false., restart_CS, &
53345303
longname="Barotropic timestep", units="seconds", conversion=US%T_to_s)
53355304

5336-
! Initialize and register streaming filters
5337-
if (CS%use_filter_m2) then
5338-
if (am2 > 0.0 .and. om2 > 0.0) then
5339-
call Filt_register(am2, om2, 'u', HI, CS%Filt_CS_um2)
5340-
call Filt_register(am2, om2, 'v', HI, CS%Filt_CS_vm2)
5341-
else
5342-
CS%use_filter_m2 = .false.
5343-
endif
5344-
endif
5345-
if (CS%use_filter_k1) then
5346-
if (ak1 > 0.0 .and. ok1 > 0.0) then
5347-
call Filt_register(ak1, ok1, 'u', HI, CS%Filt_CS_uk1)
5348-
call Filt_register(ak1, ok1, 'v', HI, CS%Filt_CS_vk1)
5349-
else
5350-
CS%use_filter_k1 = .false.
5351-
endif
5305+
! Initialize and register streaming band-pass filters
5306+
call get_param(param_file, mdl, "USE_FILTER", CS%use_filter, &
5307+
"If true, use streaming band-pass filters to detect the "//&
5308+
"instantaneous tidal signals in the simulation.", default=.false.)
5309+
call get_param(param_file, mdl, "N_FILTERS", n_filters, &
5310+
"Number of streaming band-pass filters to be used in the simulation.", &
5311+
default=0, do_not_log=.not.CS%use_filter)
5312+
if (n_filters<=0) CS%use_filter = .false.
5313+
if (CS%use_filter) then
5314+
call Filt_register(n_filters, 'ubt', 'u', HI, CS%Filt_CS_u, restart_CS)
5315+
call Filt_register(n_filters, 'vbt', 'v', HI, CS%Filt_CS_v, restart_CS)
53525316
endif
53535317

53545318
end subroutine register_barotropic_restarts

0 commit comments

Comments
 (0)