Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precompute expensive terms #372

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/optics/GasOptics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ Compute interpolation fraction for pressure.
@inline function compute_interp_frac_press(lkp::AbstractLookUp, p_lay, tropo, glay, gcol)
(; Δ_ln_p_ref, p_ref, n_p_ref) = lkp

@inbounds jpress = Int(min(max(fld(log(p_ref[1]) - log(p_lay), Δ_ln_p_ref) + 1, 1), n_p_ref - 1) + 1)
log_p_lay = log(p_lay)
@inbounds jpress = Int(min(max(fld(log(p_ref[1]) - log_p_lay, Δ_ln_p_ref) + 1, 1), n_p_ref - 1) + 1)

@inbounds fpress = (log(p_ref[jpress - 1]) - log(p_lay)) / Δ_ln_p_ref
@inbounds fpress = (log(p_ref[jpress - 1]) - log_p_lay) / Δ_ln_p_ref
jpress = jpress + tropo - 1

return (jpress, fpress)
Expand Down
5 changes: 3 additions & 2 deletions src/rte/RTESolverKernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ function rte_lw_2stream_source!(
γ2 = lw_diff_sec * FT(0.5) * ssa[glay, gcol] * (1 - g[glay, gcol])
k = sqrt(max((γ1 + γ2) * (γ1 - γ2), FT(1e-12)))

coeff = exp(-2 * τ[glay, gcol] * k)
# Refactored to avoid rounding errors when k, gamma1 are of very different magnitudes
RT_term = 1 / (k * (1 + exp(-2 * τ[glay, gcol] * k)) + γ1 * (1 - exp(-2 * τ[glay, gcol] * k)))
RT_term = 1 / (k * (1 + coeff) + γ1 * (1 - coeff))

@inbounds Rdif[glay, gcol] = RT_term * γ2 * (1 - exp(-2 * τ[glay, gcol] * k)) # Equation 25
@inbounds Rdif[glay, gcol] = RT_term * γ2 * (1 - coeff) # Equation 25
@inbounds Tdif[glay, gcol] = RT_term * 2 * k * exp(-τ[glay, gcol] * k) # Equation 26

# Source function for diffuse radiation
Expand Down