Skip to content

Commit ecd5e1b

Browse files
committed
Improve CAM_SE hyperdiff robustness and update cases
that use ClimaHyperdiffusion to be consistent
1 parent 9684580 commit ecd5e1b

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

config/default_configs/default_config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ z_max:
2929
value: 30000.0
3030
vorticity_hyperdiffusion_coefficient:
3131
help: "Hyperdiffusion coefficient for vorticity (m s-1)"
32-
value: 1.5
32+
value: 0.1857
3333
scalar_hyperdiffusion_coefficient:
3434
help: "Hyperdiffusion coefficient for scalar (m s-1)"
35-
value: 1.5
35+
value: 0.929738
3636
# Topography
3737
topography:
3838
help: "Define the surface elevation profile [`NoWarp` (default), `Earth`, `DCMIP200`, `Hughes2023`, `Agnesi`, `Schar`, `Cosine2D`, `Cosine3D`]"
@@ -152,7 +152,7 @@ vert_diff:
152152
help: "Vertical diffusion [`false` (default), `VerticalDiffusion`, `true` (defaults to `VerticalDiffusion`), `DecayWithHeightDiffusion`]"
153153
value: false
154154
hyperdiff:
155-
help: "Hyperdiffusion [`ClimaHyperdiffusion` (or `true`), `CAM_SE` (default), `none` (or `false`)]"
155+
help: "Hyperdiffusion. Use `CAM_SE` for sensible default values and ClimaHyperdiffusion for user control. [`CAM_SE` (default), `ClimaHyperdiffusion` (or `true`), `none` (or `false`)]"
156156
value: "CAM_SE"
157157
smagorinsky_lilly:
158158
help: "Smagorinsky-Lilly diffusive closure [`false` (default), `true`]"
@@ -177,7 +177,7 @@ moist:
177177
value: "dry"
178178
divergence_damping_factor:
179179
help: "Divergence damping factor"
180-
value: 1.0
180+
value: 5.0
181181
rayleigh_sponge:
182182
help: "Rayleigh sponge [`true`, `false` (default)]"
183183
value: false

config/model_configs/baroclinic_wave_topography_dcmip_rs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ initial_condition: "DryBaroclinicWave"
66
t_end: "6days"
77
dt: "200secs"
88
hyperdiff: "ClimaHyperdiffusion"
9+
vorticity_hyperdiffusion_coefficient: 1.5
10+
scalar_hyperdiffusion_coefficient: 1.5
11+
divergence_damping_factor: 1.0
912
disable_surface_flux_tendency: true
1013
netcdf_output_at_levels: false
1114
diagnostics:

