Skip to content

Commit

Permalink
fixes in tests, aw params
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Aug 21, 2023
1 parent 58bc756 commit 10e77bc
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 25 deletions.
33 changes: 25 additions & 8 deletions src/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,41 @@ function logistic_function_integral(x::FT, x_0::FT, k::FT) where {FT <: Real}
end

"""
H2SO4_soln_saturation_vapor_pressure(x, T)
H2SO4_soln_saturation_vapor_pressure(prs, x, T)
- `prs` - a set with free parameters
- `x` - wt percent sulphuric acid [unitless]
- `T` - air temperature [K].
Returns the saturation vapor pressure above a sulphuric acid solution droplet in Pa.
`x` is, for example, 0.1 if droplets are 10 percent sulphuric acid by weight
"""
function H2SO4_soln_saturation_vapor_pressure(x::FT, T::FT) where {FT <: Real}
function H2SO4_soln_saturation_vapor_pressure(
prs::APS,
x::FT,
T::FT
) where {FT <: Real}

T_max::FT = CMP.H2SO4_sol_T_max(prs)
T_min::FT = CMP.H2SO4_sol_T_min(prs)
w_h::FT = CMP.H2SO4_sol_w_2(prs)

c1::FT = CMP.H2SO4_sol_c1(prs)
c2::FT = CMP.H2SO4_sol_c2(prs)
c3::FT = CMP.H2SO4_sol_c3(prs)
c4::FT = CMP.H2SO4_sol_c4(prs)
c5::FT = CMP.H2SO4_sol_c5(prs)
c6::FT = CMP.H2SO4_sol_c6(prs)
c7::FT = CMP.H2SO4_sol_c7(prs)

@assert T < FT(235)
@assert T > FT(185)
@assert T < T_max
@assert T > T_min

w_h = 1.4408 * x
w_h = w_h * x
p_sol =
exp(
23.306 - 5.3465 * x + 12 * x * w_h - 8.19 * x * w_h^2 +
(-5814 + 928.9 * x - 1876.7 * x * w_h) / T,
c1 - c2 * x + c3 * x * w_h - c4 * x * w_h^2 +
(c5 + c6 * x - c7 * x * w_h) / T,
) * 100 # * 100 converts mbar --> Pa
return p_sol
end
Expand All @@ -160,7 +177,7 @@ function Delta_a_w(prs::APS, x::FT, T::FT) where {FT <: Real}

thermo_params = CMP.thermodynamics_params(prs)

p_sol = H2SO4_soln_saturation_vapor_pressure(x, T)
p_sol = H2SO4_soln_saturation_vapor_pressure(prs, x, T)
p_sat = TD.saturation_vapor_pressure(thermo_params, T, TD.Liquid())
p_ice = TD.saturation_vapor_pressure(thermo_params, T, TD.Ice())

Expand Down
4 changes: 2 additions & 2 deletions src/IceNucleation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ see DOI: 10.1039/C3FD00035D
function ABIFM_J(
prs::APS,
dust_type::CT.AbstractAerosolType,
Δa_w::FT
Δa_w::FT,
) where {FT <: Real}

m::FT = J_het_m(prs, dust_type)
c::FT = J_het_c(prs, dust_type)

logJ::FT = m * Δa_w + c

return max(FT(0), FT(10)^logJ * 1e2) # converts cm^-2 s^-1 to m^-2 s^-1
return max(FT(0), FT(10)^logJ * FT(1e4)) # converts cm^-2 s^-1 to m^-2 s^-1
end

end # end module
Expand Down
10 changes: 10 additions & 0 deletions src/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ Base.@kwdef struct CloudMicrophysicsParameters{FT, TP} <:
Koop2000_J_hom_c2::FT
Koop2000_J_hom_c3::FT
Koop2000_J_hom_c4::FT
H2SO4_sol_T_max::FT
H2SO4_sol_T_min::FT
H2SO4_sol_w_2::FT
H2SO4_sol_c1::FT
H2SO4_sol_c2::FT
H2SO4_sol_c3::FT
H2SO4_sol_c4::FT
H2SO4_sol_c5::FT
H2SO4_sol_c6::FT
H2SO4_sol_c7::FT
molmass_seasalt::FT
rho_seasalt::FT
osm_coeff_seasalt::FT
Expand Down
16 changes: 6 additions & 10 deletions test/common_functions_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ function test_H2SO4_soln_saturation_vapor_pressure(FT)
x_sulph = FT(0.1)

