Skip to content

Commit 3389143

Browse files
committed
Refactor NOGW code structure and naming
- Move `input_uv` computation out of the nk loop for improved clarity. - Consolidate multiple dispatch definitions for `non_orographic_gravity_wave_tendency`. - Rename `NonOrographyGravityWave` to `NonOrographicGravityWave` for consistency. - Recompute non-orographic gravity waves within callbacks at intervals defined by `dt_nogw`.
1 parent 95991d3 commit 3389143

File tree

9 files changed

+110
-54
lines changed

9 files changed

+110
-54
lines changed

config/default_configs/default_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ orographic_gravity_wave:
220220
non_orographic_gravity_wave:
221221
help: "Apply parameterization for convective gravity wave forcing on horizontal mean flow [`false` (default), `true`]"
222222
value: false
223+
dt_nogw:
224+
help: "Time between calling non-orographic gravity wave update"
225+
value: "400secs"
223226
nh_poly:
224227
help: "Horizontal polynomial degree. Note: The number of quadrature points in 1D within each horizontal element is then Nq = <--nh_poly> + 1"
225228
value: 3

config/model_configs/single_column_nonorographic_gravity_wave.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dt: "400secs"
77
output_default_diagnostics: true
88
disable_surface_flux_tendency: true
99
non_orographic_gravity_wave: true
10+
dt_nogw: "400secs"
1011
# diagnostics:
1112
# - short_name: [ta, rhoa]
1213
# period: 400secs

src/callbacks/callbacks.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
399399
return nothing
400400
end
401401

402+
403+
404+
NVTX.@annotate function nogw_model_callback!(integrator)
405+
Y = integrator.u
406+
p = integrator.p
407+
408+
non_orographic_gravity_wave_compute_tendency!(Y,p)
409+
end
410+
411+
402412
#Uniform insolation, magnitudes from Wing et al. (2018)
403413
#Note that the TOA downward shortwave fluxes won't be the same as the values in the paper if add_isothermal_boundary_layer is true
404414
function set_insolation_variables!(Y, p, t, ::RCEMIPIIInsolation)

src/callbacks/get_callbacks.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,5 +365,22 @@ function get_callbacks(config, sim_info, atmos, params, Y, p)
365365
(callbacks..., call_every_dt(rrtmgp_model_callback!, dt_rad))
366366
end
367367

368+
if atmos.non_orographic_gravity_wave isa NonOrographicGravityWave
369+
dt_nogw =
370+
dt isa ITime ? ITime(time_to_seconds(parsed_args["dt_nogw"])) :
371+
FT(time_to_seconds(parsed_args["dt_nogw"]))
372+
dt_nogw, _, _, _ = promote(dt_nogw, t_start, dt, sim_info.t_end)
373+
# We use Millisecond to support fractional seconds, eg. 0.1
374+
dt_nogw_ms = Dates.Millisecond(1_000 * float(dt_nogw))
375+
if parsed_args["dt_save_state_to_disk"] != "Inf" &&
376+
!CA.isdivisible(dt_save_state_to_disk_dates, dt_nogw_ms)
377+
@warn "Non-orographic gravity wave period ($(dt_nogw_ms)) is not an even divisor of the checkpoint frequency ($dt_save_state_to_disk_dates)"
378+
@warn "This simulation will not be reproducible when restarted"
379+
end
380+
381+
callbacks =
382+
(callbacks..., call_every_dt(nogw_model_callback!, dt_nogw))
383+
end
384+
368385
return callbacks
369386
end

src/diagnostics/Diagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import ..PrognosticEDMFX
4242
import ..DiagnosticEDMFX
4343

4444
# gravitywave_models
45-
import ..NonOrographyGravityWave
45+
import ..NonOrographicGravityWave
4646
import ..OrographicGravityWave
4747

4848
# surface_model

src/diagnostics/gravitywave_diagnostics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function compute_utendnogw!(
1616
cache,
1717
time,
1818
::T,
19-
) where {T <: NonOrographyGravityWave}
19+
) where {T <: NonOrographicGravityWave}
2020
if isnothing(out)
2121
# u_waveforcing is not a field:
2222
# return Fields.array2field(
@@ -53,7 +53,7 @@ function compute_vtendnogw!(
5353
cache,
5454
time,
5555
::T,
56-
) where {T <: NonOrographyGravityWave}
56+
) where {T <: NonOrographicGravityWave}
5757
if isnothing(out)
5858
# v_waveforcing is not a Field:
5959
# return Fields.array2field(

src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl

Lines changed: 73 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ non_orographic_gravity_wave_cache(Y, atmos::AtmosModel) =
1414

1515
non_orographic_gravity_wave_cache(Y, ::Nothing) = (;)
1616

17-
non_orographic_gravity_wave_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
1817

19-
function non_orographic_gravity_wave_cache(Y, gw::NonOrographyGravityWave)
18+
function non_orographic_gravity_wave_cache(Y, gw::NonOrographicGravityWave)
2019
if iscolumn(axes(Y.c))
2120
FT = Spaces.undertype(axes(Y.c))
2221
(; source_height, Bw, Bn, Bt_0, dc, cmax, c0, nk, cw, cn) = gw
@@ -134,12 +133,9 @@ function non_orographic_gravity_wave_cache(Y, gw::NonOrographyGravityWave)
134133
end
135134
end
136135

