Skip to content

Commit

Permalink
Merge pull request #341 from CliMA/aj/gpu_kwargs
Browse files Browse the repository at this point in the history
Get rid of kwargs for ClimaAtmos GPU
  • Loading branch information
trontrytel authored Feb 28, 2024
2 parents e871fef + 053b9f9 commit 66f4b8a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CloudMicrophysics"
uuid = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
authors = ["Climate Modeling Alliance"]
version = "0.16.0"
version = "0.17.0"

[deps]
CLIMAParameters = "6eacf6c3-8458-43b9-ae03-caf5306d3d53"
Expand Down
8 changes: 4 additions & 4 deletions docs/src/guides/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ const LD2004 = CMP.LD2004(FT) # Liu and Daum (2004)
qₗ = FT(1e-3)
ρₐ = FT(1)
N = FT(1e8)
KK2000_rate = CM2.conv_q_liq_to_q_rai(KK2000, qₗ, ρₐ, N_d = N)
TC1980_rate = CM2.conv_q_liq_to_q_rai(TC1980, qₗ, ρₐ, N_d = N)
LD2004_rate = CM2.conv_q_liq_to_q_rai(LD2004, qₗ, ρₐ, N_d = N)
B1994_rate = CM2.conv_q_liq_to_q_rai(B1994, qₗ, ρₐ, N_d = N)
KK2000_rate = CM2.conv_q_liq_to_q_rai(KK2000, qₗ, ρₐ, N)
TC1980_rate = CM2.conv_q_liq_to_q_rai(TC1980, qₗ, ρₐ, N)
LD2004_rate = CM2.conv_q_liq_to_q_rai(LD2004, qₗ, ρₐ, N)
B1994_rate = CM2.conv_q_liq_to_q_rai(B1994, qₗ, ρₐ, N)

@info("Autoconversion: ", KK2000_rate, B1994_rate, TC1980_rate, LD2004_rate)
46 changes: 18 additions & 28 deletions docs/src/plots/Microphysics2M_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,40 @@ q_rai_range = range(1e-8, stop = 1e-3, length = 1000)
N_d_range = range(1e7, stop = 1e9, length = 1000)
q_liq = 5e-4
q_rai = 5e-4
N_d = 1e8
ρ_air = 1.0 # kg m^-3

q_liq_KK2000 = [
CM2.conv_q_liq_to_q_rai(KK2000, q_liq, ρ_air, N_d = 1e8) for
q_liq in q_liq_range
]
q_liq_B1994 = [
CM2.conv_q_liq_to_q_rai(B1994, q_liq, ρ_air, N_d = 1e8) for
q_liq in q_liq_range
CM2.conv_q_liq_to_q_rai(KK2000, q_liq, ρ_air, N_d) for q_liq in q_liq_range
]
q_liq_B1994 =
[CM2.conv_q_liq_to_q_rai(B1994, q_liq, ρ_air, N_d) for q_liq in q_liq_range]
q_liq_TC1980 = [
CM2.conv_q_liq_to_q_rai(TC1980, q_liq, ρ_air, N_d = 1e8) for
q_liq in q_liq_range
CM2.conv_q_liq_to_q_rai(TC1980, q_liq, ρ_air, N_d) for q_liq in q_liq_range
]
q_liq_LD2004 = [
CM2.conv_q_liq_to_q_rai(LD2004, q_liq, ρ_air, N_d = 1e8) for
q_liq in q_liq_range
CM2.conv_q_liq_to_q_rai(LD2004, q_liq, ρ_air, N_d) for q_liq in q_liq_range
]
q_liq_VarTimeScaleAcnv = [
CM2.conv_q_liq_to_q_rai(VarTSc, q_liq, ρ_air, N_d = 1e8) for
q_liq in q_liq_range
CM2.conv_q_liq_to_q_rai(VarTSc, q_liq, ρ_air, N_d) for q_liq in q_liq_range
]
q_liq_SB2006 = [
CM2.autoconversion(SB2006.acnv, q_liq, q_rai, ρ_air, 1e8).dq_rai_dt for
CM2.autoconversion(SB2006.acnv, q_liq, q_rai, ρ_air, N_d).dq_rai_dt for
q_liq in q_liq_range
]
q_liq_K1969 =
[CM1.conv_q_liq_to_q_rai(rain.acnv1M, q_liq) for q_liq in q_liq_range]