# If T out of range
TT.@test_throws AssertionError("T < FT(235)") CO.H2SO4_soln_saturation_vapor_pressure(
TT.@test_throws AssertionError("T < T_max") CO.H2SO4_soln_saturation_vapor_pressure(
prs,
x_sulph,
T_too_warm,
)
TT.@test_throws AssertionError("T > FT(185)") CO.H2SO4_soln_saturation_vapor_pressure(
TT.@test_throws AssertionError("T > T_min") CO.H2SO4_soln_saturation_vapor_pressure(
prs,
x_sulph,
T_too_cold,
)

# p_sol should be higher at warmer temperatures
TT.@test CO.H2SO4_soln_saturation_vapor_pressure(x_sulph, T_warm) >
CO.H2SO4_soln_saturation_vapor_pressure(x_sulph, T_cold)
TT.@test CO.H2SO4_soln_saturation_vapor_pressure(prs, x_sulph, T_warm) >
CO.H2SO4_soln_saturation_vapor_pressure(prs, x_sulph, T_cold)
end
end

Expand All @@ -97,15 +99,9 @@ end

println("Testing Float64")
test_H2SO4_soln_saturation_vapor_pressure(Float64)


println("Testing Float32")
test_H2SO4_soln_saturation_vapor_pressure(Float32)


println("Testing Float64")
test_Delta_a_w(Float64)


println("Testing Float32")
test_Delta_a_w(Float32)
6 changes: 4 additions & 2 deletions test/gpu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ end
end

@kernel function test_Common_H2SO4_soln_saturation_vapor_pressure_kernel!(
prs,
output::AbstractArray{FT},
x_sulph,
T,
Expand All @@ -278,7 +279,8 @@ end
i = @index(Group, Linear)

@inbounds begin
output[i] = CO.H2SO4_soln_saturation_vapor_pressure(x_sulph[i], T[i])
output[i] =
CO.H2SO4_soln_saturation_vapor_pressure(prs, x_sulph[i], T[i])
end
end

Expand Down Expand Up @@ -584,7 +586,7 @@ function test_gpu(FT)
dev,
work_groups,
)
event = kernel!(output, x_sulph, T, ndrange = ndrange)
event = kernel!(make_prs(FT), output, x_sulph, T, ndrange = ndrange)
wait(dev, event)

# test H2SO4_soln_saturation_vapor_pressure is callable and returns a reasonable value
Expand Down
11 changes: 9 additions & 2 deletions test/heterogeneous_ice_nucleation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ function test_heterogeneous_ice_nucleation(FT)
# higher nucleation rate at colder temperatures
for dust in
[CMT.IlliteType(), CMT.KaoliniteType(), CMT.DesertDustType()]
TT.@test CMI_het.ABIFM_J(prs, dust, CO.Delta_a_w(prs, x_sulph, T_cold)) >
CMI_het.ABIFM_J(prs, dust, CO.Delta_a_w(prs, x_sulph, T_warm))
TT.@test CMI_het.ABIFM_J(
prs,
dust,
CO.Delta_a_w(prs, x_sulph, T_cold),
) > CMI_het.ABIFM_J(
prs,
dust,
CO.Delta_a_w(prs, x_sulph, T_warm),
)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/performance_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function benchmark_test(FT)
# Common
bench_press(
CO.H2SO4_soln_saturation_vapor_pressure,
(x_sulph, T_air_cold),
(prs, x_sulph, T_air_cold),
50,
)
bench_press(CO.Delta_a_w, (prs, x_sulph, T_air_cold), 230)
Expand Down

0 comments on commit 10e77bc

Please sign in to comment.