Skip to content

Commit

Permalink
Merge pull request #3397 from CliMA/zs/remove_ft
Browse files Browse the repository at this point in the history
remove unnecessary FT for type restriction
  • Loading branch information
szy21 authored Oct 31, 2024
2 parents 4138048 + 7436f52 commit 0b76ad2
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 205 deletions.
2 changes: 1 addition & 1 deletion src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
ρ_prev_level
) / local_geometry_level.J / ρ_level

@. detrʲ_prev_level = detrainment(
@. detrʲ_prev_level = detrainment_from_thermo_state(
params,
z_prev_level,
z_sfc_halflevel,
Expand Down
4 changes: 2 additions & 2 deletions src/cache/precipitation_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import CloudMicrophysics.Microphysics1M as CM1

# helper function to safely get precipitation from state
function qₚ(ρqₚ::FT, ρ::FT) where {FT}
return max(FT(0), ρqₚ / ρ)
function qₚ(ρqₚ, ρ)
return max(zero), ρqₚ / ρ)
end

"""
Expand Down
41 changes: 15 additions & 26 deletions src/cache/precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,7 @@ function eddy_diffusivity_coefficient(C_E, norm_v_a, z_a, p)
K_E = C_E * norm_v_a * z_a
return p > p_pbl ? K_E : K_E * exp(-((p_pbl - p) / p_strato)^2)
end
function eddy_diffusivity_coefficient(
z::FT,
z₀,
f_b::FT,
h::FT,
uₐ,
C_E::FT,
Ri::FT,
Ri_a::FT,
Ri_c::FT,
κ::FT,
) where {FT}
function eddy_diffusivity_coefficient(z, z₀, f_b, h, uₐ, C_E, Ri, Ri_a, Ri_c, κ)
# Equations (17), (18)
if z <= f_b * h
K_b =
Expand All @@ -356,17 +345,17 @@ function eddy_diffusivity_coefficient(
K = K_b * (z / f_b / h) * (1 - (z - f_b * h) / (1 - f_b) / h)^2
return K
else
return FT(0)
return zero(z)
end
end

function compute_boundary_layer_height!(
h_boundary_layer,
dz,
Ri_local,
Ri_c::FT,
Ri_c,
Ri_a,
) where {FT}
)
nlevels = Spaces.nlevels(Spaces.axes(Ri_local))
for level in 1:(nlevels - 1)
h_boundary_layer .=
Expand All @@ -385,22 +374,22 @@ function compute_boundary_layer_height!(
end

function compute_bulk_richardson_number(
θ_v,
θ_v::FT,
θ_v_a,
norm_ua,
grav,
z::FT,
z,
) where {FT}
# TODO Gustiness from ClimaParams
return (grav * z) * (θ_v - θ_v_a) / (θ_v_a * (max((norm_ua)^2, FT(10))))
end
function compute_exchange_coefficient(
Ri_a,
Ri_a::FT,
Ri_c,
zₐ,
z₀,
κ::FT,
C_E_min::FT,
κ,
C_E_min,
) where {FT}
# Equations (12), (13), (14)
if Ri_a <= FT(0)
Expand All @@ -414,12 +403,12 @@ end

function compute_surface_layer_diffusivity(
z::FT,
z₀::FT,
κ::FT,
C_E::FT,
Ri::FT,
Ri_a::FT,
Ri_c::FT,
z₀,
κ,
C_E,
Ri,
Ri_a,
Ri_c,
norm_uₐ,
) where {FT}
# Equations (19), (20)
Expand Down
25 changes: 7 additions & 18 deletions src/parameterized_tendencies/microphysics/microphysics_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cᵥₗ(thp) = TD.Parameters.cv_l(thp)
cᵥᵢ(thp) = TD.Parameters.cv_i(thp)

# helper function to limit the tendency
function limit(q::FT, dt::FT, n::Int) where {FT}
function limit(q, dt, n::Int)
return q / dt / n
end

Expand Down Expand Up @@ -77,24 +77,17 @@ end
Returns the qₜ source term due to precipitation formation
defined as Δm_tot / (m_dry + m_tot)
"""
function q_tot_precipitation_sources(
::NoPrecipitation,
thp,
cmp,
dt,
qₜ::FT,
ts,
) where {FT <: Real}
return FT(0)
function q_tot_precipitation_sources(::NoPrecipitation, thp, cmp, dt, qₜ, ts)
return zero(qₜ)
end
function q_tot_precipitation_sources(
::Microphysics0Moment,
thp,
cmp,
dt,
qₜ::FT,
qₜ,
ts,
) where {FT <: Real}
)
return -min(max(qₜ, 0) / dt, -CM0.remove_precipitation(cmp, PP(thp, ts)))
end

