Skip to content

Commit 017a994

Browse files
committed
rft: improve parameter constructors
- add constructor using float type (e.g. Float32) for all param structs - remove explicit type declarations where not needed - clean up some constructors
1 parent 1a23646 commit 017a994

46 files changed

Lines changed: 510 additions & 906 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
name = "CloudMicrophysics"
22
uuid = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
3-
authors = ["Climate Modeling Alliance"]
43
version = "0.32"
4+
authors = ["Climate Modeling Alliance"]
55

66
[deps]
77
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
88
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
99
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
10+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1011
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
1112
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
1213
RootSolvers = "7181ea78-2dcb-4de3-ab41-2b8ab5a31e74"
@@ -27,6 +28,7 @@ ClimaParams = "1"
2728
DataFrames = "1.6"
2829
DocStringExtensions = "0.8, 0.9"
2930
ForwardDiff = "0.10, 1"
31+
InteractiveUtils = "1"
3032
LazyArtifacts = "1"
3133
LogExpFunctions = "0.3.29"
3234
MLJ = "0.20"

docs/src/API.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ P3Scheme
128128
## Construct parameterization set
129129

130130
```@docs
131-
CMP.ParametersP3{Float64}
132-
CMP.ParametersP3(::Float64)
133-
CMP.ParametersP3(::Parameters.CP.ParamDict)
131+
CMP.ParametersP3
134132
```
135133

136134
### Sub-parameterizations

docs/src/plots/CloudDiagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ override_file = joinpath(
2424
)
2525
toml_dict = CP.create_toml_dict(FT; override_file)
2626
SB = CMP.SB2006(toml_dict)
27-
SB_no_limiters = CMP.SB2006(toml_dict, false)
27+
SB_no_limiters = CMP.SB2006(toml_dict; is_limited = false)
2828

2929
ρ_air = FT(1)
3030

docs/src/plots/TerminalVelocity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const ice = CMP.CloudIce(FT)
1717
const snow = CMP.Snow(FT)
1818

1919
const SB2006 = CMP.SB2006(FT)
20-
const SB2006_no_lim = CMP.SB2006(FT, false)
20+
const SB2006_no_lim = CMP.SB2006(FT; is_limited = false)
2121

2222
const Chen2022 = CMP.Chen2022VelType(FT)
2323
const STVel = CMP.StokesRegimeVelType(FT)

docs/src/plots/TerminalVelocity2M.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ FT = Float64
99

1010
const rain = CMP.Rain(FT)
1111
const SB2006 = CMP.SB2006(FT)
12-
const SB2006_no_lim = CMP.SB2006(FT, false)
12+
const SB2006_no_lim = CMP.SB2006(FT; is_limited = false)
1313
const SB2006Vel = CMP.SB2006VelType(FT)
1414

1515
ρ_air = 1.2

parcel/ParcelDistributions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import CloudMicrophysics.Parameters as CMP
22

3-
struct Monodisperse{FT} <: CMP.ParametersType{FT} end
3+
struct Monodisperse <: CMP.ParametersType end
44

5-
struct MonodisperseMix{FT} <: CMP.ParametersType{FT} end
5+
struct MonodisperseMix <: CMP.ParametersType end
66

7-
struct Gamma{FT} <: CMP.ParametersType{FT} end
7+
struct Gamma <: CMP.ParametersType end
88

99
#! format: off
1010
# Size distributiom moments