src/solver/model_getters.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,27 @@ function get_hyperdiffusion_model(parsed_args, ::Type{FT}) where {FT}
6666
ν₄_scalar_coeff,
6767
divergence_damping_factor,
6868
)
69-
elseif hyperdiff_name in ("CAM_SE",)
69+
elseif hyperdiff_name == "CAM_SE"
7070
# To match hyperviscosity coefficients in:
7171
# https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/2017MS001257
7272
# for equation A18 and A19
7373
# Need to scale by (1.1e5 / (sqrt(4 * pi / 6) * 6.371e6 / (3*30)) )^3 ≈ 1.238
74-
@info "Using CAM_SE hyperdiffusion. vorticity_hyperdiffusion_coefficient, \
75-
scalar_hyperdiffusion_coefficient and divergence_damping_factor in the config \
76-
will be ignored."
74+
# These are re-scaled by the grid resolution in function ν₄(hyperdiff, Y)
7775
ν₄_vorticity_coeff = FT(0.150 * 1.238)
7876
ν₄_scalar_coeff = FT(0.751 * 1.238)
7977
divergence_damping_factor = FT(5)
78+
# Ensure the user isn't trying to set the values manually from the config as CAM_SE defines a set of hyperdiffusion coefficients
79+
coeff_pairs = [
80+
(ν₄_vorticity_coeff, "vorticity_hyperdiffusion_coefficient"),
81+
(ν₄_scalar_coeff, "scalar_hyperdiffusion_coefficient"),
82+
(divergence_damping_factor, "divergence_damping_factor"),
83+
]
84+
85+
for (cam_coef, config_coef) in coeff_pairs
86+
# check to machine precision
87+
config_val = FT(parsed_args[config_coef])
88+
@assert isapprox(cam_coef, config_val, atol = 1e-8) "CAM_SE hyperdiffusion overwrites $config_coef, use hyperdiff: ClimaHyperdiffusion to set this value manually in the config instead."
89+
end
8090
return ClimaHyperdiffusion(;
8191
ν₄_vorticity_coeff,
8292
ν₄_scalar_coeff,

test/solver/model_getters.jl

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ import ClimaAtmos as CA
44

55
@testset "Hyperdiffusion config" begin
66
@info "CAM_SE (Special case of ClimaHyperdiffusion)"
7+
8+
# Test that CAM_SE uses the correct hardcoded coefficients
9+
# These match the values from https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/2017MS001257
710
config = CA.AtmosConfig(
811
Dict(
912
"hyperdiff" => "CAM_SE",
10-
"vorticity_hyperdiffusion_coefficient" => 0.2,
11-
"scalar_hyperdiffusion_coefficient" => 99.0,
12-
"divergence_damping_factor" => 99.0,
13+
"vorticity_hyperdiffusion_coefficient" => 0.1857,
14+
"scalar_hyperdiffusion_coefficient" => 0.929738,
15+
"divergence_damping_factor" => 5.0,
1316
),
14-
job_id = "model3",
17+
job_id = "test_hyperdiff_cam_se_args",
1518
)
19+
1620
parsed_args = config.parsed_args
1721
FT = eltype(config)
1822
hyperdiff_model = CA.get_hyperdiffusion_model(parsed_args, FT)
19-
# Coefficients are currently hardcoded in the CAM_SE type!!!
20-
# Regardless of user specified coeffs above, the CAM_SE selection
21-
# should override these coefficients to match values in
22-
# https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/2017MS001257
23+
24+
# Test that CAM_SE returns the correct coefficient values
2325
cam_se_ν₄_vort = FT(0.150 * 1.238)
2426
cam_se_ν₄_scalar = FT(0.751 * 1.238)
2527
cam_se_ν₄_dd = FT(5)
@@ -28,12 +30,28 @@ import ClimaAtmos as CA
2830
@test hyperdiff_model.ν₄_scalar_coeff == cam_se_ν₄_scalar
2931
@test hyperdiff_model.divergence_damping_factor == cam_se_ν₄_dd
3032

33+
@info "Test CAM_SE coefficient validation"
34+
# Test that CAM_SE throws an error when user tries to set different coefficients
35+
config_wrong = CA.AtmosConfig(
36+
Dict(
37+
"hyperdiff" => "CAM_SE",
38+
"vorticity_hyperdiffusion_coefficient" => 0.18571, # deliberately wrong value
39+
"scalar_hyperdiffusion_coefficient" => 0.929738,
40+
"divergence_damping_factor" => 5.0,
41+
),
42+
job_id = "test_hyperdiff_cam_se_wrong_args",
43+
)
44+
@test_throws AssertionError CA.AtmosSimulation(config_wrong)
45+
3146
@info "Test unrecognized Hyperdiffusion scheme"
32-
config = CA.AtmosConfig(
47+
config_unknown = CA.AtmosConfig(
3348
Dict("hyperdiff" => "UnknownHyperdiffusion"),
34-
job_id = "model4",
49+
job_id = "test_unknown_hyperdiff",
50+
)
51+
parsed_args_unknown = config_unknown.parsed_args
52+
FT = eltype(config_unknown)
53+
@test_throws ErrorException CA.get_hyperdiffusion_model(
54+
parsed_args_unknown,
55+
FT,
3556
)
36-
parsed_args = config.parsed_args
37-
FT = eltype(config)
38-
@test_throws ErrorException CA.get_hyperdiffusion_model(parsed_args, FT)
3957
end

0 commit comments

Comments
 (0)