Expand All @@ -108,13 +101,9 @@ end
Returns the total energy source term multiplier from precipitation formation
for the 0-moment scheme
"""
function e_tot_0M_precipitation_sources_helper(
thp,
ts,
Φ::FT,
) where {FT <: Real}
function e_tot_0M_precipitation_sources_helper(thp, ts, Φ)

λ::FT = TD.liquid_fraction(thp, ts)
λ = TD.liquid_fraction(thp, ts)

return λ * Iₗ(thp, ts) + (1 - λ) * Iᵢ(thp, ts) + Φ
end
Expand Down
21 changes: 11 additions & 10 deletions src/prognostic_equations/buoyancy_gradients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,25 @@ end
"""
buoyancy_gradient_chain_rule(
::AbstractEnvBuoyGradClosure,
bg_model::EnvBuoyGradVars{FT, EBG},
bg_model::EnvBuoyGradVars,
thermo_params,
∂b∂θv::FT,
∂b∂θl_sat::FT,
∂b∂qt_sat::FT,
) where {FT <: Real}
∂b∂θv,
∂b∂θl_sat,
∂b∂qt_sat,
) where
Returns the vertical buoyancy gradients in the environment, as well as in its dry and cloudy volume fractions,
from the partial derivatives with respect to thermodynamic variables in dry and cloudy volumes.
"""
function buoyancy_gradient_chain_rule(
::AbstractEnvBuoyGradClosure,
bg_model::EnvBuoyGradVars{FT},
bg_model::EnvBuoyGradVars,
thermo_params,
∂b∂θv::FT,
∂b∂θl_sat::FT,
∂b∂qt_sat::FT,
) where {FT <: Real}
∂b∂θv,
∂b∂θl_sat,
∂b∂qt_sat,
)
FT = eltype(thermo_params)
en_cld_frac = get_en_cld_frac(thermo_params, bg_model)
if en_cld_frac > FT(0)
∂b∂z_θl_sat = ∂b∂θl_sat * get_∂θl∂z_sat(thermo_params, bg_model)
Expand Down
18 changes: 9 additions & 9 deletions src/prognostic_equations/edmfx_boundary_condition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

function sgs_scalar_first_interior_bc(
ᶜz_int::FT,
ᶜρ_int::FT,
ᶜaʲ_int::FT,
ᶜscalar_int::FT,
ᶜρ_int,
ᶜaʲ_int,
ᶜscalar_int,
sfc_buoyancy_flux,
sfc_ρ_flux_scalar,
ustar,
Expand All @@ -33,8 +33,8 @@ end
function get_first_interior_variance(
flux,
ustar::FT,
z::FT,
oblength::FT,
z,
oblength,
local_geometry,
) where {FT}
c_star = -flux / ustar
Expand All @@ -47,7 +47,7 @@ function get_first_interior_variance(
end
end

function approximate_inverf(x::FT) where {FT <: Real}
function approximate_inverf(x::FT) where {FT}
# From Wikipedia
a = FT(0.147)
term1 = (2 /* a) + log(1 - x^2) / 2)
Expand All @@ -57,14 +57,14 @@ function approximate_inverf(x::FT) where {FT <: Real}
return sign(x) * sqrt(term3 - term1)
end

function guass_quantile(p::FT) where {FT <: Real}
function guass_quantile(p)
return sqrt(2) * approximate_inverf(2p - 1)
end

function percentile_bounds_mean_norm(
low_percentile::FT,
high_percentile::FT,
) where {FT <: Real}
high_percentile,
) where {FT}
gauss_int(x) = -exp(-x * x / 2) / sqrt(2 * pi)
xp_high = guass_quantile(high_percentile)
xp_low = guass_quantile(low_percentile)
Expand Down
40 changes: 21 additions & 19 deletions src/prognostic_equations/edmfx_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import ClimaCore.Fields as Fields
"""
Return draft area given ρa and ρ
"""
function draft_area(ρa::FT, ρ::FT) where {FT}
function draft_area(ρa, ρ)
return ρa / ρ
end

"""
Return buoyancy on cell centers.
"""
function ᶜphysical_buoyancy(params, ᶜρ_ref::FT, ᶜρ::FT) where {FT}
function ᶜphysical_buoyancy(params, ᶜρ_ref, ᶜρ)
# TODO - replace by ᶜgradᵥᶠΦ when we move to deep atmosphere
g = CAP.grav(params)
return (ᶜρ_ref - ᶜρ) / ᶜρ * g
Expand Down Expand Up @@ -119,7 +119,7 @@ lambert_2_over_e(::Type{FT}) where {FT} = FT(0.46305551336554884) # since we can
function lamb_smooth_minimum(
l::SA.SVector,
lower_bound::FT,
upper_bound::FT,
upper_bound,
) where {FT}
x_min = minimum(l)
λ_0 = max(x_min * lower_bound / lambert_2_over_e(FT), upper_bound)
Expand Down Expand Up @@ -153,19 +153,20 @@ Smagorinsky length scale.
"""
function mixing_length(
params,
ustar::FT,
ᶜz::FT,
z_sfc::FT,
ᶜdz::FT,
sfc_tke::FT,
ᶜlinear_buoygrad::FT,
ᶜtke::FT,
obukhov_length::FT,
ᶜstrain_rate_norm::FT,
ᶜPr::FT,
ᶜtke_exch::FT,
) where {FT}
ustar,
ᶜz,
z_sfc,
ᶜdz,
sfc_tke,
ᶜlinear_buoygrad,
ᶜtke,
obukhov_length,
ᶜstrain_rate_norm,
ᶜPr,
ᶜtke_exch,
)

FT = eltype(params)
turbconv_params = CAP.turbconv_params(params)
c_m = CAP.tke_ed_coeff(turbconv_params)
c_d = CAP.tke_diss_coeff(turbconv_params)
Expand Down Expand Up @@ -251,10 +252,11 @@ buoyancy gradient and shear production.
"""
function turbulent_prandtl_number(
params,
obukhov_length::FT,
ᶜlinear_buoygrad::FT,
ᶜstrain_rate_norm::FT,
) where {FT}
obukhov_length,
ᶜlinear_buoygrad,
ᶜstrain_rate_norm,
)
FT = eltype(params)
turbconv_params = CAP.turbconv_params(params)
Ri_c = CAP.Ri_crit(turbconv_params)
ω_pr = CAP.Prandtl_number_scale(turbconv_params)
Expand Down
Loading

0 comments on commit 0b76ad2

Please sign in to comment.