Skip to content

Commit

Permalink
bugfix; evaporation should return zero (instead of NaN) when xr = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
sajjadazimi committed Jul 4, 2024
1 parent bfd7d26 commit c901b71
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ main
------
<!--- # Add changes since the most recent release here --->

- Bugfix; fixed the evaporation scheme of SB2006 to prevent returning NaN values when limiters are not applied. ([#420](https://github.com/CliMA/CloudMicrophysics.jl/pull/415))

v0.20.0
------
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CloudMicrophysics"
uuid = "6a9e3e04-43cd-43ba-94b9-e8782df3c71b"
authors = ["Climate Modeling Alliance"]
version = "0.22.0"
version = "0.22.1"

[deps]
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
Expand Down
5 changes: 4 additions & 1 deletion src/Microphysics2M.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ function rain_evaporation(
evap_rate_0 = min(FT(0), FT(2) * FT(π) * G * S * N_rai * Dr * Fv0 / xr)
evap_rate_1 = min(FT(0), FT(2) * FT(π) * G * S * N_rai * Dr * Fv1 / ρ)

evap_rate_0 = N_rai < eps(FT) ? FT(0) : evap_rate_0
# When xr = 0 evap_rate_0 becomes NaN. We replace NaN with 0 which is the limit of
# evap_rate_0 for xr -> 0.
evap_rate_0 =
N_rai < eps(FT) || xr / x_star < eps(FT) ? FT(0) : evap_rate_0
evap_rate_1 = q_rai < eps(FT) ? FT(0) : evap_rate_1
end

Expand Down
13 changes: 13 additions & 0 deletions test/microphysics2M_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,19 @@ function test_microphysics2M(FT)
T,
).evap_rate_1 0 atol = eps(FT)
end

# test limit case: xr = 0 for SB with no limiters
TT.@test CM2.rain_evaporation(
SB2006_no_limiters,
aps,
tps,
q,
FT(0),
ρ,
N_rai,
T,
).evap_rate_0 0 atol = eps(FT)

end

TT.@testset "2M_microphysics - Seifert and Beheng 2006 effective radius and reflectivity" begin
Expand Down

0 comments on commit c901b71

Please sign in to comment.