Skip to content

Commit 72abc40

Browse files
authored
Merge pull request #677 from CliMA/he/fix-gpu-tests
fix: gpu tests
2 parents 77b997d + 447612e commit 72abc40

File tree

3 files changed

+707
-1321
lines changed

3 files changed

+707
-1321
lines changed

src/AerosolActivation.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
module AerosolActivation
1111

1212
import SpecialFunctions as SF
13+
import UnrolledUtilities as UU
1314

1415
import ..ThermodynamicsInterface as TDI
1516
import ..Common as CO
@@ -251,7 +252,7 @@ function N_activated_per_mode(
251252
return ntuple(Val(AM.n_modes(ad))) do i
252253

253254
mode_i = ad.modes[i]
254-
u_i::FT = 2 * log(sm[i] / smax) / 3 / sqrt(2) / log(mode_i.stdev)
255+
u_i = 2 * log(sm[i] / smax) / 3 / sqrt(FT(2)) / log(mode_i.stdev)
255256

256257
mode_i.N * FT(0.5) * (1 - SF.erf(u_i))
257258
end
@@ -308,18 +309,14 @@ function M_activated_per_mode(
308309
sm = critical_supersaturation(ap, ad, T)
309310

310311
return ntuple(Val(AM.n_modes(ad))) do i
311-
312312
mode_i = ad.modes[i]
313+
Mᵢ = UU.unrolled_sum(mode_i.molar_mass .* mode_i.mass_mix_ratio)
314+
σᵢ = mode_i.stdev
315+
fac = 3log(σᵢ) * (FT(2)) / 2 # 3√2/2 log(σᵢ), shared factor in `erf`
316+
u_i = log(sm[i] / smax) / fac
313317

314-
avg_molar_mass_i = FT(0)
315-
@inbounds for j in 1:(AM.n_components(mode_i))
316-
avg_molar_mass_i += mode_i.molar_mass[j] * mode_i.mass_mix_ratio[j]
317-
end
318-
319-
u_i = 2 * log(sm[i] / smax) / 3 / sqrt(2) / log(mode_i.stdev)
320-
321-
avg_molar_mass_i * 1 / 2 *
322-
(1 - SF.erf(u_i - 3 * sqrt(2) / 2 * log(mode_i.stdev)))
318+
# erfc(x) ≡ 1 - erf(x), but more accurate for large x
319+
Mᵢ / 2 * SF.erfc(u_i - fac)
323320
end
324321
end
325322
function M_activated_per_mode(

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
3232

3333
[compat]
3434
KernelAbstractions = "0.9"
35-
MLJFlux = "0.4"
35+
MLJFlux = "0.4 - 0.6"

0 commit comments

Comments
 (0)