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

unitless N_hat added, Float32 tests passing #303

Merged
merged 1 commit into from
Feb 7, 2024
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
2 changes: 1 addition & 1 deletion docs/src/P3Scheme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ N'(D) = N_{0} D^\mu \, e^{-\lambda \, D}
where:
- ``N'`` is the number concentration in ``m^{-4}``
- ``D`` is the maximum particle dimension in ``m``,
- ``N_0`` is the intercept parameter in ``m^{-4}``,
- ``N_0`` is the intercept parameter in ``m^{-5 - \mu }``,
- ``\mu`` is the shape parameter (dimensionless),
- ``\lambda`` is the slope parameter in ``m^{-1}``.

Expand Down
6 changes: 4 additions & 2 deletions src/P3Scheme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function thresholds(p3::PSP3{FT}, ρ_r::FT, F_r::FT) where {FT}
@assert F_r < FT(1) # ... and there must always be some unrimed part

if F_r == FT(0)
return (; D_cr = 0, D_gr = 0, ρ_g = 0, ρ_d = 0)
return (; D_cr = FT(0), D_gr = FT(0), ρ_g = FT(0), ρ_d = FT(0))
else
@assert ρ_r > FT(0) # rime density must be positive ...
@assert ρ_r <= p3.ρ_l # ... and as a bulk ice density can't exceed the density of water
Expand Down Expand Up @@ -344,7 +344,9 @@ function distribution_parameter_solver(
th = thresholds(p3, ρ_r, F_r)

# To ensure that λ is positive solve for x such that λ = exp(x)
shape_problem(x) = q - q_gamma(p3, F_r, N, x, th)
# We divide by N̂ to deal with large N₀ values for Float32
N̂ = FT(1e30)
shape_problem(x) = q / N̂ - q_gamma(p3, F_r, N / N̂, x, th)

# Find slope parameter
x =
Expand Down
8 changes: 4 additions & 4 deletions test/p3_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function test_p3_shape_solver(FT)
TT.@testset "shape parameters (nonlinear solver function)" begin

# initialize test values:
eps = FT(1e-3)
ep = 1e3 * eps(FT)
N_test = (FT(1e8)) # N values
λ_test = (FT(15000), FT(20000)) # test λ values in range
ρ_r_test = (FT(200)) #, FT(1)) #, FT(100)) # representative ρ_r values
Expand Down Expand Up @@ -188,8 +188,8 @@ function test_p3_shape_solver(FT)
)

# Compare solved values with the input expected values
TT.@test λ ≈ λ_ex rtol = eps
TT.@test N₀ ≈ N₀_ex rtol = eps
TT.@test λ ≈ λ_ex rtol = ep
TT.@test N₀ ≈ N₀_ex rtol = ep
end
end
end
Expand All @@ -202,7 +202,7 @@ test_p3_thresholds(Float32)
test_p3_mass(Float32)
#TODO - only works for Float64 now. We should switch the units inside the solver
# from SI base to something more managable
#test_p3_shape_solver(Float32)
test_p3_shape_solver(Float32)

println("Testing Float64")
test_p3_thresholds(Float64)
Expand Down
Loading