Skip to content

Commit

Permalink
Make precipitation part of the working fluid. Wip, [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Jan 29, 2025
1 parent ebf8e24 commit 8fe2274
Show file tree
Hide file tree
Showing 29 changed files with 688 additions and 498 deletions.
14 changes: 7 additions & 7 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ steps:
- group: "Sphere Examples (Aquaplanet)"
steps:

- label: ":umbrella: aquaplanet (ρe_tot) equil allsky monin_obukhov varying insol gravity wave (gfdl_restart) high top 1-moment"
- label: ":umbrella: aquaplanet (ρe_tot) nonequil allsky monin_obukhov varying insol gravity wave (gfdl_restart) high top 1-moment"
command: >
julia --color=yes --project=examples examples/hybrid/driver.jl
--config_file $CONFIG_PATH/sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res.yml
--job_id sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res
--config_file $CONFIG_PATH/sphere_aquaplanet_rhoe_nonequilmoist_allsky_gw_res.yml
--job_id sphere_aquaplanet_rhoe_nonequilmoist_allsky_gw_res
julia --color=yes --project=examples reproducibility_tests/test_mse.jl
--job_id sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res
--out_dir sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res/output_active
artifact_paths: "sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res/output_active/*"
--job_id sphere_aquaplanet_rhoe_nonequilmoist_allsky_gw_res
--out_dir sphere_aquaplanet_rhoe_nonequilmoist_allsky_gw_res/output_active
artifact_paths: "sphere_aquaplanet_rhoe_nonequilmoist_allsky_gw_res/output_active/*"
agents:
slurm_mem: 20GB

Expand All @@ -349,7 +349,7 @@ steps:
slurm_mem: 20GB
slurm_constraint: icelake|cascadelake|skylake|epyc

- label: ":computer: aquaplanet (ρe_tot) nonequilmoist allsky radiation monin_obukhov varying insolation high top 1-moment"
- label: ":umbrella: aquaplanet (ρe_tot) nonequilmoist allsky radiation monin_obukhov varying insolation high top 1-moment"
command: >
julia --color=yes --project=examples examples/hybrid/driver.jl
--config_file $CONFIG_PATH/sphere_aquaplanet_rhoe_nonequilmoist_allsky.yml
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ClimaComms = "0.6.4"
ClimaCore = "0.14.19"
ClimaDiagnostics = "0.2.4"
ClimaParams = "0.10.17"
ClimaTimeSteppers = "0.7.39"
ClimaTimeSteppers = "0.7, 0.8"
ClimaUtilities = "0.1.14"
CloudMicrophysics = "0.22.3"
Dates = "1"
Expand Down
21 changes: 12 additions & 9 deletions config/longrun_configs/longrun_moist_baroclinic_wave.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
h_elem: 30
z_elem: 43
dz_bottom: 30.0
dt: "90secs"
t_end: "120days"
h_elem: 6 #30
z_elem: 10 #43
dz_bottom: 300.0
dt: "200secs"
approximate_linear_solve_iters: 3
max_newton_iters_ode: 1
rayleigh_sponge: true
t_end: "10days"
ode_algo: ARS343
initial_condition: "MoistBaroclinicWave"
moist: "equil"
precip_model: "0M"
moist: "nonequil"
precip_model: "1M"
dt_save_state_to_disk: "10days"
toml: [toml/longrun_baroclinic_wave.toml]
diagnostics:
- short_name: [pfull, wa, va, rv, hus, ke]
period: 1days
- short_name: [pfull, wa, va, ua, ta, rhoa, rv, hus, ke, clw, cli, husra, hussn, ]
period: 600secs
2 changes: 1 addition & 1 deletion config/model_configs/diagnostic_edmfx_aquaplanet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ edmfx_sgs_mass_flux: true
edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
precip_model: 1M
precip_model: 0M
dt: 120secs
t_end: 3hours
reproducibility_test: true
Expand Down
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_dycoms_rf02_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edmfx_sgs_mass_flux: true
edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
precip_model: "1M"
precip_model: "0M"
call_cloud_diagnostics_per_stage: true
config: box
x_max: 1e8
Expand All @@ -35,6 +35,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_rico_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edmfx_sgs_mass_flux: true
edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
precip_model: "1M"
precip_model: "0M"
call_cloud_diagnostics_per_stage: true
config: box
x_max: 1e8
Expand All @@ -34,6 +34,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_trmm_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ moist: equil
cloud_model: "quadrature_sgs"
call_cloud_diagnostics_per_stage: true
apply_limiter: false
precip_model: "1M"
precip_model: "0M"
config: box
x_max: 1e8
y_max: 1e8
Expand All @@ -35,6 +35,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
4 changes: 1 addition & 3 deletions config/model_configs/diagnostic_edmfx_trmm_stretched_box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edmfx_sgs_diffusive_flux: true
moist: equil
cloud_model: "quadrature_sgs"
call_cloud_diagnostics_per_stage: true
precip_model: "1M"
precip_model: "0M"
config: box
x_max: 1e8
y_max: 1e8
Expand All @@ -35,6 +35,4 @@ diagnostics:
period: 10mins
- short_name: [arup, waup, taup, thetaaup, haup, husup, hurup, clwup, cliup, waen, tke, lmix]
period: 10mins
- short_name: [husra, hussn]
period: 10mins
ode_algo: ARS343
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ implicit_diffusion: true
approximate_linear_solve_iters: 2
cloud_model: "grid_scale"
moist: "nonequil"
precip_model: "nothing"
precip_model: "1M"
rad: "allskywithclear"
insolation: "timevarying"
rayleigh_sponge: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dt_save_state_to_disk: "24hours"
vert_diff: "FriersonDiffusion"
implicit_diffusion: true
approximate_linear_solve_iters: 2
moist: "equil"
moist: "nonequil"
precip_model: "1M"
rad: "allskywithclear"
aerosol_radiation: true
Expand Down
10 changes: 7 additions & 3 deletions examples/Manifest-v1.11.toml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ weakdeps = ["CUDA", "MPI"]

[[deps.ClimaCore]]
deps = ["Adapt", "BandedMatrices", "BlockArrays", "ClimaComms", "CubedSphere", "DataStructures", "ForwardDiff", "GaussQuadrature", "GilbertCurves", "HDF5", "InteractiveUtils", "IntervalSets", "KrylovKit", "LinearAlgebra", "MultiBroadcastFusion", "NVTX", "PkgVersion", "RecursiveArrayTools", "RootSolvers", "SparseArrays", "StaticArrays", "Statistics", "Unrolled"]
git-tree-sha1 = "61d071cfe584d99a1400a3bf96a122c45c282121"
git-tree-sha1 = "ce9de8f8c74e523a560b66b067c220438b287974"
repo-rev = "main"
repo-url = "https://github.com/CliMA/ClimaCore.jl.git"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
version = "0.14.24"
weakdeps = ["CUDA", "Krylov"]
Expand Down Expand Up @@ -418,9 +420,11 @@ version = "0.1.1"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
git-tree-sha1 = "ff967e27a56a938d3e719bb8d2e025b086c3f808"
git-tree-sha1 = "facfe93769c3343bbe512fb61b19cfdf85804118"
repo-rev = "main"
repo-url = "https://github.com/CliMA/ClimaTimeSteppers.jl.git"
uuid = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
version = "0.7.39"
version = "0.8.1"

[deps.ClimaTimeSteppers.extensions]
ClimaTimeSteppersBenchmarkToolsExt = ["CUDA", "BenchmarkTools", "OrderedCollections", "StatsBase", "PrettyTables"]
Expand Down
9 changes: 4 additions & 5 deletions post_processing/ci_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1190,17 +1190,16 @@ EDMFBoxPlots = Union{
Val{:prognostic_edmfx_bomex_box},
Val{:rcemipii_box_diagnostic_edmfx},
Val{:prognostic_edmfx_soares_column},
}

EDMFBoxPlotsWithPrecip = Union{
Val{:diagnostic_edmfx_dycoms_rf02_box},
Val{:prognostic_edmfx_rico_column},
Val{:prognostic_edmfx_trmm_column},
Val{:diagnostic_edmfx_rico_box},
Val{:diagnostic_edmfx_trmm_box},
Val{:diagnostic_edmfx_trmm_stretched_box},
}

EDMFBoxPlotsWithPrecip = Union{
Val{:prognostic_edmfx_rico_column},
Val{:prognostic_edmfx_trmm_column},
}
"""
plot_edmf_vert_profile!(grid_loc, var_group)
Expand Down
86 changes: 51 additions & 35 deletions src/cache/cloud_fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import NVTX
import StaticArrays as SA
import ClimaCore.RecursiveApply: rzero, ,

"""
Helper function to populate the cloud diagnostics named tuple
"""
function make_named_tuple(t1, t2, t3)
return NamedTuple{(:cf, :q_liq, :q_ice)}(tuple(t1, t2, t3))
end

# TODO: write a test with scalars that are linear with z
"""
Diagnose horizontal covariances based on vertical gradients
Expand All @@ -24,10 +31,11 @@ NVTX.@annotate function set_cloud_fraction!(Y, p, ::DryModel, _)
p.precomputed.cloud_diagnostics_tuple .=
((; cf = FT(0), q_liq = FT(0), q_ice = FT(0)),)
end

NVTX.@annotate function set_cloud_fraction!(
Y,
p,
::Union{EquilMoistModel, NonEquilMoistModel},
moist_model::Union{EquilMoistModel, NonEquilMoistModel},
::GridScaleCloud,
)
(; params) = p
Expand All @@ -48,13 +56,24 @@ NVTX.@annotate function set_cloud_fraction!(
end
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
end
@. cloud_diagnostics_tuple = NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(

if moist_model isa EquilMoistModel
@. cloud_diagnostics_tuple = make_named_tuple(
ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0),
TD.PhasePartition(thermo_params, ᶜts).liq,
TD.PhasePartition(thermo_params, ᶜts).ice,
),
)
)
else
@. cloud_diagnostics_tuple = make_named_tuple(
ifelse(
p.precomputed.ᶜspecific.q_liq + p.precomputed.ᶜspecific.q_ice > 0,
1,
0,
),
p.precomputed.ᶜspecific.q_liq,
p.precomputed.ᶜspecific.q_ice,
)
end
end
NVTX.@annotate function set_cloud_fraction!(
Y,
Expand All @@ -64,7 +83,7 @@ NVTX.@annotate function set_cloud_fraction!(
)
SG_quad = qc.SG_quad
(; params) = p

#TODO - do we want to substract precipitation for the noneq option?
FT = eltype(params)
thermo_params = CAP.thermodynamics_params(params)
(; ᶜts, ᶜmixing_length, cloud_diagnostics_tuple) = p.precomputed
Expand Down Expand Up @@ -103,6 +122,7 @@ NVTX.@annotate function set_cloud_fraction!(
moisture_model::Union{EquilMoistModel, NonEquilMoistModel},
cloud_model::SGSQuadratureCloud,
)
#TODO - do we want to substract precipitation for the noneq option?

(; turbconv_model) = p.atmos
set_cloud_fraction!(Y, p, moisture_model, cloud_model, turbconv_model)
Expand All @@ -119,6 +139,8 @@ NVTX.@annotate function set_cloud_fraction!(
SG_quad = qc.SG_quad
(; params) = p

#TODO - do we want to substract precipitation for the noneq option?

FT = eltype(params)
thermo_params = CAP.thermodynamics_params(params)
(; ᶜts, ᶜmixing_length, cloud_diagnostics_tuple) = p.precomputed
Expand All @@ -143,21 +165,18 @@ NVTX.@annotate function set_cloud_fraction!(
n = n_mass_flux_subdomains(turbconv_model)

for j in 1:n
@. cloud_diagnostics_tuple += NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)),
0,
),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
@. cloud_diagnostics_tuple += make_named_tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)),
0,
),
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(ᶜρaʲs.:($$j), ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
)
end

