Skip to content

Commit 6610c1b

Browse files
authored
Merge pull request #3713 from CliMA/zs/implicit_nh_pressure
make nonhydrostatic pressure drag implicit
2 parents cbc48e4 + 64860f3 commit 6610c1b

File tree

9 files changed

+75
-15
lines changed

9 files changed

+75
-15
lines changed

.buildkite/pipeline.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ steps:
134134
--job_id single_column_hydrostatic_balance_ft64
135135
--out_dir single_column_hydrostatic_balance_ft64/output_active
136136
artifact_paths: "single_column_hydrostatic_balance_ft64/output_active/*"
137+
agents:
138+
slurm_constraint: icelake|cascadelake|skylake|epyc
137139

138140
- group: "Box Examples"
139141
steps:
@@ -363,6 +365,7 @@ steps:
363365
artifact_paths: "aquaplanet_nonequil_allsky_gw_res/output_active/*"
364366
agents:
365367
slurm_mem: 20GB
368+
slurm_constraint: icelake|cascadelake|skylake|epyc
366369

367370
- label: ":computer: aquaplanet equil allsky monin_obukhov varying insol gravity wave (raw_topo) high top zonally asymmetric"
368371
command: >

config/default_configs/default_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ implicit_sgs_advection:
324324
implicit_sgs_entr_detr:
325325
help: "Whether to treat the subgrid-scale entrainment and detrainment tendency implicitly [`false` (default), `true`]. Setting it to true only works if implicit_sgs_advection is set to true."
326326
value: false
327+
implicit_sgs_nh_pressure:
328+
help: "Whether to treat the subgrid-scale nonhydrostatic pressure drag tendency implicitly [`false` (default), `true`]. Setting it to true only works if implicit_sgs_advection is set to true."
329+
value: false
327330
implicit_sgs_mass_flux:
328331
help: "Whether to treat the subgrid-scale mass flux tendency implicitly or explicitly in grid-mean equations. Currently updraft only with Jacobian terms 0. [`false` (default), `true`]. Setting it to true only works if both implicit_sgs_advection and implicit_diffusion are set to true."
329332
value: false

config/model_configs/prognostic_edmfx_bomex_implicit_column.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ turbconv: "prognostic_edmfx"
77
implicit_diffusion: true
88
implicit_sgs_advection: true
99
implicit_sgs_entr_detr: true
10+
implicit_sgs_nh_pressure: true
1011
implicit_sgs_mass_flux: true
1112
approximate_linear_solve_iters: 2
1213
max_newton_iters_ode: 3

config/perf_configs/bm_aquaplanet_progedmf.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ viscous_sponge: true
1010
implicit_diffusion: true
1111
implicit_sgs_advection: true
1212
implicit_sgs_entr_detr: true
13+
implicit_sgs_nh_pressure: true
1314
implicit_sgs_mass_flux: true
1415
approximate_linear_solve_iters: 2
1516
moist: equil

