Skip to content

Commit c8252b9

Browse files
committed
make it work
1 parent 874b360 commit c8252b9

File tree

9 files changed

+56
-30
lines changed

9 files changed

+56
-30
lines changed

config/model_configs/kinematic_driver.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
prescribed_flow: true
33
initial_condition: "ShipwayHill2012"
44
surface_setup: "ShipwayHill2012"
5+
energy_q_tot_upwinding: first_order_kid
56
tracer_upwinding: first_order
67
# moist: "nonequil"
78
# precip_model: "1M"
@@ -12,13 +13,14 @@ call_cloud_diagnostics_per_stage: true
1213
config: "column"
1314
hyperdiff: "false"
1415
## Simulation
15-
z_max: 4e3
16-
z_elem: 200
16+
z_max: 2e3
17+
z_elem: 128
1718
z_stretch: false
19+
use_auto_jacobian: true # Needed!! (+only 1 Newton iteration, which is the default)
1820
# ode_algo: "ARS111" # try: Explicit Euler
1921
dt: "1secs"
20-
# t_end: "1hours"
21-
t_end: "20mins"
22+
t_end: "1hours"
23+
# t_end: "20mins"
2224
dt_save_state_to_disk: "1hours"
2325
toml: [toml/kinematic_driver.toml]
2426
check_nan_every: 1
@@ -27,7 +29,7 @@ output_default_diagnostics: false
2729
diagnostics:
2830
- short_name: [
2931
# (z,t) fields
30-
ta, thetaa, ha, rhoa, wa, hur, hus, cl, clw, cli,
32+
ta, thetaa, ha, rhoa, wa, hur, hus, cl, clw, cli, ua, va, ke,
3133
# (t,) fields
3234
lwp, pr,
3335
# 1M

post_processing/ci_plots.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ function make_plots(::Val{:kinematic_driver}, output_paths::Vector{<:AbstractStr
16991699
return var
17001700
end
17011701
simdirs = SimDir.(output_paths)
1702-
short_names = ["hus", "clw", "husra", "ta", "thetaa", "wa", "cli", "hussn"]
1702+
short_names = ["hus", "clw", "husra", "rhoa", "ta", "thetaa", "wa", "cli", "hussn", "ua", "va", "ke"]
17031703
short_names = short_names collect(keys(simdirs[1].vars))
17041704
vars = map_comparison(simdirs, short_names) do simdir, short_name
17051705
var = slice(get(simdir; short_name), x = 0, y = 0)

src/cache/precomputed_quantities.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,10 @@ NVTX.@annotate function set_implicit_precomputed_quantities_part1!(Y, p, t)
480480

481481
# TODO: We might want to move this to dss! (and rename dss! to something
482482
# like enforce_constraints!).
483-
set_velocity_at_surface!(Y, ᶠuₕ³, turbconv_model)
484-
set_velocity_at_top!(Y, turbconv_model)
483+
if !(p.atmos.prescribed_flow isa PrescribedFlow)
484+
set_velocity_at_surface!(Y, ᶠuₕ³, turbconv_model)
485+
set_velocity_at_top!(Y, turbconv_model)
486+
end
485487

486488
set_velocity_quantities!(ᶜu, ᶠu³, ᶜK, Y.f.u₃, Y.c.uₕ, ᶠuₕ³)
487489
ᶜJ = Fields.local_geometry_field(Y.c).J

src/prognostic_equations/advection.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
286286
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
287287
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), energy_q_tot_upwinding)
288288
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), Val(:none))
289+
if energy_q_tot_upwinding == Val(:first_order_kid)
290+
vtt = vertical_transport_kid(ᶜρ, ᶠu³, ᶜq_tot, FT(dt), FT(t))
291+
vtt_central = NullBroadcasted() # turn off implicit advection
292+
end
289293
@. Yₜ.c.ρq_tot += vtt - vtt_central
290294
end
291295

