Skip to content

Commit 0352480

Browse files
committed
Simplify diff_mode access
1 parent d672825 commit 0352480

File tree

7 files changed

+26
-62
lines changed

7 files changed

+26
-62
lines changed

src/diagnostics/default_diagnostics.jl

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,17 @@ function default_diagnostics(
437437
start_date;
438438
output_writer,
439439
)
440-
diagnostics = []
441-
442440
# Add radiation mode diagnostics
443-
if atmos_radiation.radiation_mode !== nothing
444-
append!(
445-
diagnostics,
446-
default_diagnostics(
447-
atmos_radiation.radiation_mode,
448-
duration,
449-
start_date;
450-
output_writer,
451-
),
441+
if !isnothing(atmos_radiation.radiation_mode)
442+
return default_diagnostics(
443+
atmos_radiation.radiation_mode,
444+
duration,
445+
start_date;
446+
output_writer,
452447
)
448+
else
449+
return []
453450
end
454-
455-
return diagnostics
456451
end
457452

458453
function default_diagnostics(
@@ -461,20 +456,15 @@ function default_diagnostics(
461456
start_date;
462457
output_writer,
463458
)
464-
diagnostics = []
465-
466459
# Add turbulence convection model diagnostics
467-
if atmos_turbconv.turbconv_model !== nothing
468-
append!(
469-
diagnostics,
470-
default_diagnostics(
471-
atmos_turbconv.turbconv_model,
472-
duration,
473-
start_date;
474-
output_writer,
475-
),
460+
if !isnothing(atmos_turbconv.turbconv_model)
461+
return default_diagnostics(
462+
atmos_turbconv.turbconv_model,
463+
duration,
464+
start_date;
465+
output_writer,
476466
)
467+
else
468+
return []
477469
end
478-
479-
return diagnostics
480470
end

src/diagnostics/radiation_diagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function compute_rsd!(
4545
cache.radiation.rrtmgp_model.face_sw_flux_dn,
4646
axes(state.f),
4747
)
48-
@assert out !== nothing "Output field 'out' must not be `nothing` in this branch"
48+
@assert !isnothing(out) "Output field 'out' must not be `nothing` in this branch"
4949
radiation_mode.deep_atmosphere &&
5050
apply_geometric_scaling!(out, z_lev, planet_radius, FT)
5151
end

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ NVTX.@annotate function implicit_tendency!(Yₜ, Y, p, t)
3030
)
3131
end
3232

33-
if p.atmos.numerics.diff_mode == Implicit()
33+
if p.atmos.diff_mode == Implicit()
3434
vertical_diffusion_boundary_layer_tendency!(
3535
Yₜ,
3636
Y,

src/prognostic_equations/remaining_tendency.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
201201
)
202202
end
203203

204-
if p.atmos.numerics.diff_mode == Explicit()
204+
if p.atmos.diff_mode == Explicit()
205205
vertical_diffusion_boundary_layer_tendency!(
206206
Yₜ,
207207
Y,

src/solver/type_getters.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ function get_atmos(config::AtmosConfig, params)
145145
numerics = get_numerics(parsed_args),
146146
disable_surface_flux_tendency = parsed_args["disable_surface_flux_tendency"],
147147
)
148+
# TODO: Should this go in the AtmosModel constructor?
148149
@assert !@any_reltype(atmos, (UnionAll, DataType))
149150

150151
@info "AtmosModel: \n$(summary(atmos))"
@@ -450,7 +451,7 @@ get_jacobian(ode_algo, Y, atmos, parsed_args) =
450451
parsed_args["use_dense_jacobian"] ? AutoDenseJacobian() :
451452
ManualSparseJacobian(
452453
DerivativeFlag(has_topography(axes(Y.c))),
453-
DerivativeFlag(atmos.numerics.diff_mode),
454+
DerivativeFlag(atmos.diff_mode),
454455
DerivativeFlag(atmos.sgs_adv_mode),
455456
DerivativeFlag(atmos.sgs_entr_detr_mode),
456457
DerivativeFlag(atmos.sgs_mf_mode),

src/solver/types.jl

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ const ATMOS_MODEL_GROUPS = (
650650
(AtmosGravityWave, :gravity_wave),
651651
(AtmosSponge, :sponge),
652652
(AtmosSurface, :surface),
653+
(AtmosNumerics, :numerics),
653654
)
654655

655656
# Auto-generate map from property_name to group_field
@@ -869,20 +870,10 @@ function AtmosModel(; kwargs...)
869870
# Kwargs for direct AtmosModel fields (hyperdiff, numerics, vert_diff, disable_surface_flux_tendency)
870871
atmos_model_kwargs = Dict{Symbol, Any}()
871872

872-
# Make all kwargs: apply defaults for any missing kwargs, then sort into appropriate groups
873-
all_kwargs = Dict{Symbol, Any}()
873+
# Merge defaults with kwargs
874+
all_kwargs = merge(default_args, kwargs)
874875

875-
# First add defaults
876-
for (key, default_value) in pairs(default_args)
877-
all_kwargs[key] = default_value
878-
end
879-
880-
# Then add user kwargs (overriding defaults)
881-
for (key, value) in kwargs
882-
all_kwargs[key] = value
883-
end
884-
885-
# Sort kwargs into appropriate groups
876+
# Sort kwargs into a hierarchy of dicts
886877
for (key, value) in all_kwargs
887878
if haskey(GROUPED_PROPERTY_MAP, key)
888879
group_field = GROUPED_PROPERTY_MAP[key]
@@ -987,15 +978,6 @@ end
987978
EquilMoistAtmosModel(; kwargs...)
988979
989980
Create an equilibrium moist atmospheric model with sensible defaults for moist simulations.
990-
991-
# Example
992-
```julia
993-
model = EquilMoistAtmosModel(;
994-
precip_model = Microphysics1Moment(),
995-
cloud_model = QuadratureCloud(),
996-
surface_model = PrognosticSurfaceTemperature()
997-
)
998-
```
999981
"""
1000982
function EquilMoistAtmosModel(; kwargs...)
1001983
defaults = (
@@ -1015,15 +997,6 @@ end
1015997
NonEquilMoistAtmosModel(; kwargs...)
1016998
1017999
Create a non-equilibrium moist atmospheric model with sensible defaults.
1018-
1019-
# Example
1020-
```julia
1021-
model = NonEquilMoistAtmosModel(;
1022-
precip_model = Microphysics2Moment(),
1023-
cloud_model = SGSQuadratureCloud(),
1024-
noneq_cloud_formation_mode = Implicit()
1025-
)
1026-
```
10271000
"""
10281001
function NonEquilMoistAtmosModel(; kwargs...)
10291002
defaults = (

test/solver/atmos_model_constructor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323

2424
@testset "AtmosModel Constructor Tests" begin
2525

26-
@testset "Intelligent Defaults" begin
26+
@testset "Sensible Defaults" begin
2727
@testset "Basic AtmosModel() creates working model with expected defaults" begin
2828
model = CA.AtmosModel()
2929

0 commit comments

Comments
 (0)