Skip to content

Commit

Permalink
Inlining everything
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Jan 22, 2024
1 parent dd73501 commit 492967a
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 301 deletions.
24 changes: 12 additions & 12 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ Base.eltype(::ThermodynamicsParameters{FT}) where {FT} = FT

# wrappers
for fn in fieldnames(ATP)
@eval $(fn)(ps::ATP) = ps.$(fn)
@eval @inline $(fn)(ps::ATP) = ps.$(fn)
end

# Derived parameters
R_d(ps::ATP) = ps.gas_constant / ps.molmass_dryair
R_v(ps::ATP) = ps.gas_constant / ps.molmass_water
molmass_ratio(ps::ATP) = ps.molmass_dryair / ps.molmass_water
LH_f0(ps::ATP) = ps.LH_s0 - ps.LH_v0
e_int_v0(ps::ATP) = ps.LH_v0 - R_v(ps) * ps.T_0
e_int_i0(ps::ATP) = LH_f0(ps)
cp_d(ps::ATP) = R_d(ps) / ps.kappa_d
cv_d(ps::ATP) = cp_d(ps) - R_d(ps)
cv_v(ps::ATP) = ps.cp_v - R_v(ps)
cv_l(ps::ATP) = ps.cp_l
cv_i(ps::ATP) = ps.cp_i
@inline R_d(ps::ATP) = ps.gas_constant / ps.molmass_dryair
@inline R_v(ps::ATP) = ps.gas_constant / ps.molmass_water
@inline molmass_ratio(ps::ATP) = ps.molmass_dryair / ps.molmass_water
@inline LH_f0(ps::ATP) = ps.LH_s0 - ps.LH_v0
@inline e_int_v0(ps::ATP) = ps.LH_v0 - R_v(ps) * ps.T_0
@inline e_int_i0(ps::ATP) = LH_f0(ps)
@inline cp_d(ps::ATP) = R_d(ps) / ps.kappa_d
@inline cv_d(ps::ATP) = cp_d(ps) - R_d(ps)
@inline cv_v(ps::ATP) = ps.cp_v - R_v(ps)
@inline cv_l(ps::ATP) = ps.cp_l
@inline cv_i(ps::ATP) = ps.cp_i

end
4 changes: 2 additions & 2 deletions src/Thermodynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ const APS = TP.ThermodynamicsParameters
# Error on convergence must be the default
# behavior because this can result in printing
# very large logs resulting in CI to seemingly hang.
error_on_non_convergence() = true
@inline error_on_non_convergence() = true

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

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