src/prognostic_equations/implicit/implicit_solver.jl

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct ImplicitEquationJacobian{
100100
F3 <: DerivativeFlag,
101101
F4 <: DerivativeFlag,
102102
F5 <: DerivativeFlag,
103+
F6 <: DerivativeFlag,
103104
T <: Fields.FieldVector,
104105
R <: Base.RefValue,
105106
}
@@ -114,7 +115,8 @@ struct ImplicitEquationJacobian{
114115
topography_flag::F2
115116
sgs_advection_flag::F3
116117
sgs_entr_detr_flag::F4
117-
sgs_mass_flux_flag::F5
118+
sgs_nh_pressure_flag::F5
119+
sgs_mass_flux_flag::F6
118120

119121
# required by Krylov.jl to evaluate ldiv! with AbstractVector inputs
120122
temp_b::T
@@ -133,6 +135,7 @@ function Base.zero(jac::ImplicitEquationJacobian)
133135
jac.topography_flag,
134136
jac.sgs_advection_flag,
135137
jac.sgs_entr_detr_flag,
138+
jac.sgs_nh_pressure_flag,
136139
jac.sgs_mass_flux_flag,
137140
jac.temp_b,
138141
jac.temp_x,
@@ -153,6 +156,8 @@ function ImplicitEquationJacobian(
153156
IgnoreDerivative(),
154157
sgs_entr_detr_flag = atmos.sgs_entr_detr_mode == Implicit() ?
155158
UseDerivative() : IgnoreDerivative(),
159+
sgs_nh_pressure_flag = atmos.sgs_nh_pressure_mode == Implicit() ?
160+
UseDerivative() : IgnoreDerivative(),
156161
sgs_mass_flux_flag = atmos.sgs_mf_mode == Implicit() ? UseDerivative() :
157162
IgnoreDerivative(),
158163
transform_flag = false,
@@ -409,6 +414,7 @@ function ImplicitEquationJacobian(
409414
topography_flag,
410415
sgs_advection_flag,
411416
sgs_entr_detr_flag,
417+
sgs_nh_pressure_flag,
412418
sgs_mass_flux_flag,
413419
similar(Y),
414420
similar(Y),
@@ -497,11 +503,22 @@ NVTX.@annotate function Wfact!(A, Y, p, dtγ, t)
497503
p.precomputed.bdmr_l,
498504
p.precomputed.bdmr_r,
499505
p.precomputed.bdmr,
506+
) : (;)
507+
)...,
508+
(
509+
use_derivative(A.sgs_entr_detr_flag) &&
510+
p.atmos.turbconv_model isa PrognosticEDMFX ?
511+
(;
500512
p.precomputed.ᶜentrʲs,
501513
p.precomputed.ᶜdetrʲs,
502514
p.precomputed.ᶜturb_entrʲs,
503515
) : (;)
504516
)...,
517+
(
518+
use_derivative(A.sgs_nh_pressure_flag) &&
519+
p.atmos.turbconv_model isa PrognosticEDMFX ?
520+
(; p.precomputed.ᶠu₃⁰,) : (;)
521+
)...,
505522
p.core.ᶜΦ,
506523
p.core.ᶠgradᵥ_ᶜΦ,
507524
p.scratch.ᶜtemp_scalar,
@@ -537,6 +554,7 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ)
537554
diffusion_flag,
538555
sgs_advection_flag,
539556
sgs_entr_detr_flag,
557+
sgs_nh_pressure_flag,
540558
topography_flag,
541559
sgs_mass_flux_flag,
542560
) = A
@@ -580,6 +598,7 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ)
580598
ᶠJ = Fields.local_geometry_field(Y.f).J
581599
ᶜgⁱʲ = Fields.local_geometry_field(Y.c).gⁱʲ
582600
ᶠgⁱʲ = Fields.local_geometry_field(Y.f).gⁱʲ
601+
ᶠlg = Fields.local_geometry_field(Y.f)
583602

584603
ᶜkappa_m = p.ᶜtemp_scalar
585604
@. ᶜkappa_m =
@@ -1006,19 +1025,39 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ)
10061025
end
10071026

10081027
# entrainment and detrainment
1009-
(; ᶜentrʲs, ᶜdetrʲs, ᶜturb_entrʲs) = p
1010-
# This assumes entrainment and detrainment rates are constant in the Jacobian
1011-
@. ∂ᶜq_totʲ_err_∂ᶜq_totʲ -=
1012-
dtγ * DiagonalMatrixRow(ᶜentrʲs.:(1) + ᶜturb_entrʲs.:(1))
1013-
@. ∂ᶜmseʲ_err_∂ᶜmseʲ -=
1014-
dtγ * DiagonalMatrixRow(ᶜentrʲs.:(1) + ᶜturb_entrʲs.:(1))
1015-
@. ∂ᶜρaʲ_err_∂ᶜρaʲ +=
1016-
dtγ * DiagonalMatrixRow(ᶜentrʲs.:(1) - ᶜdetrʲs.:(1))
1017-
@. ∂ᶠu₃ʲ_err_∂ᶠu₃ʲ -=
1018-
dtγ * (DiagonalMatrixRow(
1019-
(ᶠinterp(ᶜentrʲs.:(1) + ᶜturb_entrʲs.:(1))) *
1020-
(one_C3xACT3,),
1021-
))
1028+
if use_derivative(sgs_entr_detr_flag)
1029+
(; ᶜentrʲs, ᶜdetrʲs, ᶜturb_entrʲs) = p
1030+
# This assumes entrainment and detrainment rates are constant in the Jacobian
1031+
@. ∂ᶜq_totʲ_err_∂ᶜq_totʲ -=
1032+
dtγ * DiagonalMatrixRow(ᶜentrʲs.:(1) + ᶜturb_entrʲs.:(1))
1033+
@. ∂ᶜmseʲ_err_∂ᶜmseʲ -=
1034+
dtγ * DiagonalMatrixRow(ᶜentrʲs.:(1) + ᶜturb_entrʲs.:(1))
1035+
@. ∂ᶜρaʲ_err_∂ᶜρaʲ +=
1036+
dtγ * DiagonalMatrixRow(ᶜentrʲs.:(1) - ᶜdetrʲs.:(1))
1037+
@. ∂ᶠu₃ʲ_err_∂ᶠu₃ʲ -=
1038+
dtγ * (DiagonalMatrixRow(
1039+
(ᶠinterp(ᶜentrʲs.:(1) + ᶜturb_entrʲs.:(1))) *
1040+
(one_C3xACT3,),
1041+
))
1042+
end
1043+
1044+
# non-hydrostatic pressure drag
1045+
# Only the quadratic drag term is considered in the Jacobian, the buoyancy term is ignored
1046+
if use_derivative(sgs_nh_pressure_flag)
1047+
(; ᶠu₃⁰) = p
1048+
turbconv_params = CAP.turbconv_params(params)
1049+
α_d = CAP.pressure_normalmode_drag_coeff(turbconv_params)
1050+
scale_height =
1051+
CAP.R_d(params) * CAP.T_surf_ref(params) / CAP.grav(params)
1052+
H_up_min = CAP.min_updraft_top(turbconv_params)
1053+
@. ∂ᶠu₃ʲ_err_∂ᶠu₃ʲ -=
1054+
dtγ * (DiagonalMatrixRow(
1055+
2 *
1056+
α_d *
1057+
Geometry._norm((Y.f.sgsʲs.:(1).u₃ - ᶠu₃⁰), ᶠlg) /
1058+
max(scale_height, H_up_min) * (one_C3xACT3,),
1059+
))
1060+
end
10221061

