Skip to content

Commit 8bba111

Browse files
committed
Add more output options for SFCC functions
1 parent 3d4ee0d commit 8bba111

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

src/sfcc.jl

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ end
9494
@inline function (f::PainterKarra)(
9595
T,
9696
ψ₀=nothing,
97-
::Val{return_all}=Val{false}();
97+
::Val{output}=Val{:θw}();
9898
θtot=stripparams(f.swrc.water.θtot),
9999
θsat=stripparams(f.swrc.water.θsat),
100100
θres=stripparams(f.swrc.water.θres),
101101
Tₘ=f.freezethaw.Tₘ,
102102
β=f.β,
103103
ω=f.ω,
104104
swrc_kwargs...
105-
) where return_all
105+
) where output
106106
let θsat = max(θtot, θsat),
107107
ψ₀ = isnothing(ψ₀) ? waterpotential(swrc(f), θtot; θsat, θres, swrc_kwargs...) : ψ₀,
108108
g = f.g,
@@ -111,14 +111,20 @@ end
111111
Lsl = f.freezethaw.Lsl,
112112
Tₘ = normalize_temperature(Tₘ),
113113
T = normalize_temperature(T),
114-
Tstar = Tₘ + ω*g*Tₘ/Lsl*ψ₀,
114+
Tstar = Tₘ + ω*g*Tₘ/Lsl*ψ₀;
115115
# matric potential as a function of T (same as Dall'Amico but with β parameter)
116-
ψ = ψ₀ + β*Lsl/(g*Tstar)*(T-Tstar)*heaviside(Tstar-T),
117-
θw = f.swrc(ψ; θsat, θres, swrc_kwargs...);
118-
if return_all
116+
ψ = ψ₀ + β*Lsl/(g*Tstar)*(T-Tstar)*heaviside(Tstar-T)
117+
# output is a compile-time constant so will be compiled away
118+
if output == :all || output == true # allow 'true' for backwards compatibility w/ 0.4
119+
θw = f.swrc(ψ; θsat, θres, swrc_kwargs...)
119120
return (; θw, ψ, Tstar)
120-
else
121+
elseif output == :θw || output == false # allow 'false' for backwards compatibility w/ 0.4
122+
θw = f.swrc(ψ; θsat, θres, swrc_kwargs...)
121123
return θw
124+
elseif output ==
125+
return ψ
126+
elseif output == :Tstar
127+
return Tstar
122128
end
123129
end
124130
end
@@ -157,18 +163,18 @@ end
157163
@inline function (f::DallAmico)(
158164
T,
159165
ψ₀=nothing,
160-
::Val{return_all}=Val{false}();
166+
::Val{output}=Val{:θw}();
161167
θtot=stripparams(f.swrc.water.θtot),
162168
θsat=stripparams(f.swrc.water.θsat),
163169
θres=stripparams(f.swrc.water.θres),
164170
Tₘ=f.freezethaw.Tₘ,
165171
swrc_kwargs...
166-
) where return_all
172+
) where output
167173
# Dall'Amico is a special case of Painter-Karra with ω = β = 1
168174
pkfc = PainterKarra()
169175
ω = 1.0
170176
β = 1.0
171-
return pkfc(T, ψ₀, Val{return_all}(); θtot, θsat, θres, Tₘ, ω, β, swrc_kwargs...)
177+
return pkfc(T, ψ₀, Val{output}(); θtot, θsat, θres, Tₘ, ω, β, swrc_kwargs...)
172178
end
173179
function inflectionpoint(
174180
f::DallAmico,
@@ -200,14 +206,14 @@ end
200206
function (f::DallAmicoSalt)(
201207
T,
202208
ψ₀=nothing,
203-
::Val{return_all}=Val{false}();
209+
::Val{output}=Val{:θw}();
204210
θtot=stripparams(f.swrc.water.θtot),
205211
θsat=stripparams(f.swrc.water.θsat),
206212
θres=stripparams(f.swrc.water.θres),
207213
Tₘ=f.freezethaw.Tₘ,
208214
saltconc=f.saltconc,
209215
swrc_kwargs...
210-
) where return_all
216+
) where output
211217
let θsat = max(θtot, θsat),
212218
ψ₀ = isnothing(ψ₀) ? waterpotential(swrc(f), θtot; θsat, θres, swrc_kwargs...) : ψ₀,
213219
g = f.g,
@@ -222,12 +228,17 @@ function (f::DallAmicoSalt)(
222228
# water matric potential
223229
ψ = ψ₀ + Lf / (ρw * g * Tstar) * (T - Tstar) * heaviside(Tstar-T),
224230
ψ = IfElse.ifelse< zero(ψ), ψ, zero(ψ));
225-
# van Genuchten evaulation to get θw
226-
θw = f.swrc(ψ; θres, θsat, swrc_kwargs...)
227-
if return_all
231+
# output is a compile-time constant so will be compiled away
232+
if output == :all || output == true # allow 'true' for backwards compatibility w/ 0.4
233+
θw = f.swrc(ψ; θsat, θres, swrc_kwargs...)
228234
return (; θw, ψ, Tstar)
229-
else
235+
elseif output == :θw || output == false # allow 'false' for backwards compatibility w/ 0.4
236+
θw = f.swrc(ψ; θsat, θres, swrc_kwargs...)
230237
return θw
238+
elseif output ==
239+
return ψ
240+
elseif output == :Tstar
241+
return Tstar
231242
end
232243
end
233244
end

test/sfcc_tests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FreezeCurves
2+
using ModelParameters
23
using Test
34
using Unitful
45

@@ -38,6 +39,13 @@ using Unitful
3839
@test f(0.0u"°C"; θtot,θsat,θres,Tₘ,α,n) θtot
3940
θw = f(-0.1u"°C"; θtot,θsat,θres,Tₘ,α,n)
4041
@test θw > 0.0 && θw < θtot
42+
f_stripped = stripparams(f)
43+
res = f_stripped(-0.1u"°C", 0.0u"m", Val{:all}(); θtot,θsat,θres,Tₘ,α,n)
44+
@test keys(res) == (:θw,,:Tstar)
45+
ψ = f_stripped(-0.1u"°C", 0.0u"m", Val{:ψ}(); θtot,θsat,θres,Tₘ,α,n)
46+
@test ψ == res.ψ
47+
Tstar = f_stripped(-0.1u"°C", 0.0u"m", Val{:Tstar}(); θtot,θsat,θres,Tₘ,α,n)
48+
@test Tstar == res.Tstar
4149
end
4250
end
4351
@testset "DallAmico freeze curve" begin
@@ -67,6 +75,13 @@ using Unitful
6775
@test θw > 0.0 && θw < θtot
6876
θw_nosalt = f(-5.0u"°C"; θtot,θsat,θres,Tₘ,saltconc=zero(saltconc),α,n)
6977
@test θw > θw_nosalt
78+
f_stripped = stripparams(f)
79+
res = f_stripped(-0.1u"°C", 0.0u"m", Val{:all}(); θtot,θsat,θres,Tₘ,α,n)
80+
@test keys(res) == (:θw,,:Tstar)
81+
ψ = f_stripped(-0.1u"°C", 0.0u"m", Val{:ψ}(); θtot,θsat,θres,Tₘ,α,n)
82+
@test ψ == res.ψ
83+
Tstar = f_stripped(-0.1u"°C", 0.0u"m", Val{:Tstar}(); θtot,θsat,θres,Tₘ,α,n)
84+
@test Tstar == res.Tstar
7085
end
7186
end
7287
end

0 commit comments

Comments
 (0)