Expand Down
40 changes: 20 additions & 20 deletions src/config_numerical_method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# KA.@print only accepts literal strings, so we must
# branch to print which method is being used.
function print_numerical_method(
@inline function print_numerical_method(
::Type{sat_adjust_method},
) where {sat_adjust_method}
if sat_adjust_method <: RS.NewtonsMethod
Expand All @@ -21,7 +21,7 @@ function print_numerical_method(
end
end

function print_T_guess(
@inline function print_T_guess(

Check warning on line 24 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L24

Added line #L24 was not covered by tests
::Type{sat_adjust_method},
T_guess::Real,
) where {sat_adjust_method}
Expand All @@ -32,7 +32,7 @@ function print_T_guess(
end
end

function print_T_guess(
@inline function print_T_guess(
::Type{sat_adjust_method},
T_guess::Nothing,
) where {sat_adjust_method}
Expand All @@ -46,7 +46,7 @@ end
#####
##### Thermodynamic variable inputs: ρ, e_int, q_tot
#####
function sa_numerical_method(
@inline function sa_numerical_method(
::Type{NM},
param_set::APS,
ρ::FT,
Expand All @@ -64,7 +64,7 @@ function sa_numerical_method(
return RS.NewtonsMethod(T_init)
end

function sa_numerical_method(
@inline function sa_numerical_method(

Check warning on line 67 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L67

Added line #L67 was not covered by tests
::Type{NM},
param_set::APS,
ρ::FT,
Expand All @@ -82,7 +82,7 @@ function sa_numerical_method(
return RS.NewtonsMethodAD(T_init)
end

function sa_numerical_method(
@inline function sa_numerical_method(
::Type{NM},
param_set::APS,
ρ::FT,
Expand All @@ -99,7 +99,7 @@ function sa_numerical_method(
return RS.SecantMethod(T_1, T_2)
end

function sa_numerical_method(
@inline function sa_numerical_method(

Check warning on line 102 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L102

Added line #L102 was not covered by tests
::Type{NM},
param_set::APS,
ρ::FT,
Expand All @@ -120,7 +120,7 @@ end
##### Thermodynamic variable inputs: ρ, p, q_tot
#####

function sa_numerical_method_ρpq(
@inline function sa_numerical_method_ρpq(
::Type{NM},
param_set::APS,
ρ::FT,
Expand All @@ -138,7 +138,7 @@ function sa_numerical_method_ρpq(
return RS.NewtonsMethodAD(T_init)
end

function sa_numerical_method_ρpq(
@inline function sa_numerical_method_ρpq(

Check warning on line 141 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L141

Added line #L141 was not covered by tests
::Type{NM},
param_set::APS,
ρ::FT,
Expand All @@ -157,7 +157,7 @@ end
##### Thermodynamic variable inputs: p, e_int, q_tot
#####

function sa_numerical_method_peq(
@inline function sa_numerical_method_peq(

Check warning on line 160 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L160

Added line #L160 was not covered by tests
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -175,7 +175,7 @@ function sa_numerical_method_peq(
return RS.NewtonsMethodAD(T_init)
end

function sa_numerical_method_peq(
@inline function sa_numerical_method_peq(
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -196,7 +196,7 @@ end
##### Thermodynamic variable inputs: p, h, q_tot
#####

function sa_numerical_method_phq(
@inline function sa_numerical_method_phq(

Check warning on line 199 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L199

Added line #L199 was not covered by tests
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -217,7 +217,7 @@ function sa_numerical_method_phq(
return RS.NewtonsMethodAD(T_init)
end

function sa_numerical_method_phq(
@inline function sa_numerical_method_phq(
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -237,7 +237,7 @@ function sa_numerical_method_phq(
return RS.SecantMethod(T_1, T_2)
end

function sa_numerical_method_phq(
@inline function sa_numerical_method_phq(

Check warning on line 240 in src/config_numerical_method.jl

View check run for this annotation

Codecov / codecov/patch

src/config_numerical_method.jl#L240

Added line #L240 was not covered by tests
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -261,7 +261,7 @@ end
##### Thermodynamic variable inputs: p, θ_liq_ice, q_tot
#####

function sa_numerical_method_pθq(
@inline function sa_numerical_method_pθq(
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -272,14 +272,14 @@ function sa_numerical_method_pθq(
) where {FT, NM <: RS.RegulaFalsiMethod, phase_type <: PhaseEquil}
_T_min::FT = TP.T_min(param_set)
_T_max::FT = TP.T_max(param_set)
air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
T_2 = T_1 + 10
T_1 = T_1 - 10
return RS.RegulaFalsiMethod(T_1, T_2)
end

function sa_numerical_method_pθq(
@inline function sa_numerical_method_pθq(
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -289,14 +289,14 @@ function sa_numerical_method_pθq(
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.SecantMethod, phase_type <: PhaseEquil}
_T_min::FT = TP.T_min(param_set)
air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
T_1 = max(_T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
T_2 = air_temp(PhasePartition(q_tot, FT(0), q_tot)) # Assume all ice
T_2 = bound_upper_temperature(T_1, T_2)
return RS.SecantMethod(T_1, T_2)
end

function sa_numerical_method_pθq(
@inline function sa_numerical_method_pθq(
::Type{NM},
param_set::APS,
p::FT,
Expand All @@ -306,7 +306,7 @@ function sa_numerical_method_pθq(
T_guess::Union{FT, Nothing},
) where {FT, NM <: RS.NewtonsMethodAD, phase_type <: PhaseEquil}
T_min::FT = TP.T_min(param_set)
air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
@inline air_temp(q) = air_temperature_given_pθq(param_set, p, θ_liq_ice, q)
T_init = if T_guess isa Nothing
max(T_min, air_temp(PhasePartition(q_tot))) # Assume all vapor
else
Expand Down
6 changes: 3 additions & 3 deletions src/isentropic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The air pressure for an isentropic process, where
- `θ` potential temperature
- `Φ` gravitational potential
"""
function air_pressure_given_θ(
@inline function air_pressure_given_θ(
param_set::APS,
θ::FT,
Φ::FT,
Expand All @@ -44,7 +44,7 @@ The air pressure for an isentropic process, where
- `T∞` ambient temperature
- `p∞` ambient pressure
"""
function air_pressure(
@inline function air_pressure(
param_set::APS,
T::FT,
T∞::FT,
Expand All @@ -64,7 +64,7 @@ The air temperature for an isentropic process, where
- `p` pressure
- `θ` potential temperature
"""
function air_temperature(
@inline function air_temperature(
param_set::APS,
p::FT,
θ::FT,
Expand Down
Loading

0 comments on commit 492967a

Please sign in to comment.