parcel/ParcelModel.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include(joinpath(pkgdir(CM), "parcel", "ParcelParameters.jl"))
88
"""
99
Parcel simulation parameters
1010
"""
11-
Base.@kwdef struct parcel_params{FT} <: CMP.ParametersType{FT}
11+
Base.@kwdef struct parcel_params{FT} <: CMP.ParametersType
1212
prescribed_thermodynamics = false
1313
t_profile = []
1414
T_profile = []
@@ -21,7 +21,7 @@ Base.@kwdef struct parcel_params{FT} <: CMP.ParametersType{FT}
2121
deposition_growth = "None"
2222
liq_size_distribution = "Monodisperse"
2323
ice_size_distribution = "Monodisperse"
24-
aerosol = Empty{FT}()
24+
aerosol = Empty()
2525
aero_σ_g = FT(0)
2626
wps = CMP.WaterProperties(FT)
2727
aps = CMP.AirProperties(FT)
@@ -102,7 +102,7 @@ function parcel_model(dY, Y, p, t)
102102
qₗ_mode1 = Y[11]
103103
Nₗ_mode1 = Y[12]
104104
_tmp_state = merge(state, (; qₗ = qₗ_mode1, Nₗ = Nₗ_mode1))
105-
PSD_liq_mode1 = distribution_moments(Monodisperse{FT}(), qₗ_mode1, Nₗ_mode1, ρₗ, ρ_air)
105+
PSD_liq_mode1 = distribution_moments(Monodisperse(), qₗ_mode1, Nₗ_mode1, ρₗ, ρ_air)
106106
dqₗ_mode1_dt = condensation(ce_params, PSD_liq_mode1, _tmp_state, ρ_air)
107107
dNₗ_mode1_dt =
108108
dqₗ_mode1_dt < FT(0) && qₗ_mode1 > FT(0) && qₗ_mode1 < FT(1e-6) ? Nₗ_mode1 * dqₗ_mode1_dt / qₗ_mode1 : FT(0)
@@ -231,20 +231,20 @@ function run_parcel(IC, t_0, t_end, pp)
231231

232232
info = "\nSize distribution (liq): $(pp.liq_size_distribution)\n"
233233
if pp.liq_size_distribution == "Monodisperse"
234-
liq_distr = Monodisperse{FT}()
234+
liq_distr = Monodisperse()
235235
elseif pp.liq_size_distribution == "Gamma"
236-
liq_distr = Gamma{FT}()
236+
liq_distr = Gamma()
237237
elseif pp.liq_size_distribution == "MonodisperseMix"
238-
liq_distr = MonodisperseMix{FT}()
238+
liq_distr = MonodisperseMix()
239239
else
240240
throw("Unrecognized size distribution")
241241
end
242242

243243
info *= "Size distribution (ice): $(pp.ice_size_distribution)\n"
244244
if pp.ice_size_distribution == "Monodisperse"
245-
ice_distr = Monodisperse{FT}()
245+
ice_distr = Monodisperse()
246246
elseif pp.ice_size_distribution == "Gamma"
247-
ice_distr = Gamma{FT}()
247+
ice_distr = Gamma()
248248
else
249249
throw("Unrecognized size distribution")
250250
end
@@ -253,7 +253,7 @@ function run_parcel(IC, t_0, t_end, pp)
253253

254254
info *= "Aerosol Activation: $(pp.aerosol_act)\n"
255255
if pp.aerosol_act == "None"
256-
aero_act_params = Empty{FT}()
256+
aero_act_params = Empty()
257257
elseif pp.aerosol_act == "AeroAct"
258258
aero_act_params =
259259
AeroAct{FT}(pp.aap, pp.aerosol, pp.aero_σ_g, pp.r_nuc, pp.const_dt, pp.Nₐ)
@@ -263,7 +263,7 @@ function run_parcel(IC, t_0, t_end, pp)
263263

264264
info *= "Deposition: $(pp.deposition)\n"
265265
if pp.deposition == "None"
266-
dep_params = Empty{FT}()
266+
dep_params = Empty()
267267
elseif pp.deposition == "MohlerAF"
268268
dep_params = MohlerAF{FT}(pp.ips, pp.aerosol, pp.tps, pp.const_dt)
269269
elseif pp.deposition == "MohlerRate"
@@ -278,7 +278,7 @@ function run_parcel(IC, t_0, t_end, pp)
278278