end

NVTX.@annotate function set_cloud_fraction!(
Expand All @@ -176,6 +195,7 @@ NVTX.@annotate function set_cloud_fraction!(
(; ᶜρʲs, ᶜtsʲs, ᶜρa⁰, ᶜρ⁰) = p.precomputed
(; turbconv_model) = p.atmos

# TODO - do we want to substract precipitation for the noneq option?
# TODO - we should make this default when using diagnostic edmf
# environment
diagnostic_covariance_coeff = CAP.diagnostic_covariance_coeff(params)
Expand All @@ -191,29 +211,25 @@ NVTX.@annotate function set_cloud_fraction!(
)

# weight cloud diagnostics by environmental area
@. cloud_diagnostics_tuple *= NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
),
@. cloud_diagnostics_tuple *= make_named_tuple(
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
draft_area(ᶜρa⁰, ᶜρ⁰),
)
# updrafts
n = n_mass_flux_subdomains(turbconv_model)

for j in 1:n
@. cloud_diagnostics_tuple += NamedTuple{(:cf, :q_liq, :q_ice)}(
tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
0,
),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
@. cloud_diagnostics_tuple += make_named_tuple(
ifelse(
TD.has_condensate(thermo_params, ᶜtsʲs.:($$j)),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)),
0,
),
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).liq,
draft_area(Y.c.sgsʲs.:($$j).ρa, ᶜρʲs.:($$j)) *
TD.PhasePartition(thermo_params, ᶜtsʲs.:($$j)).ice,
)
end
end
Expand Down
6 changes: 2 additions & 4 deletions src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
# To be applied in updraft continuity, moisture and energy
# for updrafts and grid mean
if precip_model isa Microphysics0Moment
@. S_q_totʲ_prev_level = q_tot_precipitation_sources(
precip_model,
@. S_q_totʲ_prev_level = q_tot_0M_precipitation_sources(
thermo_params,
microphys_0m_params,
dt,
Expand Down Expand Up @@ -1034,8 +1033,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_precipita
(; q_tot) = p.precomputed.ᶜspecific

# Environment precipitation sources (to be applied to grid mean)
@. ᶜSqₜᵖ⁰ = q_tot_precipitation_sources(
precip_model,
@. ᶜSqₜᵖ⁰ = q_tot_0M_precipitation_sources(
thermo_params,
microphys_0m_params,
dt,
Expand Down
Loading

0 comments on commit 8fe2274

Please sign in to comment.