Skip to content

Commit f19f105

Browse files
authored
Bug in two stream scheme (#1193)
1 parent 90c1e1c commit f19f105

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/standalone/Vegetation/canopy_parameterizations.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ function canopy_sw_rt_two_stream(
235235
# Compute μ̄, the average inverse diffuse optical length per LAI
236236
μ̄ = 1 / max(2G, eps(FT))
237237

238-
# Clip this to eps(FT) to prevent dividing by zero; the sum must also be < 1
239-
ω = min(max(α_leaf + τ_leaf, eps(FT)), 1 - eps(FT))
238+
# Clip this to prevent dividing by zero; the sum must also be < 1. Note that using eps(FT)
239+
# as the threshold leads to numerical errors, so we use 1e-4
240+
ω = min(max(α_leaf + τ_leaf, FT(1e-4)), 1 - FT(1e-4))
240241

241242
# Compute aₛ, the single scattering albedo
242243
aₛ =

test/standalone/Vegetation/test_two_stream.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ end
125125
cosθs = cos.(θs)
126126
α_leaf = [rand(N - 4)..., 0.0, 0.0, 1.0, 1.0]
127127
τ_leaf = (1.0 .- α_leaf) .* rand(N)
128-
α_soil = [rand(N - 6)..., 0.0, 1.0, 0.2, 0.2, 0.2, 0.2]
128+
τ_leaf[end - 2] = 0.0
129+
α_soil = [rand(N - 6)..., 0.0, 1.0, 0.2, 0.99, 0.2, 0.2]
129130
G_Function = ConstantGFunction(0.5)
130131
K = ClimaLand.Canopy.extinction_coeff.(G_Function, cosθs)
131132
frac_diff = rand(N)

0 commit comments

Comments
 (0)