279279
info *= "Heterogeneous: $(pp.heterogeneous)\n"
280280
if pp.heterogeneous == "None"
281-
imm_params = Empty{FT}()
281+
imm_params = Empty()
282282
elseif pp.heterogeneous == "ABIFM"
283283
imm_params = ABIFM{FT}(pp.tps, pp.aerosol, pp.A_aer, pp.const_dt)
284284
elseif pp.heterogeneous == "P3_het"
@@ -296,7 +296,7 @@ function run_parcel(IC, t_0, t_end, pp)
296296

297297
info *= "Homogeneous: $(pp.homogeneous)\n"
298298
if pp.homogeneous == "None"
299-
hom_params = Empty{FT}()
299+
hom_params = Empty()
300300
elseif pp.homogeneous == "ABHOM"
301301
hom_params = ABHOM{FT}(pp.tps, pp.ips, pp.const_dt)
302302
elseif pp.homogeneous == "P3_hom"
@@ -307,7 +307,7 @@ function run_parcel(IC, t_0, t_end, pp)
307307

308308
info *= "Condensation growth: $(pp.condensation_growth)\n"
309309
if pp.condensation_growth == "None"
310-
ce_params = Empty{FT}()
310+
ce_params = Empty()
311311
elseif pp.condensation_growth == "Condensation"
312312
ce_params = CondParams{FT}(pp.aps, pp.tps, pp.const_dt)
313313
elseif pp.condensation_growth == "NonEq_Condensation_simple"
@@ -320,7 +320,7 @@ function run_parcel(IC, t_0, t_end, pp)
320320

321321
info *= "Deposition growth: $(pp.deposition_growth)\n"
322322
if pp.deposition_growth == "None"
323-
ds_params = Empty{FT}()
323+
ds_params = Empty()
324324
elseif pp.deposition_growth == "Deposition"
325325
ds_params = DepParams{FT}(pp.aps, pp.tps, pp.const_dt)
326326
elseif pp.deposition_growth == "NonEq_Deposition_simple"

parcel/ParcelParameters.jl

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,111 @@
11
import CloudMicrophysics.Parameters as CMP
22
import CloudMicrophysics.ThermodynamicsInterface.TD.Parameters as TDP
33

4-
struct Empty{FT} <: CMP.ParametersType{FT} end
4+
struct Empty <: CMP.ParametersType end
55

6-
struct AeroAct{FT} <: CMP.ParametersType{FT}
7-
aap::CMP.ParametersType{FT}
8-
aerosol::CMP.AerosolType{FT}
6+
struct AeroAct{FT} <: CMP.ParametersType
7+
aap::CMP.ParametersType
8+
aerosol::CMP.AerosolType
99
aero_σ_g::FT
1010
r_nuc::FT
1111
const_dt::FT
1212
Nₐ::FT
1313
end
1414

15-
struct MohlerAF{FT} <: CMP.ParametersType{FT}
16-
ips::CMP.ParametersType{FT}
17-
aerosol::CMP.AerosolType{FT}
15+
struct MohlerAF{FT} <: CMP.ParametersType
16+
ips::CMP.ParametersType
17+
aerosol::CMP.AerosolType
1818
tps::TDP.ThermodynamicsParameters{FT}
1919
const_dt::FT
2020
end
2121

22-
struct MohlerRate{FT} <: CMP.ParametersType{FT}
23-
ips::CMP.ParametersType{FT}
24-
aerosol::CMP.AerosolType{FT}
22+
struct MohlerRate{FT} <: CMP.ParametersType
23+
ips::CMP.ParametersType
24+
aerosol::CMP.AerosolType
2525
tps::TDP.ThermodynamicsParameters{FT}
2626
const_dt::FT
2727
end
2828

