Skip to content

Commit

Permalink
Merge #108
Browse files Browse the repository at this point in the history
108: Refactor KiD driver, add precipitation analysis r=sajjadazimi a=mikhailmints



Co-authored-by: Mikhail Mints <[email protected]>
  • Loading branch information
bors[bot] and mikhailmints authored Jul 17, 2023
2 parents c7078df + cbd27bc commit a7c67a7
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 211 deletions.
4 changes: 2 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ steps:
command: "julia --color=yes --project=test test/experiments/KiD_driver/KiD_driver.jl --moisture_choice=NonEquilibriumMoisture --prognostic_vars=RhodTQ --precipitation_choice=Precipitation1M"
artifact_paths: "test/experiments/KiD_driver/Output_NonEquilibriumMoisture_RhodTQ_Precipitation1M_CliMA_1M/figures/*"

- label: ":crystal_ball: Experiments: equil (fixed rhod and T) + KK2000 "
command: "julia --color=yes --project=test test/experiments/KiD_driver/KiD_driver.jl --moisture_choice=EquilibriumMoisture --prognostic_vars=RhodTQ --precipitation_choice=Precipitation1M --rain_formation_scheme_choice KK2000 --prescribed_Nd 1e8"
- label: ":crystal_ball: Experiments: equil (fixed rhod and T) + KK2000 + Float32 "
command: "julia --color=yes --project=test test/experiments/KiD_driver/KiD_driver.jl --FLOAT_TYPE=Float32 --moisture_choice=EquilibriumMoisture --prognostic_vars=RhodTQ --precipitation_choice=Precipitation1M --rain_formation_scheme_choice KK2000 --prescribed_Nd 1e8"
artifact_paths: "test/experiments/KiD_driver/Output_EquilibriumMoisture_RhodTQ_Precipitation1M_KK2000/figures/*"

- label: ":crystal_ball: Experiments: equil (fixed rhod and T) + B1994 "
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.8.1'
- '1.8.5'
os:
- ubuntu-latest
- macOS-latest
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Kinematic1D"
uuid = "a8a3bb05-6cc5-4342-abf6-5cc636bd2b35"
authors = ["Climate Modeling Alliance"]
version = "0.3.1"
version = "0.3.2"

