Skip to content

Commit 99dce77

Browse files
Merge pull request #183 from CliMA/ck/inline_everything
Inlining everything
2 parents 805d172 + ecfb71d commit 99dce77

6 files changed

+357
-301
lines changed

src/Parameters.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ Base.eltype(::ThermodynamicsParameters{FT}) where {FT} = FT
5656

5757
# wrappers
5858
for fn in fieldnames(ATP)
59-
@eval $(fn)(ps::ATP) = ps.$(fn)
59+
@eval @inline $(fn)(ps::ATP) = ps.$(fn)
6060
end
6161

6262
# Derived parameters
63-
R_d(ps::ATP) = ps.gas_constant / ps.molmass_dryair
64-
R_v(ps::ATP) = ps.gas_constant / ps.molmass_water
65-
molmass_ratio(ps::ATP) = ps.molmass_dryair / ps.molmass_water
66-
LH_f0(ps::ATP) = ps.LH_s0 - ps.LH_v0
67-
e_int_v0(ps::ATP) = ps.LH_v0 - R_v(ps) * ps.T_0
68-
e_int_i0(ps::ATP) = LH_f0(ps)
69-
cp_d(ps::ATP) = R_d(ps) / ps.kappa_d
70-
cv_d(ps::ATP) = cp_d(ps) - R_d(ps)
71-
cv_v(ps::ATP) = ps.cp_v - R_v(ps)
72-
cv_l(ps::ATP) = ps.cp_l
73-
cv_i(ps::ATP) = ps.cp_i
63+
@inline R_d(ps::ATP) = ps.gas_constant / ps.molmass_dryair
64+
@inline R_v(ps::ATP) = ps.gas_constant / ps.molmass_water
65+
@inline molmass_ratio(ps::ATP) = ps.molmass_dryair / ps.molmass_water
66+
@inline LH_f0(ps::ATP) = ps.LH_s0 - ps.LH_v0
67+
@inline e_int_v0(ps::ATP) = ps.LH_v0 - R_v(ps) * ps.T_0
68+
@inline e_int_i0(ps::ATP) = LH_f0(ps)
69+
@inline cp_d(ps::ATP) = R_d(ps) / ps.kappa_d
70+
@inline cv_d(ps::ATP) = cp_d(ps) - R_d(ps)
71+
@inline cv_v(ps::ATP) = ps.cp_v - R_v(ps)
72+
@inline cv_l(ps::ATP) = ps.cp_l
73+
@inline cv_i(ps::ATP) = ps.cp_i
7474

7575
end

src/Thermodynamics.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ const APS = TP.ThermodynamicsParameters
6565
# Error on convergence must be the default
6666
# behavior because this can result in printing
6767
# very large logs resulting in CI to seemingly hang.
68-
error_on_non_convergence() = true
68+
@inline error_on_non_convergence() = true
6969

7070
# Allow users to skip printing warnings on non-convergence
71-
print_warning() = true
71+
@inline print_warning() = true
7272

7373
@inline q_pt_0(::Type{FT}) where {FT} = PhasePartition(FT(0), FT(0), FT(0))
7474

src/config_numerical_method.jl