29-
struct ABDINM{FT} <: CMP.ParametersType{FT}
29+
struct ABDINM{FT} <: CMP.ParametersType
3030
tps::TDP.ThermodynamicsParameters{FT}
31-
aerosol::CMP.AerosolType{FT}
31+
aerosol::CMP.AerosolType
3232
r_nuc::FT
3333
const_dt::FT
3434
end
3535

36-
struct P3_dep{FT} <: CMP.ParametersType{FT}
37-
ips::CMP.ParametersType{FT}
36+
struct P3_dep{FT} <: CMP.ParametersType
37+
ips::CMP.ParametersType
3838
const_dt::FT
3939
end
4040

41-
struct ABIFM{FT} <: CMP.ParametersType{FT}
41+
struct ABIFM{FT} <: CMP.ParametersType
4242
tps::TDP.ThermodynamicsParameters{FT}
43-
aerosol::CMP.AerosolType{FT}
43+
aerosol::CMP.AerosolType
4444
A_aer::FT
4545
const_dt::FT
4646
end
4747

48-
struct P3_het{FT} <: CMP.ParametersType{FT}
49-
ips::CMP.ParametersType{FT}
48+
struct P3_het{FT} <: CMP.ParametersType
49+
ips::CMP.ParametersType
5050
const_dt::FT
5151
end
5252

53-
struct Frostenberg_random{FT} <: CMP.ParametersType{FT}
54-
ip::CMP.ParametersType{FT}
53+
struct Frostenberg_random{FT} <: CMP.ParametersType
54+
ip::CMP.ParametersType
5555
sampling_interval::FT
5656
const_dt::FT
5757
end
5858

59-
struct Frostenberg_stochastic{FT} <: CMP.ParametersType{FT}
60-
ip::CMP.ParametersType{FT}
59+
struct Frostenberg_stochastic{FT} <: CMP.ParametersType
60+
ip::CMP.ParametersType
6161
γ::FT
6262
const_dt::FT
6363
end
6464

65-
struct Frostenberg_mean{FT} <: CMP.ParametersType{FT}
66-
ip::CMP.ParametersType{FT}
65+
struct Frostenberg_mean{FT} <: CMP.ParametersType
66+
ip::CMP.ParametersType
6767
const_dt::FT
6868
end
6969

70-
struct ABHOM{FT} <: CMP.ParametersType{FT}
70+
struct ABHOM{FT} <: CMP.ParametersType
7171
tps::TDP.ThermodynamicsParameters{FT}
72-
ips::CMP.ParametersType{FT}
72+
ips::CMP.ParametersType
7373
const_dt::FT
7474
end
7575

76-
struct P3_hom{FT} <: CMP.ParametersType{FT}
76+
struct P3_hom{FT} <: CMP.ParametersType
7777
const_dt::FT
7878
end
7979

80-
struct CondParams{FT} <: CMP.ParametersType{FT}
81-
aps::CMP.ParametersType{FT}
80+
struct CondParams{FT} <: CMP.ParametersType
81+
aps::CMP.ParametersType
8282
tps::TDP.ThermodynamicsParameters{FT}
8383
const_dt::FT
8484
end
8585

86-
struct NonEqCondParams_simple{FT} <: CMP.ParametersType{FT}
86+
struct NonEqCondParams_simple{FT} <: CMP.ParametersType
8787
tps::TDP.ThermodynamicsParameters{FT}
8888
liquid::CMP.CloudLiquid{FT}
8989
end
9090

91-
struct NonEqCondParams{FT} <: CMP.ParametersType{FT}
91+
struct NonEqCondParams{FT} <: CMP.ParametersType
9292
tps::TDP.ThermodynamicsParameters{FT}
9393
liquid::CMP.CloudLiquid{FT}
9494
dt::FT
9595
end
9696

97-
struct DepParams{FT} <: CMP.ParametersType{FT}
98-
aps::CMP.ParametersType{FT}
97+
struct DepParams{FT} <: CMP.ParametersType
98+
aps::CMP.ParametersType
9999
tps::TDP.ThermodynamicsParameters{FT}
100100
const_dt::FT
101101
end
102102