[deps]
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
Expand All @@ -27,7 +27,7 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
[compat]
ClimaCore = "0.10"
ClimaCorePlots = "0.2"
CloudMicrophysics = "0.10"
CloudMicrophysics = "0.11.1"
DiffEqBase = "6.75"
Distributions = "0.25"
EnsembleKalmanProcesses = "1.1"
Expand Down
6 changes: 3 additions & 3 deletions src/driveKiD/NetCDFIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ function NetCDFIO_Stats(
return NetCDFIO_Stats(output_interval, nc_filename, output_profiles)
end

function KiD_output(aux, t::Float64)
function KiD_output(aux, t::FT) where {FT <: Real}

(; Stats) = aux

NC.Dataset(Stats.nc_filename, "a") do ds

# write simulation time to profiles and timeseries
profile_t = ds.group["profiles"]["t"]
@inbounds profile_t[end + 1] = t::Float64
@inbounds profile_t[end + 1] = t::FT
ts_t = ds.group["timeseries"]["t"]
@inbounds ts_t[end + 1] = t::Float64
@inbounds ts_t[end + 1] = t::FT

# write profiles
for field in (aux.moisture_variables, aux.precip_variables)
Expand Down
8 changes: 4 additions & 4 deletions src/driveKiD/TimeStepping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
- simulation time `t_max`.
"""

mutable struct TimeStepping
dt::Float64
dt_io::Float64
t_max::Float64
mutable struct TimeStepping{FT <: Real}
dt::FT
dt_io::FT
t_max::FT
end
55 changes: 32 additions & 23 deletions src/driveKiD/tendency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ end
else
error("Unrecognized rain formation scheme")
end
S_qt_rain = -min(max(0, q.liq / dt), tmp)
S_qt_snow = -min(max(0, q.ice / dt), CM1.conv_q_ice_to_q_sno(microphys_params, q, ρ, T))
S_qt_rain = -min(max(FT(0), q.liq / dt), tmp)
S_qt_snow = -min(max(FT(0), q.ice / dt), CM1.conv_q_ice_to_q_sno(microphys_params, q, ρ, T))
S_q_rai -= S_qt_rain
S_q_sno -= S_qt_snow
S_q_tot += S_qt_rain + S_qt_snow
Expand All @@ -207,22 +207,26 @@ end
end

# accretion cloud water + rain
S_qr = min(max(0, q.liq / dt), tmp)
S_qr = min(max(FT(0), q.liq / dt), tmp)
S_q_rai += S_qr
S_q_tot -= S_qr
S_q_liq -= S_qr
#θ_liq_ice_tendency += S_qr / Π_m / c_pm * L_v0

# accretion cloud ice + snow
S_qs = min(max(0, q.ice / dt), CM1.accretion(microphys_params, CMT.IceType(), CMT.SnowType(), q.ice, q_sno, ρ))
S_qs =
min(max(FT(0), q.ice / dt), CM1.accretion(microphys_params, CMT.IceType(), CMT.SnowType(), q.ice, q_sno, ρ))
S_q_sno += S_qs
S_q_tot -= S_qs
S_q_ice -= S_qs
#θ_liq_ice_tendency += S_qs / Π_m / c_pm * L_s0

# sink of cloud water via accretion cloud water + snow
S_qt =
-min(max(0, q.liq / dt), CM1.accretion(microphys_params, CMT.LiquidType(), CMT.SnowType(), q.liq, q_sno, ρ))
-min(
max(FT(0), q.liq / dt),
CM1.accretion(microphys_params, CMT.LiquidType(), CMT.SnowType(), q.liq, q_sno, ρ),
)
if T < T_fr # cloud droplets freeze to become snow)
S_q_sno -= S_qt
S_q_tot += S_qt
Expand All @@ -238,9 +242,13 @@ end
end

# sink of cloud ice via accretion cloud ice - rain
S_qt = -min(max(0, q.ice / dt), CM1.accretion(microphys_params, CMT.IceType(), CMT.RainType(), q.ice, q_rai, ρ))
S_qt =
-min(
max(FT(0), q.ice / dt),
CM1.accretion(microphys_params, CMT.IceType(), CMT.RainType(), q.ice, q_rai, ρ),
)
# sink of rain via accretion cloud ice - rain
S_qr = -min(max(0, q_rai / dt), CM1.accretion_rain_sink(microphys_params, q.ice, q_rai, ρ))
S_qr = -min(max(FT(0), q_rai / dt), CM1.accretion_rain_sink(microphys_params, q.ice, q_rai, ρ))
S_q_tot += S_qt
S_q_ice += S_qt
S_q_rai += S_qr
Expand All @@ -250,13 +258,13 @@ end
# accretion rain - snow
if T < T_fr
S_qs = min(
max(0, q_rai / dt),
max(FT(0), q_rai / dt),
CM1.accretion_snow_rain(microphys_params, CMT.SnowType(), CMT.RainType(), q_sno, q_rai, ρ),
)
else
S_qs =
-min(
max(0, q_sno / dt),
max(FT(0), q_sno / dt),
CM1.accretion_snow_rain(microphys_params, CMT.RainType(), CMT.SnowType(), q_rai, q_sno, ρ),
)
end
Expand All @@ -267,22 +275,23 @@ end

if Bool(params.precip_sinks)
# evaporation
S_qr = -min(max(0, q_rai / dt), -CM1.evaporation_sublimation(microphys_params, CMT.RainType(), q, q_rai, ρ, T))
S_qr =
-min(max(FT(0), q_rai / dt), -CM1.evaporation_sublimation(microphys_params, CMT.RainType(), q, q_rai, ρ, T))
S_q_rai += S_qr
S_q_tot -= S_qr
S_q_vap -= S_qr

# melting
S_qs = -min(max(0, q_sno / dt), CM1.snow_melt(microphys_params, q_sno, ρ, T))
S_qs = -min(max(FT(0), q_sno / dt), CM1.snow_melt(microphys_params, q_sno, ρ, T))
S_q_rai -= S_qs
S_q_sno += S_qs

# deposition, sublimation
tmp = CM1.evaporation_sublimation(microphys_params, CMT.SnowType(), q, q_sno, ρ, T)
if tmp > 0
S_qs = min(max(0, q_vap / dt), tmp)
S_qs = min(max(FT(0), q_vap / dt), tmp)
else
S_qs = -min(max(0, q_sno / dt), -tmp)
S_qs = -min(max(FT(0), q_sno / dt), -tmp)
end
S_q_sno += S_qs
S_q_tot -= S_qs
Expand Down Expand Up @@ -320,43 +329,43 @@ end

# autoconversion liquid to rain
tmp = CM2.autoconversion(microphys_params, rf, q.liq, q_rai, ρ, N_liq)
S_qr = min(max(0, q.liq / dt), tmp.dq_rai_dt)
S_qr = min(max(FT(0), q.liq / dt), tmp.dq_rai_dt)
S_q_rai += S_qr
S_q_tot -= S_qr
S_q_liq -= S_qr
S_Nr = min(max(0, N_liq / 2 / dt), tmp.dN_rai_dt)
S_Nr = min(max(FT(0), N_liq / 2 / dt), tmp.dN_rai_dt)
S_N_rai += S_Nr
S_N_liq -= 2 * S_Nr

# self_collection
tmp_l = CM2.liquid_self_collection(microphys_params, rf, q.liq, ρ, -S_qr)
tmp_r = CM2.rain_self_collection(microphys_params, rf, q_rai, ρ, N_rai)
S_N_liq += -min(max(0, N_liq / dt), -tmp_l)
S_N_rai += -min(max(0, N_rai / dt), -tmp_r)
S_N_liq += -min(max(FT(0), N_liq / dt), -tmp_l)
S_N_rai += -min(max(FT(0), N_rai / dt), -tmp_r)

# rain breakup
tmp = CM2.rain_breakup(microphys_params, rf, q_rai, ρ, N_rai, tmp_r)
S_N_rai += min(max(0, N_rai / dt), tmp_r)
S_N_rai += min(max(FT(0), N_rai / dt), tmp_r)

# accretion cloud water + rain
tmp = CM2.accretion(microphys_params, rf, q.liq, q_rai, ρ, N_liq)
S_qr = min(max(0, q.liq / dt), tmp.dq_rai_dt)
S_qr = min(max(FT(0), q.liq / dt), tmp.dq_rai_dt)
S_q_rai += S_qr
S_q_tot -= S_qr
S_q_liq -= S_qr
S_N_liq += -min(max(0, N_liq / dt), -tmp.dN_liq_dt)
S_N_liq += -min(max(FT(0), N_liq / dt), -tmp.dN_liq_dt)
S_N_rai += FT(0)

# evaporation
tmp = CM2.rain_evaporation(microphys_params, rf, q, q_rai, ρ, N_rai, T)
S_Nr = -min(max(0, N_rai / dt), -tmp[1])
S_qr = -min(max(0, q_rai / dt), -tmp[2])
S_Nr = -min(max(FT(0), N_rai / dt), -tmp[1])
S_qr = -min(max(FT(0), q_rai / dt), -tmp[2])
S_q_rai += S_qr
S_q_tot -= S_qr
S_q_vap -= S_qr
S_N_rai += S_Nr

vt = CM2.rain_terminal_velocity(microphys_params, CMT.SB2006Type(), q_rai, ρ, N_rai)
vt = CM2.rain_terminal_velocity(microphys_params, rf, q_rai, ρ, N_rai)
term_vel_N_rai = vt[1]
term_vel_rai = vt[2]

Expand Down
3 changes: 2 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CloudMicrophysics = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
EnsembleKalmanProcesses = "aa8a2aa5-91d8-4396-bcef-d4f2ec43552d"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Kinematic1D = "a8a3bb05-6cc5-4342-abf6-5cc636bd2b35"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -27,7 +28,7 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
CLIMAParameters = "0.7"
ClimaCore = "0.10"
ClimaCorePlots = "0.2"
CloudMicrophysics = "0.10"
CloudMicrophysics = "0.11.1"
DiffEqBase = "6.75"
NCDatasets = "0.12"
Plots = "1.29"
Expand Down
Loading

0 comments on commit a7c67a7

Please sign in to comment.