137-
function non_orographic_gravity_wave_tendency!(
138-
Yₜ,
136+
function non_orographic_gravity_wave_compute_tendency!(
139137
Y,
140-
p,
141-
t,
142-
::NonOrographyGravityWave,
138+
p
143139
)
144140
#unpack
145141
ᶜT = p.scratch.ᶜtemp_scalar
@@ -276,11 +272,39 @@ function non_orographic_gravity_wave_tendency!(
276272
p,
277273
)
278274

275+
# # update cache after computation
276+
# # do I need to do this? Since these attributes were
277+
# # unpacked via reference?
278+
# p.non_orographic_gravity_wave.uforcing .= uforcing
279+
# p.non_orographic_gravity_wave.vforcing .= vforcing
280+
281+
end
282+
283+
non_orographic_gravity_wave_tendency!(Yₜ, Y, p, t, ::Nothing) = nothing
284+
285+
function non_orographic_gravity_wave_tendency!(
286+
Yₜ,
287+
Y,
288+
p,
289+
t,
290+
::NonOrographicGravityWave,
291+
)
292+
293+
#unpack
294+
(;
295+
uforcing,
296+
vforcing,
297+
) = p.non_orographic_gravity_wave
298+
279299
@. Yₜ.c.uₕ +=
280300
Geometry.Covariant12Vector.(Geometry.UVVector.(uforcing, vforcing))
281301

282302
end
283303

304+
305+
306+
307+
284308
function non_orographic_gravity_wave_forcing(
285309
ᶜu,
286310
ᶜv,
@@ -368,49 +392,50 @@ function non_orographic_gravity_wave_forcing(
368392
#StaticBitVector stores 8 boolean values in a UInt8, allowing efficient storage for up to 256 gravity wave break data.
369393
level_end = Spaces.nlevels(axes(ᶜρ))
370394

371-
# loop over all wave lengths
372-
for ink in 1:gw_nk
395+
# Collect all required fields in a broadcasted object
396+
input_u = Base.Broadcast.broadcasted(
397+
tuple,
398+
ᶜu_p1,
399+
ᶜu_source,
400+
ᶜbf_p1,
401+
ᶜρ,
402+
ᶜρ_p1,
403+
ᶜρ_source,
404+
ᶜz_p1,
405+
ᶜz,
406+
source_level,
407+
gw_Bw,
408+
gw_Bn,
409+
gw_cw,
410+
gw_cn,
411+
gw_flag,
412+
ᶜlevel,
413+
gw_source_ampl,
414+
)
373415

374-
# Collect all required fields in a broadcasted object
375-
input_u = Base.Broadcast.broadcasted(
376-
tuple,
377-
ᶜu_p1,
378-
ᶜu_source,
379-
ᶜbf_p1,
380-
ᶜρ,
381-
ᶜρ_p1,
382-
ᶜρ_source,
383-
ᶜz_p1,
384-
ᶜz,
385-
source_level,
386-
gw_Bw,
387-
gw_Bn,
388-
gw_cw,
389-
gw_cn,
390-
gw_flag,
391-
ᶜlevel,
392-
gw_source_ampl,
393-
)
416+
input_v = Base.Broadcast.broadcasted(
417+
tuple,
418+
ᶜv_p1,
419+
ᶜv_source,
420+
ᶜbf_p1,
421+
ᶜρ,
422+
ᶜρ_p1,
423+
ᶜρ_source,
424+
ᶜz_p1,
425+
ᶜz,
426+
source_level,
427+
gw_Bw,
428+
gw_Bn,
429+
gw_cw,
430+
gw_cn,
431+
gw_flag,
432+
ᶜlevel,
433+
gw_source_ampl,
434+
)
394435

395-
input_v = Base.Broadcast.broadcasted(
396-
tuple,
397-
ᶜv_p1,
398-
ᶜv_source,
399-
ᶜbf_p1,
400-
ᶜρ,
401-
ᶜρ_p1,
402-
ᶜρ_source,
403-
ᶜz_p1,
404-
ᶜz,
405-
source_level,
406-
gw_Bw,
407-
gw_Bn,
408-
gw_cw,
409-
gw_cn,
410-
gw_flag,
411-
ᶜlevel,
412-
gw_source_ampl,
413-
)
436+
437+
# loop over all wave lengths
438+
for ink in 1:gw_nk
414439

415440
# Accumulate zonal wave forcing in every column
416441
waveforcing_column_accumulate!(

src/solver/model_getters.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ function get_non_orographic_gravity_wave_model(
183183
@assert nogw_name in (true, false)
184184
return if nogw_name == true
185185
if parsed_args["config"] == "column"
186-
NonOrographyGravityWave{FT}(; Bw = 1.2, Bn = 0.0, Bt_0 = 4e-3)
186+
NonOrographicGravityWave{FT}(; Bw = 1.2, Bn = 0.0, Bt_0 = 4e-3)
187187
elseif parsed_args["config"] == "sphere"
188-
NonOrographyGravityWave{FT}(;
188+
NonOrographicGravityWave{FT}(;
189189
Bw = 0.4,
190190
Bn = 0.0,
191191
cw = 35.0,

src/solver/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Base.@kwdef struct RayleighSponge{FT} <: AbstractSponge
241241
end
242242

243243
abstract type AbstractGravityWave end
244-
Base.@kwdef struct NonOrographyGravityWave{FT} <: AbstractGravityWave
244+
Base.@kwdef struct NonOrographicGravityWave{FT} <: AbstractGravityWave
245245
source_pressure::FT = 31500
246246
damp_pressure::FT = 85
247247
source_height::FT = 15000

0 commit comments

Comments
 (0)