103-
struct NonEqDepParams_simple{FT} <: CMP.ParametersType{FT}
103+
struct NonEqDepParams_simple{FT} <: CMP.ParametersType
104104
tps::TDP.ThermodynamicsParameters{FT}
105105
ice::CMP.CloudIce{FT}
106106
end
107107

108-
struct NonEqDepParams{FT} <: CMP.ParametersType{FT}
108+
struct NonEqDepParams{FT} <: CMP.ParametersType
109109
tps::TDP.ThermodynamicsParameters{FT}
110110
ice::CMP.CloudIce{FT}
111111
dt::FT

src/BulkMicrophysicsTendencies.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ derivatives; snow and cloud formation derivatives are zero for now.
510510
"""
511511
@inline function bulk_microphysics_derivatives(
512512
::Microphysics2Moment,
513-
mp::CMP.Microphysics2MParams{FT, WR, ICE},
513+
mp::CMP.Microphysics2MParams{WR, ICE},
514514
tps,
515515
ρ,
516516
T,
@@ -521,7 +521,7 @@ derivatives; snow and cloud formation derivatives are zero for now.
521521
q_sno,
522522
n_lcl,
523523
n_rai,
524-
) where {FT, WR, ICE}
524+
) where {WR, ICE}
525525
ρ = UT.clamp_to_nonneg(ρ)
526526
q_tot = UT.clamp_to_nonneg(q_tot)
527527
q_lcl = UT.clamp_to_nonneg(q_lcl)
@@ -688,7 +688,7 @@ end
688688
"""
689689
bulk_microphysics_tendencies(
690690
::Microphysics2Moment,
691-
mp::Microphysics2MParams{FT, WR, Nothing},
691+
mp::Microphysics2MParams{WR, Nothing},
692692
...
693693
)
694694
@@ -720,7 +720,7 @@ For warm rain + P3 ice, see the method that accepts `Microphysics2MParams{FT, WR
720720
"""
721721
@inline function bulk_microphysics_tendencies(
722722
::Microphysics2Moment,
723-
mp::CMP.Microphysics2MParams{FT, WR, Nothing},
723+
mp::CMP.Microphysics2MParams{WR, Nothing},
724724
tps,
725725
ρ,
726726
T,
@@ -734,7 +734,7 @@ For warm rain + P3 ice, see the method that accepts `Microphysics2MParams{FT, WR
734734
q_rim = zero(ρ),
735735
b_rim = zero(ρ),
736736
logλ = zero(ρ),
737-
) where {FT, WR}
737+
) where {WR}
738738
# Clamp negative inputs to zero (robustness against numerical errors)
739739
ρ = UT.clamp_to_nonneg(ρ)
740740
q_tot = UT.clamp_to_nonneg(q_tot)
@@ -829,7 +829,7 @@ to be non-Nothing, eliminating runtime type checks and dynamic dispatch.
829829
"""
830830
@inline function bulk_microphysics_tendencies(
831831
::Microphysics2Moment,
832-
mp::CMP.Microphysics2MParams{FT, WR, ICE},
832+
mp::CMP.Microphysics2MParams{WR, ICE},
833833
tps,
834834
ρ,
835835
T,
@@ -843,7 +843,7 @@ to be non-Nothing, eliminating runtime type checks and dynamic dispatch.
843843
q_rim = zero(ρ),
844844
b_rim = zero(ρ),
845845
logλ = zero(ρ),
846-
) where {FT, WR, ICE <: CMP.P3IceParams}
846+
) where {WR, ICE <: CMP.P3IceParams}
847847
# Clamp negative inputs to zero (robustness against numerical errors)
848848
ρ = UT.clamp_to_nonneg(ρ)
849849
q_tot = UT.clamp_to_nonneg(q_tot)

0 commit comments

Comments
 (0)