+20-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# KA.@print only accepts literal strings, so we must
77
# branch to print which method is being used.
8-
function print_numerical_method(
8+
@inline function print_numerical_method(
99
::Type{sat_adjust_method},
1010
) where {sat_adjust_method}
1111
if sat_adjust_method <: RS.NewtonsMethod
@@ -21,7 +21,7 @@ function print_numerical_method(
2121
end
2222
end
2323

24-
function print_T_guess(
24+
@inline function print_T_guess(
2525
::Type{sat_adjust_method},
2626
T_guess::Real,
2727
) where {sat_adjust_method}
@@ -32,7 +32,7 @@ function print_T_guess(
3232
end
3333
end
3434

35-
function print_T_guess(
35+
@inline function print_T_guess(
3636
::Type{sat_adjust_method},
3737
T_guess::Nothing,
3838
) where {sat_adjust_method}
@@ -46,7 +46,7 @@ end
4646
#####
4747
##### Thermodynamic variable inputs: ρ, e_int, q_tot
4848
#####
49-
function sa_numerical_method(
49+
@inline function sa_numerical_method(
5050
::Type{NM},
5151
param_set::APS,
5252
ρ::FT,
@@ -64,7 +64,7 @@ function sa_numerical_method(
6464
return RS.NewtonsMethod(T_init)
6565
end
6666

67-
function sa_numerical_method(
67+
@inline function sa_numerical_method(
6868
::Type{NM},
6969
param_set::APS,
7070
ρ::FT,
@@ -82,7 +82,7 @@ function sa_numerical_method(
8282
return RS.NewtonsMethodAD(T_init)
8383
end
8484

85-
function sa_numerical_method(
85+
@inline function sa_numerical_method(
8686
::Type{NM},
8787
param_set::APS,
8888
ρ::FT,
@@ -99,7 +99,7 @@ function sa_numerical_method(
9999
return RS.SecantMethod(T_1, T_2)
100100
end
101101

102-
function sa_numerical_method(
102+
@inline function sa_numerical_method(
103103
::Type{NM},
104104
param_set::APS,
105105
ρ::FT,
@@ -120,7 +120,7 @@ end
120120
##### Thermodynamic variable inputs: ρ, p, q_tot
121121
#####
122122

123-
function sa_numerical_method_ρpq(
123+
@inline function sa_numerical_method_ρpq(
124124
::Type{NM},
125125
param_set::APS,
126126
ρ::FT,
@@ -138,7 +138,7 @@ function sa_numerical_method_ρpq(
138138
return RS.NewtonsMethodAD(T_init)
139139
end
140140

141-
function sa_numerical_method_ρpq(
141+
@inline function sa_numerical_method_ρpq(
142142
::Type{NM},
143143
param_set::APS,
144144
ρ::FT,
@@ -157,7 +157,7 @@ end
157157
##### Thermodynamic variable inputs: p, e_int, q_tot
158158
#####
159159

160-
function sa_numerical_method_peq(
160+
@inline function sa_numerical_method_peq(
161161
::Type{NM},
162162
param_set::APS,
163163
p::FT,
@@ -175,7 +175,7 @@ function sa_numerical_method_peq(
175175
return RS.NewtonsMethodAD(T_init)
176176
end
177177

178-
function sa_numerical_method_peq(
178+
@inline function sa_numerical_method_peq(
179179
::Type{NM},
180180
param_set::APS,
181181
p::FT,
@@ -196,7 +196,7 @@ end
196196
##### Thermodynamic variable inputs: p, h, q_tot
197197
#####
198198

199-
function sa_numerical_method_phq(
199+
@inline function sa_numerical_method_phq(
200200
::Type{NM},
201201
param_set::APS,
202202
p::FT,
@@ -217,7 +217,7 @@ function sa_numerical_method_phq(
217217
return RS.NewtonsMethodAD(T_init)
218218
end
219219

220-
function sa_numerical_method_phq(
220+
@inline function sa_numerical_method_phq(
221221
::Type{NM},
222222
param_set::APS,
223223
p::FT,
@@ -237,7 +237,7 @@ function sa_numerical_method_phq(
237237
return RS.SecantMethod(T_1, T_2)
238238
end
239239

240-
function sa_numerical_method_phq(
240+
@inline function sa_numerical_method_phq(
241241
::Type{NM},
242242
param_set::APS,
243243
p::FT,
@@ -261,7 +261,7 @@ end
261261
##### Thermodynamic variable inputs: p, θ_liq_ice, q_tot
262262
#####
263263

264-
function sa_numerical_method_pθq(
264+
@inline function sa_numerical_method_pθq(
265265
::Type{NM},
266266
param_set::APS,
267267
p::FT,
@@ -272,14 +272,14 @@ function sa_numerical_method_pθq(
272272
) where {FT, NM <: RS.RegulaFalsiMethod, phase_type <: PhaseEquil}
273273
_T_min::FT = TP.T_min(param_set)
274274
_T_max::FT = TP.T_max(param_set)
275-
air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
275+
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
276276
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
277277
T_2 = T_1 + 10
278278
T_1 = T_1 - 10
279279
return RS.RegulaFalsiMethod(T_1, T_2)
280280
end
281281

282-
function sa_numerical_method_pθq(
282+
@inline function sa_numerical_method_pθq(
283283
::Type{NM},
284284
param_set::APS,
285285
p::FT,
@@ -289,14 +289,14 @@ function sa_numerical_method_pθq(
289289
T_guess::Union{FT, Nothing},
290290
) where {FT, NM <: RS.SecantMethod, phase_type <: PhaseEquil}
291291
_T_min::FT = TP.T_min(param_set)
292-
air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
292+
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
293293
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
294294
T_2 = air_temp(PhasePartition(q_tot, FT(0), q_tot)) # Assume all ice
295295
T_2 = bound_upper_temperature(T_1, T_2)
296296
return RS.SecantMethod(T_1, T_2)
297297
end
298298

299-
function sa_numerical_method_pθq(
299+
@inline function sa_numerical_method_pθq(
300300
::Type{NM},
301301
param_set::APS,
302302
p::FT,
@@ -306,7 +306,7 @@ function sa_numerical_method_pθq(
306306
T_guess::Union{FT, Nothing},
307307
) where {FT, NM <: RS.NewtonsMethodAD, phase_type <: PhaseEquil}
308308
T_min::FT = TP.T_min(param_set)
309-
air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
309+
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
310310
T_init = if T_guess isa Nothing
311311
max(T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
312312
else

src/isentropic.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The air pressure for an isentropic process, where
2222
- `θ` potential temperature
2323
- `Φ` gravitational potential
2424
"""
25-
function air_pressure_given_θ(
25+
@inline function air_pressure_given_θ(
2626
param_set::APS,
2727
θ::FT,
2828
Φ::FT,
@@ -44,7 +44,7 @@ The air pressure for an isentropic process, where
4444
- `T∞` ambient temperature
4545
- `p∞` ambient pressure
4646
"""
47-
function air_pressure(
47+
@inline function air_pressure(
4848
param_set::APS,
4949
T::FT,
5050
T∞::FT,
@@ -64,7 +64,7 @@ The air temperature for an isentropic process, where
6464
- `p` pressure
6565
- `θ` potential temperature
6666
"""
67-
function air_temperature(
67+
@inline function air_temperature(
6868
param_set::APS,
6969
p::FT,
7070
θ::FT,

0 commit comments

Comments
 (0)