src/prognostic_equations/dss.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,25 @@ end
8787

8888
prescribe_flow!(Y, p, t, ::Nothing) = nothing
8989
function prescribe_flow!(Y, p, t, flow::PrescribedFlow)
90-
FT = eltype(p.params)
91-
(; prescribed_u₃) = flow
9290
ᶠlg = Fields.local_geometry_field(Y.f)
93-
@. Y.f.u₃ = C3(Geometry.WVector(prescribed_u₃(FT, t)), ᶠlg)
91+
z = Fields.coordinate_field(Y.f).z
92+
@. Y.f.u₃ = C3(Geometry.WVector(flow(z, t)), ᶠlg)
9493

95-
return nothing # comment out to try fixing energy
94+
# return nothing # comment out to try fixing energy
9695

9796
### Fix energy to initial temperature
9897
ᶜlg = Fields.local_geometry_field(Y.c)
9998
local_state = InitialConditions.ShipwayHill2012()(p.params)
100-
get_ρ_init(ls) = TD.air_density(ls.thermo_params, ls.thermo_state)
99+
get_ρ_init_dry(ls) = ls.thermo_state.ρ * (1 - ls.thermo_state.q_tot)
101100
get_T_init(ls) = TD.air_temperature(ls.thermo_params, ls.thermo_state)
102-
ᶜρ_init = @. lazy(get_ρ_init(local_state(ᶜlg)))
101+
ᶜρ_init_dry = @. lazy(get_ρ_init_dry(local_state(ᶜlg)))
103102
ᶜT_init = @. lazy(get_T_init(local_state(ᶜlg)))
104103

105104
thermo_params = CAP.thermodynamics_params(p.params)
106105
grav = CAP.grav(p.params)
107106
z = Fields.coordinate_field(Y.c).z
108107

109-
@. Y.c.ρ = ᶜρ_init + Y.c.ρq_tot
108+
@. Y.c.ρ = ᶜρ_init_dry + Y.c.ρq_tot
110109
ᶜts = @. lazy(TD.PhaseEquil_ρTq(thermo_params, Y.c.ρ, ᶜT_init, Y.c.ρq_tot / Y.c.ρ))
111110
ᶜe_kin = compute_kinetic(Y.c.uₕ, Y.f.u₃)
112111
ᶜe_pot = @. lazy(grav * z)

src/prognostic_equations/implicit/implicit_tendency.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ function vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:first_order})
8282
ᶠJ = Fields.local_geometry_field(axes(ᶠu³)).J
8383
return @. lazy(-(ᶜadvdivᵥ(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ * ᶠupwind1(ᶠu³, ᶜχ))))
8484
end
85+
vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:first_order_kid}) =
86+
vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, Val(:first_order)) # transport e.g. ρe_tot as usual
87+
function vertical_transport_kid(ᶜρ, ᶠu³, ᶜχ, dt, t)
88+
FT = eltype(ᶜρ)
89+
ᶜJ = Fields.local_geometry_field(axes(ᶜρ)).J
90+
ᶠJ = Fields.local_geometry_field(axes(ᶠu³)).J
91+
ρ_sfc = FT(1.1650101) # TODO: Get from initial conditions or state
92+
q_tot_sfc = FT(0.014778325) # TODO: Get from initial conditions or state
93+
u₃_sfc = ShipwayHill2012VelocityProfile{FT}()(FT(0), t)
94+
95+
bottom_bc = Geometry.WVector(ρ_sfc * q_tot_sfc * u₃_sfc)
96+
ᶜadvdivᵥ_kid = Operators.DivergenceF2C(
97+
bottom = Operators.SetValue(bottom_bc), top = Operators.Extrapolate(),
98+
)
99+
return @. lazy(-(ᶜadvdivᵥ_kid(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ * ᶠupwind1(ᶠu³, ᶜχ))))
100+
end
85101
@static if pkgversion(ClimaCore) v"0.14.22"
86102
function vertical_transport(ᶜρ, ᶠu³, ᶜχ, dt, ::Val{:vanleer_limiter})
87103
ᶜJ = Fields.local_geometry_field(axes(ᶜρ)).J
@@ -131,6 +147,9 @@ function implicit_vertical_advection_tendency!(Yₜ, Y, p, t)
131147
if !(moisture_model isa DryModel)
132148
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
133149
vtt = vertical_transport(Y.c.ρ, ᶠu³, ᶜq_tot, dt, Val(:none))
150+
if p.atmos.numerics.energy_q_tot_upwinding == Val(:first_order_kid)
151+
vtt = NullBroadcasted() # Turn off implicit energy q_tot advection
152+
end
134153
@. Yₜ.c.ρq_tot += vtt
135154
end
136155

