Skip to content

Commit 4e4e9b2

Browse files
committed
fully explicit kid
1 parent c843d86 commit 4e4e9b2

File tree

7 files changed

+56
-32
lines changed

7 files changed

+56
-32
lines changed

config/default_configs/default_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,5 +426,5 @@ use_itime:
426426
2. Time dependent forcing/tendencies use time rounded to the nearest unit of time for dt"
427427
value: false
428428
prescribed_flow:
429-
help: "Prescribe a flow field [`nothing` (default), `true`]"
429+
help: "Prescribe a flow field [`nothing` (default), `ShipwayHill2012`]"
430430
value: ~

config/model_configs/kinematic_driver.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Model
2-
prescribed_flow: true
3-
initial_condition: "ShipwayHill2012"
4-
surface_setup: "ShipwayHill2012"
2+
prescribed_flow: ShipwayHill2012
3+
initial_condition: ShipwayHill2012
4+
surface_setup: ShipwayHill2012
55
energy_q_tot_upwinding: first_order
66
tracer_upwinding: first_order
77
# moist: "nonequil"
@@ -13,8 +13,10 @@ call_cloud_diagnostics_per_stage: true
1313
config: "column"
1414
hyperdiff: "false"
1515
## Simulation
16-
z_max: 2e3
17-
z_elem: 128
16+
# z_max: 2e3 # TODO: Update top boundary condition for ρu₃qₜ to allow lower z_max
17+
# z_elem: 128
18+
z_max: 8e3
19+
z_elem: 512
1820
z_stretch: false
1921
use_auto_jacobian: true # Needed!! (+only 1 Newton iteration, which is the default)
2022
# ode_algo: "ARS111" # try: Explicit Euler

src/cache/temporary_quantities.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,6 @@ function temporary_quantities(Y, atmos)
117117
ᶜdiffusion_u_matrix = similar(Y.c, TridiagonalMatrixRow{FT}),
118118
ᶜtridiagonal_matrix_scalar = similar(Y.c, TridiagonalMatrixRow{FT}),
119119
ᶠtridiagonal_matrix_c3 = similar(Y.f, TridiagonalMatrixRow{C3{FT}}),
120+
(!isnothing(atmos.prescribed_flow) ? (; temp_Yₜ_imp = similar(Y)) : (;))...,
120121
)
121122
end

src/prognostic_equations/advection.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,6 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
314314
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), energy_q_tot_upwinding)
315315
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), Val(:none))
316316
vtt_bc = ᶜρq_tot_vertical_transport_bc(prescribed_flow, thermo_params, t, ᶠu³)
317-
if prescribed_flow isa PrescribedFlow
318-
vtt_central = NullBroadcasted() # turn off implicit advection
319-
end
320317
@. Yₜ.c.ρq_tot += vtt - vtt_central + vtt_bc
321318
end
322319

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
131131
if !(moisture_model isa DryModel)
132132
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
133133
vtt = vertical_transport(Y.c.ρ, ᶠu³, ᶜq_tot, dt, Val(:none))
134-
(; prescribed_flow) = p.atmos
135-
if prescribed_flow isa PrescribedFlow
136-
vtt = NullBroadcasted() # Turn off implicit energy q_tot advection
137-
end
138134
@. Yₜ.c.ρq_tot += vtt
139135
end
140136

src/solver/model_getters.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ function check_case_consistency(parsed_args)
660660
turbconv = parsed_args["turbconv"]
661661
topography = parsed_args["topography"]
662662
prescribed_flow = parsed_args["prescribed_flow"]
663-
auto_jacobian = parsed_args["use_auto_jacobian"]
664663

