Skip to content

Commit aeec9eb

Browse files
committed
trim down reproducer
1 parent 3d75952 commit aeec9eb

File tree

1 file changed

+20
-57
lines changed

1 file changed

+20
-57
lines changed

test/Fields/inference_repro.jl

+20-57
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,29 @@ import ClimaComms
44
ClimaComms.@import_required_backends
55
import ClimaCore: Fields, Domains, Geometry, Meshes, Spaces
66

7-
Base.@kwdef struct LandParameters{FT}
7+
struct LandParameters{FT}
88
ρ_cloud_ice::FT
9-
ρ_cloud_liq::FT
10-
LH_f0::FT
11-
T_freeze::FT
12-
grav::FT
139
end
1410
Base.broadcastable(x::LandParameters) = tuple(x)
1511

16-
ρ_cloud_ice(x) = x.ρ_cloud_ice
17-
ρ_cloud_liq(x) = x.ρ_cloud_liq
18-
LH_f0(x) = x.LH_f0
19-
T_freeze(x) = x.T_freeze
20-
grav(x) = x.grav
21-
2212
struct vanGenuchten{FT}
23-
"The inverse of the air entry potential (1/m)"
2413
α::FT
25-
"The van Genuchten pore-size distribution index (unitless)"
26-
n::FT
27-
"The van Genuchten parameter m = 1 - 1/n (unitless)"
28-
m::FT
29-
"A derived parameter: the critical saturation at which capillary flow no longer replenishes the surface"
30-
S_c::FT
31-
function vanGenuchten{FT}(; α::FT, n::FT) where {FT}
32-
m = 1 - 1 / n
33-
S_c = (1 + ((n - 1) / n)^(1 - 2 * n))^(-m)
34-
return new{FT}(α, n, m, S_c)
35-
end
3614
end
3715
Base.broadcastable(x::vanGenuchten) = tuple(x)
3816

39-
function matric_potential(cm::vanGenuchten{FT}, S::FT) where {FT}
40-
(; α, m, n) = cm
41-
ψ = -((S^(-FT(1) / m) - FT(1)) * α^(-n))^(FT(1) / n)
42-
return ψ
43-
end
44-
4517
function phase_change_source(
4618
θ_l::FT,
47-
# θ_i::FT,
48-
# T::FT,
49-
# τ::FT,
50-
# ν::FT,
51-
# θ_r::FT,
5219
hydrology_cm::C,
5320
earth_param_set::EP,
5421
) where {FT, EP, C}
55-
_ρ_i = FT(ρ_cloud_ice(earth_param_set))
56-
# ψw0 = matric_potential(hydrology_cm, _ρ_i)
57-
return (θ_l - _ρ_i)
58-
# return (θ_l - _ρ_i) / τ
22+
return nothing
5923
end
6024

61-
function make_space(::Type{FT}; zlim = (FT(-1), FT(0)), nelements = 200) where {FT}
25+
function make_space(
26+
::Type{FT};
27+
zlim = (FT(-1), FT(0)),
28+
nelements = 200,
29+
) where {FT}
6230
boundary_names = (:bottom, :top)
6331
column = Domains.IntervalDomain(
6432
Geometry.ZPoint{FT}(zlim[1]),
@@ -70,32 +38,27 @@ function make_space(::Type{FT}; zlim = (FT(-1), FT(0)), nelements = 200) where {
7038
return subsurface_space
7139
end
7240

73-
function call_func(θ_l, θ_i, T, tau, ν, θ_r, hydrology_cm, earth_param_set)
41+
function call_func(θ_l, hydrology_cm, earth_param_set)
42+
# function call_func(hydrology_cm, earth_param_set)
7443
# This fails with dynamic function invocation when `LandParameters`
75-
# and `vanGenuchten` both use `tuple` for broadcasting, and it
76-
# passes when `Ref` is used for either `LandParameters` or `vanGenuchten` broadcasting
77-
# @. -phase_change_source(θ_l, θ_i, T, tau, ν, θ_r, hydrology_cm, earth_param_set)
78-
# @. -phase_change_source(θ_l, tau, hydrology_cm, earth_param_set)
79-
@. -phase_change_source(θ_l, hydrology_cm, earth_param_set)
44+
# and `vanGenuchten` both use `tuple` for broadcasting,
45+
# This passes when `Ref` is used for either `LandParameters` or `vanGenuchten` broadcasting
46+
@. phase_change_source(θ_l, hydrology_cm, earth_param_set)
47+
48+
# These don't fail on GPU
49+
# @. phase_change_source(hydrology_cm, earth_param_set)
50+
# @. phase_change_source(θ_l, earth_param_set)
51+
# @. phase_change_source(θ_l, hydrology_cm)
8052
return nothing
8153
end
8254
function main(::Type{FT}) where {FT}
83-
Np = length(fieldtypes(LandParameters))
84-
earth_param_set = LandParameters{FT}(zeros(Np)...)
85-
ν = FT(0.495)
86-
θ_r = FT(0.1)
87-
hydrology_cm = vanGenuchten{FT}(; α = FT(2.6), n = FT(2.0))
55+
earth_param_set = LandParameters{FT}(FT(0))
56+
hydrology_cm = vanGenuchten{FT}(FT(2.6))
8857

8958
space_3d = make_space(FT; zlim = (FT(-1), FT(0)), nelements = 200)
90-
9159
θ_l = Fields.ones(space_3d)
92-
θ_i = Fields.ones(space_3d)
93-
T = Fields.ones(space_3d)
94-
κ = Fields.ones(space_3d)
95-
tau = Fields.ones(space_3d)
96-
97-
call_func(θ_l, θ_i, T, tau, ν, θ_r, hydrology_cm, earth_param_set)
9860

61+
call_func(θ_l, hydrology_cm, earth_param_set)
9962
return nothing
10063
end
10164

0 commit comments

Comments
 (0)