Skip to content

Commit 97f24be

Browse files
committed
ft: Add Kinematic Driver (KiD) model configuration
temp: commented out various tendencies todo: debug why we have `clw` at surface
1 parent 79028dd commit 97f24be

File tree

10 files changed

+365
-181
lines changed

10 files changed

+365
-181
lines changed

config/default_configs/default_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,6 @@ use_itime:
419419
1. Surface conditions that explicitly depend on time (e.g. LifeCycleTan2018, TRMM_LBA, etc.),
420420
2. Time dependent forcing/tendencies use time rounded to the nearest unit of time for dt"
421421
value: false
422+
prescribed_flow:
423+
help: "Prescribe a flow field [`nothing` (default), `true`]"
424+
value: ~
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## Model
2+
prescribed_flow: true
3+
initial_condition: "ShipwayHill2012"
4+
tracer_upwinding: first_order
5+
moist: "nonequil"
6+
cloud_model: "grid_scale"
7+
call_cloud_diagnostics_per_stage: true
8+
precip_model: "1M"
9+
config: "column"
10+
## Simulation
11+
z_max: 4e3
12+
z_elem: 100
13+
z_stretch: false
14+
dt: "1secs"
15+
t_end: "1hours"
16+
dt_save_state_to_disk: "1hours"
17+
toml: [toml/kinematic_driver.toml]
18+
## Diagnostics
19+
output_default_diagnostics: false
20+
diagnostics:
21+
- short_name: [ta, thetaa, ha, rhoa, wa, hur, hus, cl, clw, cli, husra, hussn]
22+
period: 10secs

examples/hybrid/KiD_driver.jl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import ClimaComms
2+
import ClimaAtmos as CA
3+
import ClimaCore: Fields
4+
import YAML
5+
import ClimaComms
6+
7+
import Random
8+
# Random.seed!(Random.MersenneTwister())
9+
Random.seed!(1234)
10+
11+
# --> get config
12+
configs_path = joinpath(pkgdir(CA), "config/model_configs/")
13+
pth = joinpath(configs_path, "kinematic_driver.yml");
14+
job_id = "kinematic_driver";
15+
config_dict = YAML.load_file(pth)
16+
# <--
17+
18+
19+
config = CA.AtmosConfig(config_dict; job_id)
20+
simulation = CA.get_simulation(config);
21+
22+
sol_res = CA.solve_atmos!(simulation); # solve!
23+
24+
(; integrator) = simulation;
25+
(; p) = integrator;
26+
(; atmos, params) = p;
27+
28+
# --> Make ci plots
29+
# ]add ClimaAnalysis, ClimaCoreSpectra
30+
include(joinpath(pkgdir(CA), "post_processing", "ci_plots.jl"))
31+
ref_job_id = config.parsed_args["reference_job_id"]
32+
reference_job_id = isnothing(ref_job_id) ? simulation.job_id : ref_job_id
33+
make_plots(Val(Symbol(reference_job_id)), simulation.output_dir)
34+
# <--
35+
36+
# --> ClimaAnalysis
37+
import ClimaAnalysis
38+
# using ClimaAnalysis.Visualize
39+
import ClimaAnalysis.Visualize as viz
40+
using ClimaAnalysis.Utils: kwargs
41+
using CairoMakie;
42+
CairoMakie.activate!();
43+
# using GLMakie; GLMakie.activate!()
44+
simdir = ClimaAnalysis.SimDir(simulation.output_dir);
45+
46+
# entr = get(simdir; short_name = "entr")
47+
# entr.dims # (time, x, y, z)
48+
49+
# fig = Figure();
50+
# viz.plot!(fig, entr, time=0, x=0, y=0, more_kwargs = Dict(:axis => kwargs(dim_on_y = true)))
51+
# viz.plot!(fig, entr, x=0, y=0);
52+
# fig
53+
# <--
54+
55+
56+
57+
#=
58+
%use upwinding for the rain -- yes!
59+
60+
qr, qs, all specific humidities,
61+
62+
take 30% acoustic Courant number c=300m/s, divided by vertical res
63+
- for ~200
64+
65+
ill make some plots
66+
67+
is smag applied to qr??? check this!
68+
69+
most likely precip would cause blow-ups.
70+
=#