665664
ISDAC_mandatory = (ic, subs, surf, rad, extf)
666665
if "ISDAC" in ISDAC_mandatory
@@ -677,14 +676,20 @@ function check_case_consistency(parsed_args)
677676
"Implicit vertical diffusion is only supported when using a " *
678677
"turbulence convection model or vertical diffusion model.",
679678
)
680-
elseif prescribed_flow === true
679+
elseif !isnothing(prescribed_flow)
681680
@assert(topography == "NoWarp",
682681
"Prescribed flow elides `set_velocity_at_surface!` and `set_velocity_at_top!` \
683682
which is needed for topography. Thus, prescribed flow must have flat surface."
684683
)
685-
@assert(auto_jacobian === true,
686-
"Prescribed flow modifies the implicit treatment of sound waves, \
687-
thus the manual sparse jacobian is not supported."
684+
@assert(
685+
!parsed_args["implicit_noneq_cloud_formation"] &&
686+
!parsed_args["implicit_diffusion"] &&
687+
!parsed_args["implicit_sgs_advection"] &&
688+
!parsed_args["implicit_sgs_entr_detr"] &&
689+
!parsed_args["implicit_sgs_nh_pressure"] &&
690+
!parsed_args["implicit_sgs_vertdiff"] &&
691+
!parsed_args["implicit_sgs_mass_flux"],
692+
"Prescribed flow does not use the implicit solver."
688693
)
689694
end
690695
end

src/solver/type_getters.jl

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function get_atmos(config::AtmosConfig, params)
114114
FT,
115115
)
116116

117-
if parsed_args["prescribed_flow"] === true
117+
if parsed_args["prescribed_flow"] == "ShipwayHill2012"
118118
prescribed_flow = ShipwayHill2012VelocityProfile{FT}()
119119
else
120120
prescribed_flow = nothing
@@ -724,21 +724,45 @@ function get_sim_info(config::AtmosConfig)
724724
return sim
725725
end
726726

727+
"""
728+
fully_explicit_tendency!
729+
730+
Experimental timestepping mode where all implicit tendencies are treated explicitly.
731+
"""
732+
function fully_explicit_tendency!(Yₜ, Yₜ_lim, Y, p, t)
733+
(; temp_Yₜ_imp) = p.scratch
734+
implicit_tendency!(temp_Yₜ_imp, Y, p, t)
735+
remaining_tendency!(Yₜ, Yₜ_lim, Y, p, t)
736+
Yₜ .+= temp_Yₜ_imp
737+
end
738+
function fully_explicit_cache!(Y, p, t)
739+
set_precomputed_quantities!(Y, p, t)
740+
set_implicit_precomputed_quantities!(Y, p, t)
741+
end
742+
743+
727744
function args_integrator(parsed_args, Y, p, tspan, ode_algo, callback)
728745
(; atmos, dt) = p
729746
s = @timed_str begin
730-
T_imp! = SciMLBase.ODEFunction(
731-
implicit_tendency!;
732-
jac_prototype = get_jacobian(ode_algo, Y, atmos, parsed_args),
733-
Wfact = update_jacobian!,
734-
)
747+
if isnothing(parsed_args["prescribed_flow"])
748+
# This is the default case
749+
T_exp_T_lim! = remaining_tendency!
750+
T_imp! = SciMLBase.ODEFunction(implicit_tendency!;
751+
jac_prototype = get_jacobian(ode_algo, Y, atmos, parsed_args),
752+
Wfact = update_jacobian!,
753+
)
754+
cache! = set_precomputed_quantities!
755+
cache_imp! = set_implicit_precomputed_quantities!
756+
else
757+
# `prescribed_flow` is an experimental case where the flow is prescribed,
758+
# so implicit tendencies are treated explicitly to avoid treatment of sound waves
759+
T_exp_T_lim! = fully_explicit_tendency!
760+
T_imp! = nothing
761+
cache! = fully_explicit_cache!
762+
cache_imp! = nothing
763+
end
735764
tendency_function = CTS.ClimaODEFunction(;
736-
T_exp_T_lim! = remaining_tendency!,
737-
T_imp!,
738-
lim! = limiters_func!,
739-
dss!,
740-
cache! = set_precomputed_quantities!,
741-
cache_imp! = set_implicit_precomputed_quantities!,
765+
T_exp_T_lim!, T_imp!, cache!, cache_imp!, lim! = limiters_func!, dss!,
742766
)
743767
end
744768
@info "Define ode function: $s"
@@ -748,8 +772,7 @@ function args_integrator(parsed_args, Y, p, tspan, ode_algo, callback)
748772
saveat = [t_begin, t_end]
749773
args = (problem, ode_algo)
750774
allow_custom_kwargs = (; kwargshandle = CTS.DiffEqBase.KeywordArgSilent)
751-
kwargs =
752-
(; saveat, callback, dt, adjustfinal = true, allow_custom_kwargs...)
775+
kwargs = (; saveat, callback, dt, adjustfinal = true, allow_custom_kwargs...)
753776
return (args, kwargs)
754777
end
755778

0 commit comments

Comments
 (0)