src/solver/type_getters.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,7 @@ function get_atmos(config::AtmosConfig, params)
115115
)
116116

117117
if parsed_args["prescribed_flow"]
118-
function prescribed_u₃(FT::Type{<:Real}, _t)
119-
t = FT(_t)
120-
w1 = FT(2)
121-
t1 = FT(600) # 10 minutes
122-
return t < t1 ? w1 * sin* t / t1) : FT(0)
123-
end
124-
prescribed_flow = PrescribedFlow(; prescribed_u₃)
118+
prescribed_flow = ShipwayHill2012VelocityProfile{FT}()
125119
else
126120
prescribed_flow = nothing
127121
end

src/solver/types.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import Dates
66
import ClimaUtilities.ClimaArtifacts: @clima_artifact
77
import LazyArtifacts
88

9-
abstract type AbstractPrescribedFlow end
10-
@kwdef struct PrescribedFlow
11-
prescribed_u₃::Function
12-
end
13-
149
abstract type AbstractMoistureModel end
1510
abstract type AbstractMoistModel <: AbstractMoistureModel end
1611
struct DryModel <: AbstractMoistureModel end
@@ -504,6 +499,15 @@ struct RadiationTRMM_LBA{R}
504499
end
505500
end
506501

502+
abstract type PrescribedFlow end
503+
504+
struct ShipwayHill2012VelocityProfile{FT} <: PrescribedFlow end
505+
function (::ShipwayHill2012VelocityProfile{FT})(z, t) where {FT}
506+
w1 = FT(1.5)
507+
t1 = FT(600)
508+
return t < t1 ? w1 * sinpi(FT(t) / t1) : FT(0)
509+
end
510+
507511
struct TestDycoreConsistency end
508512

509513
abstract type AbstractTimesteppingMode end
@@ -708,7 +712,7 @@ const ATMOS_MODEL_GROUPS = (
708712
(AtmosWater, :water),
709713
(AtmosRadiation, :radiation),
710714
(AtmosTurbconv, :turbconv),
711-
(PrescribedFlow, :prescribed_flow),
715+
(ShipwayHill2012VelocityProfile, :prescribed_flow),
712716
(AtmosGravityWave, :gravity_wave),
713717
(AtmosSponge, :sponge),
714718
(AtmosSurface, :surface),

src/surface_conditions/surface_setups.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ function (::ShipwayHill2012)(params)
254254
# Adjust the coefficients from 20 m to the actual value of z.
255255
z0 = FT(1.5e-4)
256256
adjustment = (log(20 / z0) / log(interior_z / z0))^2
257-
Cd = FT(0.001229) * adjustment
258-
Ch = FT(0.001094) * adjustment
257+
# Cd = FT(0.001229) * adjustment
258+
# Ch = FT(0.001094) * adjustment
259+
Cd = FT(0.0)
260+
Ch = FT(0.0)
259261
parameterization = ExchangeCoefficients(; Cd, Ch)
260262
# <<<
261263
return SurfaceState(; parameterization, T, p, q_vap)

0 commit comments

Comments
 (0)