N_d_KK2000 = [
CM2.conv_q_liq_to_q_rai(KK2000, 5e-4, ρ_air, N_d = N_d) for N_d in N_d_range
]
N_d_B1994 = [
CM2.conv_q_liq_to_q_rai(B1994, 5e-4, ρ_air, N_d = N_d) for N_d in N_d_range
]
N_d_TC1980 = [
CM2.conv_q_liq_to_q_rai(TC1980, 5e-4, ρ_air, N_d = N_d) for N_d in N_d_range
]
N_d_LD2004 = [
CM2.conv_q_liq_to_q_rai(LD2004, 5e-4, ρ_air, N_d = N_d) for N_d in N_d_range
]
N_d_VarTimeScaleAcnv = [
CM2.conv_q_liq_to_q_rai(VarTSc, 5e-4, ρ_air, N_d = N_d) for N_d in N_d_range
]
N_d_KK2000 =
[CM2.conv_q_liq_to_q_rai(KK2000, q_liq, ρ_air, N_d) for N_d in N_d_range]
N_d_B1994 =
[CM2.conv_q_liq_to_q_rai(B1994, q_liq, ρ_air, N_d) for N_d in N_d_range]
N_d_TC1980 =
[CM2.conv_q_liq_to_q_rai(TC1980, q_liq, ρ_air, N_d) for N_d in N_d_range]
N_d_LD2004 =
[CM2.conv_q_liq_to_q_rai(LD2004, q_liq, ρ_air, N_d) for N_d in N_d_range]
N_d_VarTimeScaleAcnv =
[CM2.conv_q_liq_to_q_rai(VarTSc, q_liq, ρ_air, N_d) for N_d in N_d_range]
N_d_SB2006 = [
CM2.autoconversion(SB2006.acnv, q_liq, q_rai, ρ_air, N_d).dq_rai_dt for
N_d in N_d_range
Expand Down
37 changes: 19 additions & 18 deletions docs/src/plots/Thersholds_transitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,37 @@ end
q_liq_range = range(1e-8, stop = 1.5e-3, length = 1000)
N_d_range = range(1e7, stop = 1e9, length = 1000)
ρ_air = 1.0 # kg m^-3
N_d = 1e8

q_liq_K1969 =
[CM1.conv_q_liq_to_q_rai(rain[1].acnv1M, q_liq) for q_liq in q_liq_range]
q_liq_K1969_s = [
CM1.conv_q_liq_to_q_rai(rain[1].acnv1M, q_liq, smooth_transition = true) for q_liq in q_liq_range
CM1.conv_q_liq_to_q_rai(rain[1].acnv1M, q_liq, true) for
q_liq in q_liq_range
]

q_liq_TC1980 =
[CM2.conv_q_liq_to_q_rai(TC1980[2], q_liq, ρ_air) for q_liq in q_liq_range]
q_liq_TC1980 = [
CM2.conv_q_liq_to_q_rai(TC1980[2], q_liq, ρ_air, N_d) for
q_liq in q_liq_range
]
q_liq_TC1980_s = [
CM2.conv_q_liq_to_q_rai(TC1980[2], q_liq, ρ_air, smooth_transition = true) for q_liq in q_liq_range
CM2.conv_q_liq_to_q_rai(TC1980[2], q_liq, ρ_air, N_d, true) for
q_liq in q_liq_range
]
q_liq_LD2004 = [
CM2.conv_q_liq_to_q_rai(LD2004[2], q_liq, ρ_air, N_d) for
q_liq in q_liq_range
]
q_liq_LD2004 =
[CM2.conv_q_liq_to_q_rai(LD2004[2], q_liq, ρ_air) for q_liq in q_liq_range]
q_liq_LD2004_s = [
CM2.conv_q_liq_to_q_rai(LD2004[2], q_liq, ρ_air, smooth_transition = true) for q_liq in q_liq_range
CM2.conv_q_liq_to_q_rai(LD2004[2], q_liq, ρ_air, N_d, true) for
q_liq in q_liq_range
]

N_d_B1994 = [
CM2.conv_q_liq_to_q_rai(B1994[3], 5e-4, ρ_air, N_d = N_d) for
N_d in N_d_range
]
N_d_B1994 =
[CM2.conv_q_liq_to_q_rai(B1994[3], 5e-4, ρ_air, N_d) for N_d in N_d_range]
N_d_B1994_s = [
CM2.conv_q_liq_to_q_rai(
B1994[3],
5e-4,
ρ_air,
N_d = N_d,
smooth_transition = true,
) for N_d in N_d_range
CM2.conv_q_liq_to_q_rai(B1994[3], 5e-4, ρ_air, N_d, true) for
N_d in N_d_range
]

PL.plot(
Expand Down
4 changes: 2 additions & 2 deletions src/Microphysics1M.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Returns the q_rai tendency due to collisions between cloud droplets
"""
conv_q_liq_to_q_rai(
(; τ, q_threshold, k)::CMP.Acnv1M{FT},
q_liq::FT;
q_liq::FT,
smooth_transition::Bool = false,
) where {FT} =
smooth_transition ?
Expand All @@ -229,7 +229,7 @@ simulations where there is no supersaturation
"""
conv_q_ice_to_q_sno_no_supersat(
(; τ, q_threshold, k)::CMP.Acnv1M{FT},
q_ice::FT;
q_ice::FT,
smooth_transition::Bool = false,
) where {FT} =
smooth_transition ?
Expand Down
27 changes: 10 additions & 17 deletions src/Microphysics2M.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ end
# - variable timescale autoconversion Azimi (2023)

"""
conv_q_liq_to_q_rai(acnv, q_liq, ρ; N_d, smooth_transition)
conv_q_liq_to_q_rai(acnv, q_liq, ρ, N_d; smooth_transition)
- `acnv` - 2-moment rain autoconversion parameterization
- `q_liq` - cloud water specific humidity
Expand All @@ -469,28 +469,21 @@ Returns the q_rai tendency due to collisions between cloud droplets
- Tripoli and Cotton (1980) for `scheme == TC1980Type`
- Liu and Daum (2004) for `scheme ==LD2004Type`
`N_d` is an optional argument with the default value of 100 cm-3
The `Beheng1994Type`, `TC1980Type` and `LD2004Type` of schemes
additionally accept `smooth_transition` flag that
smoothes their thershold behaviour if set to `true`.
The default value is `false`.
"""
function conv_q_liq_to_q_rai(
(; acnv)::CMP.KK2000{FT},
q_liq,
ρ;
N_d = FT(1e8),
) where {FT}
function conv_q_liq_to_q_rai((; acnv)::CMP.KK2000{FT}, q_liq, ρ, N_d) where {FT}
q_liq = max(0, q_liq)
(; A, a, b, c) = acnv
return A * q_liq^a * N_d^b * ρ^c
end
function conv_q_liq_to_q_rai(
(; acnv)::CMP.B1994{FT},
q_liq,
ρ;
N_d = FT(1e8),
ρ,
N_d,
smooth_transition = false,
) where {FT}
q_liq = max(0, q_liq)
Expand All @@ -508,8 +501,8 @@ end
function conv_q_liq_to_q_rai(
(; acnv)::CMP.TC1980{FT},
q_liq,
ρ;
N_d = FT(1e8),
ρ,
N_d,
smooth_transition = false,
) where {FT}
#TODO - The original paper is actually formulated for mixing ratios, not specific humidities
Expand All @@ -524,8 +517,8 @@ end
function conv_q_liq_to_q_rai(
(; ρ_w, R_6C_0, E_0, k)::CMP.LD2004{FT},
q_liq,
ρ;
N_d = FT(1e8),
ρ,
N_d,
smooth_transition = false,
) where {FT}
if q_liq <= eps(FT)
Expand All @@ -551,8 +544,8 @@ end
function conv_q_liq_to_q_rai(
(; τ, α)::CMP.VarTimescaleAcnv{FT},
q_liq::FT,
ρ::FT;
N_d::FT = FT(1e8),
ρ::FT,
N_d::FT,
) where {FT}
return max(0, q_liq) /* (N_d / 1e8)^α)
end
Expand Down
10 changes: 5 additions & 5 deletions test/gpu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ end
i = @index(Group, Linear)

@inbounds begin
output[1, i] = CM2.conv_q_liq_to_q_rai(VarTSc, ql[i], ρ[i], N_d = Nd[i])
output[2, i] = CM2.conv_q_liq_to_q_rai(LD2004, ql[i], ρ[i], N_d = Nd[i])
output[3, i] = CM2.conv_q_liq_to_q_rai(TC1980, ql[i], ρ[i], N_d = Nd[i])
output[4, i] = CM2.conv_q_liq_to_q_rai(B1994, ql[i], ρ[i], N_d = Nd[i])
output[5, i] = CM2.conv_q_liq_to_q_rai(KK2000, ql[i], ρ[i], N_d = Nd[i])
output[1, i] = CM2.conv_q_liq_to_q_rai(VarTSc, ql[i], ρ[i], Nd[i])
output[2, i] = CM2.conv_q_liq_to_q_rai(LD2004, ql[i], ρ[i], Nd[i])
output[3, i] = CM2.conv_q_liq_to_q_rai(TC1980, ql[i], ρ[i], Nd[i])
output[4, i] = CM2.conv_q_liq_to_q_rai(B1994, ql[i], ρ[i], Nd[i])
output[5, i] = CM2.conv_q_liq_to_q_rai(KK2000, ql[i], ρ[i], Nd[i])
end
end

Expand Down
26 changes: 14 additions & 12 deletions test/microphysics1M_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,15 @@ function test_microphysics1M(FT)
q_liq_small = FT(0.5) * q_liq_threshold
TT.@test CM1.conv_q_liq_to_q_rai(rain.acnv1M, q_liq_small) == FT(0)

TT.@test CM1.conv_q_liq_to_q_rai(
rain.acnv1M,
q_liq_small,
smooth_transition = true,
) FT(0.0) atol = 0.15 * q_liq_threshold / τ_acnv_rai
TT.@test CM1.conv_q_liq_to_q_rai(rain.acnv1M, q_liq_small, true)
FT(0.0) atol = 0.15 * q_liq_threshold / τ_acnv_rai

q_liq_big = FT(1.5) * q_liq_threshold
TT.@test CM1.conv_q_liq_to_q_rai(rain.acnv1M, q_liq_big)
FT(0.5) * q_liq_threshold / τ_acnv_rai

TT.@test CM1.conv_q_liq_to_q_rai(
rain.acnv1M,
q_liq_big,
smooth_transition = true,
) FT(0.5) * q_liq_threshold / τ_acnv_rai atol =
TT.@test CM1.conv_q_liq_to_q_rai(rain.acnv1M, q_liq_big, true)
FT(0.5) * q_liq_threshold / τ_acnv_rai atol =
FT(0.15) * q_liq_threshold / τ_acnv_rai

end
Expand All @@ -145,7 +139,7 @@ function test_microphysics1M(FT)
TT.@test CM1.conv_q_ice_to_q_sno_no_supersat(
snow.acnv1M,
q_ice_small,
smooth_transition = true,
true,
) FT(0.0) atol = FT(0.15) * q_ice_threshold / τ_acnv_sno

q_ice_big = FT(1.5) * q_ice_threshold
Expand All @@ -155,9 +149,17 @@ function test_microphysics1M(FT)
TT.@test CM1.conv_q_ice_to_q_sno_no_supersat(
snow.acnv1M,
q_ice_big,
smooth_transition = true,
true,
) FT(0.5) * q_ice_threshold / τ_acnv_sno atol =
FT(0.15) * q_ice_threshold / τ_acnv_sno

TT.@test CM1.conv_q_ice_to_q_sno_no_supersat(snow.acnv1M, q_ice_big) ==
CM1.conv_q_ice_to_q_sno_no_supersat(
snow.acnv1M,
q_ice_big,
false,
)

end

TT.@testset "SnowAutoconversion" begin
Expand Down
Loading

2 comments on commit 66f4b8a

@trontrytel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/101948

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.0 -m "<description of version>" 66f4b8a63cc769f36892844d41dbcd472f39e7b3
git push origin v0.17.0

Please sign in to comment.