Skip to content

Commit fe5b1c6

Browse files
committed
more wip on adding 2M scheme
1 parent 7460b9c commit fe5b1c6

File tree

1 file changed

+66
-56
lines changed

1 file changed

+66
-56
lines changed

src/parameterized_tendencies/microphysics/microphysics_wrappers.jl

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const Iₗ = TD.internal_energy_liquid
1111
const Iᵢ = TD.internal_energy_ice
1212
const Lf = TD.latent_heat_fusion
1313
const Tₐ = TD.air_temperature
14-
const PP = TD.PhasePartition
1514
const qᵥ = TD.vapor_specific_humidity
1615
qₜ(thp, ts) = TD.PhasePartition(thp, ts).tot
1716
qₗ(thp, ts) = TD.PhasePartition(thp, ts).liq
@@ -266,6 +265,7 @@ function compute_precipitation_sources!(
266265
end
267266
function compute_precipitation_sources2M!(
268267
Sᵖ,
268+
N_act,
269269
Sqₜᵖ,
270270
Sqᵣᵖ,
271271
SNᵣᵖ,
@@ -277,6 +277,8 @@ function compute_precipitation_sources2M!(
277277
Nₗ,
278278
ts,
279279
Φ,
280+
p,
281+
w,
280282
dt,
281283
mp,
282284
thp,
@@ -291,68 +293,76 @@ function compute_precipitation_sources2M!(
291293
@. Seₜᵖ = ρ * FT(0)
292294

293295
#! format: off
294-
# rain autoconversion: q_liq -> q_rain
296+
297+
# TODO - only do activation at cloud base
298+
@. Sᵖ = TD.supersaturation(thp, PP(thp, ts), ρ, Tₐ(thp, ts), TD.Liquid())
299+
# TODO - pass in background aerosol as parameters
300+
r_dry = FT(0.1 * 1e-6)
301+
std_dry = FT(1.1)
302+
κ = FT(1.2)
303+
N_aer = FT(1000 * 1e6)
304+
@. N_act = CMAA.total_N_activated(
305+
activation_params,
306+
CMAM.AerosolDistribution(
307+
(CMAM.Mode_κ(r_dry, std_dry, N_aer, (FT(1),), (FT(1),), (FT(0),), (κ,)),)
308+
)
309+
mp.aps,
310+
thp,
311+
Tₐ(thp, ts),
312+
p,
313+
w,
314+
PP(thp, ts),
315+
)
316+
# Convert the total activated number to tendency
317+
@. SNₗᵖ = ifelse(Sᵖ < 0 || isnan(N_act), FT(0), max(FT(0), N_act - Nₗ) / dt)
318+
319+
# autoconversion liquid to rain (mass)
295320
@. Sᵖ = min(
296321
limit(qₗ(thp, ts), dt, 5),
297-
CM1.conv_q_liq_to_q_rai(mp.pr.acnv1M, qₗ(thp, ts), true),
322+
CM2.autoconversion(mp.sb2006.acnv, qₗ(thp, ts), qᵣ, ρ, Nₗ).dq_rai_dt,
298323
)
299324
@. Sqₜᵖ -= Sᵖ
300325
@. Sqᵣᵖ += Sᵖ
301326
@. Seₜᵖ -= Sᵖ * (Iₗ(thp, ts) + Φ)
302327

303-
#TODO - add sources
304-
# # autoconversion liquid to rain (mass)
305-
# @. S₁ = limit(q_liq, dt, CM2.autoconversion(sb2006.acnv, q_liq, q_rai, ρ, N_liq).dq_rai_dt)
306-
# @. aux.precip_sources += to_sources(-S₁, -S₁, S₁, 0, 0, 0)
307-
308-
309-
310-
# TODO - only do activation at cloud base
311-
#FT = eltype(q_tot)
312-
#S_Nl::FT = FT(0)
313-
314-
#q = TD.PhasePartition(q_tot, q_liq, q_ice)
315-
#S::FT = TD.supersaturation(thermo_params, q, ρ, T, TD.Liquid())
316-
317-
#(; r_dry, std_dry, κ) = kid_params
318-
#w = ρw / ρ
319-
320-
#aerosol_distribution =
321-
# CMAM.AerosolDistribution((CMAM.Mode_κ(r_dry, std_dry, N_aer, (FT(1),), (FT(1),), (FT(0),), (κ,)),))
322-
#N_act = CMAA.total_N_activated(activation_params, aerosol_distribution, air_params, thermo_params, T, p, w, q)
323-
324-
## Convert the total activated number to tendency
325-
#S_Nl = ifelse(S < 0 || isnan(N_act), FT(0), max(FT(0), N_act - N_liq) / dt)
326-
327-
328-
329-
330-
# # autoconversion liquid to rain (number)
331-
# @. S₂ = limit(N_liq, dt, CM2.autoconversion(sb2006.acnv, q_liq, q_rai, ρ, N_liq).dN_rai_dt, 2)
332-
# @. aux.precip_sources += to_sources(0, 0, 0, 0, -2 * S₂, S₂)
333-
# # liquid self_collection
334-
# @. S₁ = -limit(N_liq, dt, -CM2.liquid_self_collection(sb2006.acnv, q_liq, ρ, -2 * S₂))
335-
# @. aux.precip_sources += to_sources(0, 0, 0, 0, S₁, 0)
336-
337-
# # rain self_collection
338-
# @. S₁ = CM2.rain_self_collection(sb2006.pdf_r, sb2006.self, q_rai, ρ, N_rai)
339-
# @. aux.precip_sources += to_sources(0, 0, 0, 0, 0, -limit(N_rai, dt, -S₁))
340-
# # rain breakup
341-
# @. aux.precip_sources += to_sources(
342-
# 0,
343-
# 0,
344-
# 0,
345-
# 0,
346-
# 0,
347-
# limit(N_rai, dt, CM2.rain_breakup(sb2006.pdf_r, sb2006.brek, q_rai, ρ, N_rai, S₁)),
348-
# )
349-
350-
# # accretion cloud water + rain
351-
# @. S₁ = limit(q_liq, dt, CM2.accretion(sb2006, q_liq, q_rai, ρ, N_liq).dq_rai_dt)
352-
# @. S₂ = -limit(N_liq, dt, -CM2.accretion(sb2006, q_liq, q_rai, ρ, N_liq).dN_liq_dt)
353-
# @. aux.precip_sources += to_sources(-S₁, -S₁, S₁, 0, S₂, 0)
328+
# autoconversion liquid to rain (number)
329+
@. Sᵖ = min(
330+
limit(Nₗ, dt, 5),
331+
CM2.autoconversion(mp.sb2006.acnv, qₗ(thp, ts), qᵣ, ρ, Nₗ).dN_rai_dt,
332+
)
333+
@. SNₗᵖ -= 2 * Sᵖ
334+
@. SNᵣᵖ += Sᵖ
335+
# liquid self_collection
336+
@. SNₗᵖ -= min(
337+
limit(Nₗ, dt, 5),
338+
-CM2.liquid_self_collection(mp.sb2006.acnv, qₗ, ρ, -2 * Sᵖ),
339+
)
354340

341+
# rain self_collection
342+
@. Sᵖ = -min(
343+
limit(Nᵣ, dt, 5),
344+
-CM2.rain_self_collection(mp.sb2006.pdf_r, mp.sb2006.self, qᵣ, ρ, Nᵣ),
345+
)
346+
@. SNᵣᵖ += Sᵖ
347+
# rain breakup
348+
@. SNᵣᵖ += min(
349+
limit(Nᵣ, dt, 5),
350+
CM2.rain_breakup(mp.sb2006.pdf_r, mp.sb2006.brek, qᵣ, ρ, Nᵣ, Sᵖ),
351+
)
355352

353+
# accretion cloud water + rain
354+
@. Sᵖ = min(
355+
limit(qₗ(thp, ts), dt, 5),
356+
CM2.accretion(mp.sb2006, qₗ(thp, ts), qᵣ, ρ, Nₗ).dq_rai_dt
357+
)
358+
@. Sqₜᵖ -= Sᵖ
359+
@. Sqᵣᵖ += Sᵖ
360+
@. Seₜᵖ -= Sᵖ * (Iₗ(thp, ts) + Φ)
361+
@. Sᵖ = -min(
362+
limit(Nₗ, dt, 5),
363+
-CM2.accretion(mp.sb2006, qₗ(thp, ts), qᵣ, ρ, Nₗ).dN_liq_dt,
364+
)
365+
@. SNₗᵖ += Sᵖ
356366
end
357367

358368
"""
@@ -517,7 +527,7 @@ function compute_precipitation_sinks2M!(
517527
# evaporation: q_rai -> q_vap (mass)
518528
@. Sᵖ = -min(
519529
limit(qᵣ, dt, 5),
520-
-CM2.rain_evaporation(rps..., PP(thp, ts), qᵣ, ρ, Nᵣ, Tₐ(thp.ts)).evap_rate_1,
530+
-CM2.rain_evaporation(rps..., PP(thp, ts), qᵣ, ρ, Nᵣ, Tₐ(thp, ts)).evap_rate_1,
521531
)
522532
@. Sqₜᵖ -= Sᵖ
523533
@. Sqᵣᵖ += Sᵖ
@@ -526,7 +536,7 @@ function compute_precipitation_sinks2M!(
526536
# evaporation: q_rai -> q_vap (number)
527537
@. Sᵖ = -min(
528538
limit(Nᵣ, dt, 5),
529-
-CM2.rain_evaporation(rps..., PP(thp, ts), qᵣ, ρ, Nᵣ, Tₐ(thp.ts)).evap_rate_0,
539+
-CM2.rain_evaporation(rps..., PP(thp, ts), qᵣ, ρ, Nᵣ, Tₐ(thp, ts)).evap_rate_0,
530540
)
531541
@. SNᵣᵖ += Sᵖ
532542
#! format: on

0 commit comments

Comments
 (0)