@@ -18,11 +18,17 @@ abstract type SWRC end
1818"""
1919 Base.inv(f::SWRC)
2020
21- Returns a function `(args...) -> f(inv, args...)` which, when implemented, evaluates the inverse of the
22- soil water retention curve.
21+ Returns a function that evaluates the inverse of the soil water retention curve, `f`.
2322"""
2423Base. inv (f:: SWRC ) = (args... ; kwargs... ) -> f (inv, args... ; kwargs... )
2524
25+ """
26+ derivative(f::SWRC)
27+
28+ Returns a function that evaluates the derivative `∂f∂ψ` of the soil water retention curve, `f`.
29+ """
30+ derivative (f:: SWRC ) = (args... ; kwargs... ) -> f (derivative, args... , kwargs... )
31+
2632"""
2733 SoilWaterVolume{Tρw,Tθres,Tθsat}
2834
@@ -78,9 +84,10 @@ function (f::VanGenuchten)(ψ; θsat=f.vol.θsat, θres=f.vol.θres, α=f.α, n=
7884 let m = 1 - 1 / n,
7985 x = 1 + (- α* ψ)^ n;
8086 # @assert isnan(x) || x > zero(x) "van Genuchten violated constraint $x > 0 with input $ψ and parameters θsat=$θsat, θres=$θres, α=$α, n=$n"
81- IfElse. ifelse (ψ <= zero (ψ), θres + (θsat - θres)* x^ (- m), θsat* one (ψ))
87+ IfElse. ifelse (ψ < zero (ψ), θres + (θsat - θres)* x^ (- m), θsat* one (ψ))
8288 end
8389end
90+
8491function (f:: VanGenuchten )(
8592 :: typeof (inv),
8693 θ;
@@ -94,6 +101,21 @@ function (f::VanGenuchten)(
94101 end
95102end
96103
104+ function (f:: VanGenuchten )(
105+ :: typeof (derivative),
106+ ψ;
107+ θsat= f. vol. θsat,
108+ θres= f. vol. θres,
109+ α= f. α,
110+ n= f. n
111+ )
112+ let m = 1 - 1 / n,
113+ x = 1 + (- α* ψ)^ n;
114+ # @assert isnan(x) || x > zero(x) "van Genuchten violated constraint $x > 0 with input $ψ and parameters θsat=$θsat, θres=$θres, α=$α, n=$n"
115+ IfElse. ifelse (ψ < zero (ψ), α* n* m* (θsat - θres)* x^ (- m- 1 )* (- α* ψ)^ (n- 1 ), 0 )
116+ end
117+ end
118+
97119inflectionpoint (f:: VanGenuchten ; α= f. α, n= f. n) = - 1 / α* ((n - 1 ) / n)^ (1 / n)
98120
99121# Preset Van Genucthen curves from soil types;
@@ -121,6 +143,7 @@ Base.@kwdef struct BrooksCorey{Tvol,Tψₛ,Tλ} <: SWRC
121143 ψₛ:: T ψₛ = 0.01 u " m"
122144 λ:: T λ = 0.2 # domain: (0,Inf)
123145end
146+
124147function (f:: BrooksCorey )(
125148 ψ;
126149 θsat= f. vol. θsat,
@@ -130,6 +153,7 @@ function (f::BrooksCorey)(
130153)
131154 IfElse. ifelse (ψ < - ψₛ, θres + (θsat - θres)* (- ψₛ / ψ)^ λ, θsat* one (ψ))
132155end
156+
133157function (f:: BrooksCorey )(
134158 :: typeof (inv),
135159 θ;
@@ -140,4 +164,16 @@ function (f::BrooksCorey)(
140164)
141165 IfElse. ifelse (θ < θsat, - ψₛ* ((θ - θres)/ (θsat - θres))^ (- 1 / λ), - ψₛ* one (θ))
142166end
167+
168+ function (f:: BrooksCorey )(
169+ :: typeof (derivative),
170+ ψ;
171+ θsat= f. vol. θsat,
172+ θres= f. vol. θres,
173+ ψₛ= f. ψₛ,
174+ λ= f. λ
175+ )
176+ IfElse. ifelse (ψ < - ψₛ, (θsat - θres)* λ* (- ψₛ / ψ)^ (λ- 1 )* (ψₛ* ψ^- 2 ), θsat* one (ψ))
177+ end
178+
143179inflectionpoint (f:: BrooksCorey ; ψₛ= f. ψₛ) = ψₛ
0 commit comments