Skip to content

Commit 91823f6

Browse files
authored
Mask on/off for StochasticStirring
1 parent cd1bc10 commit 91823f6

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/stochastic_stirring.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Base.@kwdef struct StochasticStirring{NF} <: SpeedyWeather.AbstractForcing
2323
"Stirring latitude [˚N]"
2424
latitude::NF = 45
2525

26+
"En/disable stirring mask"
27+
mask::Bool = true
28+
2629
"Stirring width [˚]"
2730
width::NF = 24
2831

@@ -81,12 +84,13 @@ function SpeedyWeather.initialize!( forcing::StochasticStirring,
8184
forcing.a[] = A*sqrt(1 - exp(-2dt/τ))
8285
forcing.b[] = exp(-dt/τ)
8386

84-
# precompute the Gaussian latitudinal mask
85-
(;latd) = model.geometry # in ˚N on every latitude ring
86-
87-
for j in eachindex(forcing.lat_mask)
88-
# Gaussian centred at forcing.latitude of width forcing.width
89-
forcing.lat_mask[j] = exp(-(forcing.latitude-latd[j])^2/forcing.width^2*2)
87+
if forcing.mask
88+
# precompute the Gaussian latitudinal mask
89+
(;latd) = model.geometry # in ˚N on every latitude ring
90+
for j in eachindex(forcing.lat_mask)
91+
# Gaussian centred at forcing.latitude of width forcing.width
92+
forcing.lat_mask[j] = exp(-(forcing.latitude-latd[j])^2/forcing.width^2*2)
93+
end
9094
end
9195

9296
return nothing
@@ -134,16 +138,20 @@ function SpeedyWeather.forcing!(
134138
end
135139
end
136140

137-
# to grid-point space
138-
S_grid = diagn.dynamics_variables.a_grid # reuse general work array
139-
SpeedyTransforms.gridded!(S_grid, S, spectral_transform)
140-
141-
# mask everything but mid-latitudes
142-
RingGrids._scale_lat!(S_grid, forcing.lat_mask)
143-
144-
# back to spectral space, write directly into vorticity tendency
145-
(; vor_tend) = diagn.tendencies
146-
SpeedyTransforms.spectral!(vor_tend, S_grid, spectral_transform)
147-
141+
if forcing.mask
142+
# to grid-point space
143+
S_grid = diagn.dynamics_variables.a_grid # reuse general work array
144+
SpeedyTransforms.gridded!(S_grid, S, spectral_transform)
145+
146+
# mask everything but mid-latitudes
147+
RingGrids._scale_lat!(S_grid, forcing.lat_mask)
148+
149+
# back to spectral space, write directly into vorticity tendency
150+
(; vor_tend) = diagn.tendencies
151+
SpeedyTransforms.spectral!(vor_tend, S_grid, spectral_transform)
152+
else
153+
vor_tend .= S # copy forcing S over into vor_tend
154+
end
155+
148156
return nothing
149157
end

0 commit comments

Comments
 (0)