src/initial_conditions/initial_conditions.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,3 +1618,49 @@ function (initial_condition::ISDAC)(params)
16181618
)
16191619
end
16201620
end
1621+
1622+
"""
1623+
ShipwayHill2012
1624+
1625+
The `InitialCondition` described in [ShipwayHill2012](@cite), but with a hydrostatically
1626+
balanced pressure profile.
1627+
1628+
B. J. Shipway and A. A. Hill.
1629+
Diagnosis of systematic differences between multiple parametrizations of warm rain microphysics using a kinematic framework.
1630+
Quarterly Journal of the Royal Meteorological Society 138, 2196-2211 (2012).
1631+
"""
1632+
Base.@kwdef struct ShipwayHill2012 <: InitialCondition end
1633+
1634+
function (initial_condition::ShipwayHill2012)(params)
1635+
FT = eltype(params)
1636+
1637+
## Initialize the profile
1638+
z_0 = FT(0.0) # 0.0
1639+
z_1 = FT(740.0) # 740.0
1640+
z_2 = FT(3260.0) # 3260.0
1641+
rv_0 = FT(0.015) # 0.015
1642+
rv_1 = FT(0.0138) # 0.0138
1643+
rv_2 = FT(0.0024) # 0.0024
1644+
θ_0 = FT(297.9) # 297.9
1645+
θ_1 = FT(297.9) # 297.9
1646+
θ_2 = FT(312.66) # 312.66
1647+
1648+
# profile of water vapour mixing ratio
1649+
rv(z) = z < z_1 ? rv_0 + (rv_1 - rv_0) / (z_1 - z_0) * (z - z_0) : rv_1 + (rv_2 - rv_1) / (z_2 - z_1) * (z - z_1)
1650+
q_tot(z) = rv(z) / (1 + rv(z))
1651+
1652+
# profile of potential temperature
1653+
θ(z) = z < z_1 ? θ_0 : θ_1 + (θ_2 - θ_1) / (z_2 - z_1) * (z - z_1)
1654+
##
1655+
thermo_params = CAP.thermodynamics_params(params)
1656+
p_0 = FT(100700) # Pa
1657+
p = hydrostatic_pressure_profile(; thermo_params, p_0, θ, q_tot)
1658+
function local_state(local_geometry)
1659+
(; z) = local_geometry.coordinates
1660+
return LocalState(; params, geometry = local_geometry,
1661+
thermo_state = TD.PhaseEquil_pθq(thermo_params, p(z), θ(z), q_tot(z)),
1662+
precip_state = PrecipStateMassNum(; q_rai = FT(0), q_sno = FT(0)),
1663+
)
1664+
end
1665+
return local_state
1666+
end

src/prognostic_equations/advection.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
279279
)
280280
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, FT(dt), energy_q_tot_upwinding)
281281
vtt_central = vertical_transport(ᶜρ, ᶠu³, ᶜh_tot, FT(dt), Val(:none))
282-
@. Yₜ.c.ρe_tot += vtt - vtt_central
282+
# @. Yₜ.c.ρe_tot += vtt - vtt_central
283283
end
284284

285285
if !(p.atmos.moisture_model isa DryModel) && energy_q_tot_upwinding != Val(:none)
@@ -289,35 +289,35 @@ NVTX.@annotate function explicit_vertical_advection_tendency!(Yₜ, Y, p, t)
289289
@. Yₜ.c.ρq_tot += vtt - vtt_central
290290
end
291291