10231062
# add updraft mass flux contributions to grid-mean
10241063
if use_derivative(sgs_mass_flux_flag)

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ NVTX.@annotate function implicit_tendency!(Yₜ, Y, p, t)
3939
edmfx_sgs_mass_flux_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
4040
end
4141

42+
if p.atmos.sgs_nh_pressure_mode == Implicit()
43+
edmfx_nh_pressure_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
44+
end
45+
4246
# NOTE: All ρa tendencies should be applied before calling this function
4347
pressure_work_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
4448

src/prognostic_equations/remaining_tendency.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ NVTX.@annotate function additional_tendency!(Yₜ, Y, p, t)
118118
if p.atmos.sgs_mf_mode == Explicit()
119119
edmfx_sgs_mass_flux_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
120120
end
121-
edmfx_nh_pressure_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
121+
if p.atmos.sgs_nh_pressure_mode == Explicit()
122+
edmfx_nh_pressure_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
123+
end
122124
edmfx_filter_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
123125
edmfx_tke_tendency!(Yₜ, Y, p, t, p.atmos.turbconv_model)
124126
# Non-equilibrium cloud formation

src/solver/type_getters.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ function get_atmos(config::AtmosConfig, params)
5858
implicit_sgs_entr_detr = parsed_args["implicit_sgs_entr_detr"]
5959
@assert implicit_sgs_entr_detr in (true, false)
6060

61+
implicit_sgs_nh_pressure = parsed_args["implicit_sgs_nh_pressure"]
62+
@assert implicit_sgs_nh_pressure in (true, false)
63+
6164
implicit_sgs_mass_flux = parsed_args["implicit_sgs_mass_flux"]
6265
@assert implicit_sgs_mass_flux in (true, false)
6366

@@ -107,6 +110,8 @@ function get_atmos(config::AtmosConfig, params)
107110
diff_mode = implicit_diffusion ? Implicit() : Explicit(),
108111
sgs_adv_mode = implicit_sgs_advection ? Implicit() : Explicit(),
109112
sgs_entr_detr_mode = implicit_sgs_entr_detr ? Implicit() : Explicit(),
113+
sgs_nh_pressure_mode = implicit_sgs_nh_pressure ? Implicit() :
114+
Explicit(),
110115
sgs_mf_mode = implicit_sgs_mass_flux ? Implicit() : Explicit(),
111116
viscous_sponge = get_viscous_sponge_model(parsed_args, params, FT),
112117
smagorinsky_lilly = get_smagorinsky_lilly_model(parsed_args),

src/solver/types.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ Base.@kwdef struct AtmosModel{
560560
sgs_adv_mode::SAM = nothing
561561
"""sgs_entr_detr_mode == Implicit() only works if sgs_adv_mode == Implicit()"""
562562
sgs_entr_detr_mode::SEDM = nothing
563+
"""sgs_nh_pressure_mode == Implicit() only works if sgs_adv_mode == Implicit()"""
564+
sgs_nh_pressure_mode::SEDM = nothing
563565
"""sgs_mf_mode == Implicit() only works if sgs_adv_mode == Implicit() and diff_mode == Implicit()"""
564566
sgs_mf_mode::SMM = nothing
565567
viscous_sponge::VS = nothing

0 commit comments

Comments
 (0)