292-
if isnothing(ᶠf¹²)
293-
# shallow atmosphere
294-
@. Yₜ.c.uₕ -=
295-
ᶜinterp(ᶠω¹² × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) / (Y.c.ρ * ᶜJ) +
296-
(ᶜf³ + ᶜω³) × CT12(ᶜu)
297-
@. Yₜ.f.u₃ -= ᶠω¹² × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
298-
for j in 1:n
299-
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
300-
ᶠω¹²ʲs.:($$j) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
301-
ᶠgradᵥ(ᶜKʲs.:($$j) - ᶜinterp(ᶠKᵥʲs.:($$j)))
302-
end
303-
else
304-
# deep atmosphere
305-
@. Yₜ.c.uₕ -=
306-
ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) /
307-
(Y.c.ρ * ᶜJ) + (ᶜf³ + ᶜω³) × CT12(ᶜu)
308-
@. Yₜ.f.u₃ -= (ᶠf¹² + ᶠω¹²) × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
309-
for j in 1:n
310-
@. Yₜ.f.sgsʲs.:($$j).u₃ -=
311-
(ᶠf¹² + ᶠω¹²ʲs.:($$j)) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
312-
ᶠgradᵥ(ᶜKʲs.:($$j) - ᶜinterp(ᶠKᵥʲs.:($$j)))
313-
end
314-
end
315-
316-
if use_prognostic_tke(turbconv_model) # advect_tke triggers allocations
317-
@. ᶜa_scalar = ᶜtke⁰ * draft_area(ᶜρa⁰, ᶜρ⁰)
318-
vtt = vertical_transport(ᶜρ⁰, ᶠu³⁰, ᶜa_scalar, dt, edmfx_mse_q_tot_upwinding)
319-
@. Yₜ.c.sgs⁰.ρatke += vtt
320-
end
292+
# if isnothing(ᶠf¹²)
293+
# # shallow atmosphere
294+
# @. Yₜ.c.uₕ -=
295+
# ᶜinterp(ᶠω¹² × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) / (Y.c.ρ * ᶜJ) +
296+
# (ᶜf³ + ᶜω³) × CT12(ᶜu)
297+
# @. Yₜ.f.u₃ -= ᶠω¹² × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
298+
# for j in 1:n
299+
# @. Yₜ.f.sgsʲs.:($$j).u₃ -=
300+
# ᶠω¹²ʲs.:($$j) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
301+
# ᶠgradᵥ(ᶜKʲs.:($$j) - ᶜinterp(ᶠKᵥʲs.:($$j)))
302+
# end
303+
# else
304+
# # deep atmosphere
305+
# @. Yₜ.c.uₕ -=
306+
# ᶜinterp((ᶠf¹² + ᶠω¹²) × (ᶠinterp(Y.c.ρ * ᶜJ) * ᶠu³)) /
307+
# (Y.c.ρ * ᶜJ) + (ᶜf³ + ᶜω³) × CT12(ᶜu)
308+
# @. Yₜ.f.u₃ -= (ᶠf¹² + ᶠω¹²) × ᶠinterp(CT12(ᶜu)) + ᶠgradᵥ(ᶜK)
309+
# for j in 1:n
310+
# @. Yₜ.f.sgsʲs.:($$j).u₃ -=
311+
# (ᶠf¹² + ᶠω¹²ʲs.:($$j)) × ᶠinterp(CT12(ᶜuʲs.:($$j))) +
312+
# ᶠgradᵥ(ᶜKʲs.:($$j) - ᶜinterp(ᶠKᵥʲs.:($$j)))
313+
# end
314+
# end
315+
316+
# if use_prognostic_tke(turbconv_model) # advect_tke triggers allocations
317+
# @. ᶜa_scalar = ᶜtke⁰ * draft_area(ᶜρa⁰, ᶜρ⁰)
318+
# vtt = vertical_transport(ᶜρ⁰, ᶠu³⁰, ᶜa_scalar, dt, edmfx_mse_q_tot_upwinding)
319+
# @. Yₜ.c.sgs⁰.ρatke += vtt
320+
# end
321321
end
322322

323323
"""

src/prognostic_equations/dss.jl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,23 @@ dss!(Y_state, params, t_current)
7777
"""
7878

7979
NVTX.@annotate function dss!(Y, p, t)
80-
if do_dss(axes(Y.c))
81-
Spaces.weighted_dss!(Y.c => p.ghost_buffer.c, Y.f => p.ghost_buffer.f)
82-
end
80+
# if do_dss(axes(Y.c))
81+
# Spaces.weighted_dss!(Y.c => p.ghost_buffer.c, Y.f => p.ghost_buffer.f)
82+
# end
83+
prescribe_flow!(Y, p, t, p.atmos.prescribed_flow)
8384
return nothing
8485
end
86+
87+
prescribe_flow!(Y, p, t, ::Nothing) = nothing
88+
function prescribe_flow!(Y, p, t, flow::PrescribedFlow)
89+
FT = eltype(p.params)
90+
# (; uₕ, u₃, ρ, p) = flow
91+
(; prescribed_u₃) = flow
92+
lg = Fields.local_geometry_field(Y.f)
93+
# Main.@infiltrate
94+
@. Y.f.u₃ = C3(Geometry.WVector(prescribed_u₃(FT, t)), lg)
95+
# @. Y.c.uₕ = uₕ(t)
96+
# @. Y.c.ρ = ρ₀ # move to IC
97+
# @. Y.c.p = p₀ # move to IC
98+
return nothing
99+
end

0 commit comments

Comments
 (0)