Skip to content

Commit

Permalink
Rename SorptivityProblem to SorptivityCauchyProblem
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlero committed Dec 18, 2023
1 parent cdd7226 commit 5c2180a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/src/problems.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Problem
DirichletProblem
FlowrateProblem
CauchyProblem
SorptivityProblem
SorptivityCauchyProblem
FiniteProblem
FiniteDirichletProblem
FiniteReservoirProblem
Expand Down
2 changes: 1 addition & 1 deletion src/Fronts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export Equation, DiffusionEquation, RichardsEquation, diffusivity, flow_diffusiv
export d_do, d_dr, d_dt, boltzmann
export sorptivity
export Problem,
DirichletProblem, FlowrateProblem, CauchyProblem, SorptivityProblem, monotonicity
DirichletProblem, FlowrateProblem, CauchyProblem, SorptivityCauchyProblem, monotonicity
export BoltzmannODE
export MathiasAndSander
export solve
Expand Down
14 changes: 7 additions & 7 deletions src/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ end

"""
boltzmann(prob::CauchyProblem) -> DifferentialEquations.ODEProblem
boltzmann(prob::SorptivityProblem) -> DifferentialEquations.ODEProblem
boltzmann(prob::SorptivityCauchyProblem) -> DifferentialEquations.ODEProblem
Transform `prob` into an ODE problem in terms of the Boltzmann variable `o`.
The ODE problem is set up to terminate automatically (`ReturnCode.Terminated`) when the steady state is reached.
See also: [`DifferentialEquations`](https://diffeq.sciml.ai/stable/)
"""
function boltzmann(prob::Union{CauchyProblem, SorptivityProblem})
function boltzmann(prob::Union{CauchyProblem, SorptivityCauchyProblem})
if prob isa CauchyProblem
u0 = @SVector [prob.b, prob.d_dob]
elseif prob isa SorptivityProblem
elseif prob isa SorptivityCauchyProblem
u0 = @SVector [prob.b, d_do(prob.eq, prob.b, prob.S)]
end

Expand All @@ -54,7 +54,7 @@ end
const _ODE_ALG = RadauIIA5()
const _ODE_MAXITERS = 1000

function _init(prob::Union{CauchyProblem, SorptivityProblem},
function _init(prob::Union{CauchyProblem, SorptivityCauchyProblem},
::BoltzmannODE;
limit = nothing,
verbose = true)
Expand Down Expand Up @@ -82,15 +82,15 @@ function _reinit!(integrator, prob::CauchyProblem)
return integrator
end

function _reinit!(integrator, prob::SorptivityProblem)
function _reinit!(integrator, prob::SorptivityCauchyProblem)
@assert -sign(prob.S) == sign(integrator.sol.u[1][2])
reinit!(integrator, @SVector [prob.b, d_do(prob.eq, prob.b, prob.S)])
return integrator
end

"""
solve(prob::CauchyProblem[, alg::BoltzmannODE; verbose]) -> Solution
solve(prob::SorptivityProblem[, alg::BoltzmannODE; verbose]) -> Solution
solve(prob::SorptivityCauchyProblem[, alg::BoltzmannODE; verbose]) -> Solution
Solve the problem `prob`.
Expand All @@ -107,7 +107,7 @@ Capillarity, 2023, vol. 6, no. 2, p. 31-40.
See also: [`Solution`](@ref), [`BoltzmannODE`](@ref)
"""
function solve(prob::Union{CauchyProblem, SorptivityProblem},
function solve(prob::Union{CauchyProblem, SorptivityCauchyProblem},
alg::BoltzmannODE = BoltzmannODE();
verbose = true)
odesol = solve!(_init(prob, alg, verbose = verbose))
Expand Down
24 changes: 12 additions & 12 deletions src/problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ monotonicity(prob::CauchyProblem)::Int = sign(prob.d_dob)
sorptivity(prob::CauchyProblem) = sorptivity(prob.eq, prob.b, prob.d_dob)

"""
SorptivityProblem(eq; b, S[, ob]) <: Problem{typeof(eq)}
SorptivityProblem(D; b, S[, ob]) <: Problem{DiffusionEquation{1}}
SorptivityCauchyProblem(eq; b, S[, ob]) <: Problem{typeof(eq)}
SorptivityCauchyProblem(D; b, S[, ob]) <: Problem{DiffusionEquation{1}}
Semi-infinite problem with a known boundary value and soprtivity (and unknown initial condition).
# Arguments
- `eq::Equation`: governing equation.
- `D`: diffusivity function. Shortcut for `SorptivityProblem(DiffusionEquation(D), ...)`.
- `D`: diffusivity function. Shortcut for `SorptivityCauchyProblem(DiffusionEquation(D), ...)`.
# Keyword arguments
- `b`: imposed boundary value.
Expand All @@ -242,33 +242,33 @@ Semi-infinite problem with a known boundary value and soprtivity (and unknown in
julia> D(θ) = θ^4
D (generic function with 1 method)
julia> prob = Fronts.SorptivityProblem(D, b=2, S=1)
julia> prob = Fronts.SorptivityCauchyProblem(D, b=2, S=1)
⎧ ∂θ/∂t = ∂(D(θ)*∂θ/∂r)/∂r, r>0,t>0
⎨ θ(0,t) = 2, t>0
⎩ S = 1
```
See also: [`Equation`](@ref), [`sorptivity`](@ref)
"""
struct SorptivityProblem{Teq, _T, _To, _TS} <: Problem{Teq}
struct SorptivityCauchyProblem{Teq, _T, _To, _TS} <: Problem{Teq}
eq::Teq
b::_T
S::_TS
ob::_To
function SorptivityProblem(eq::Equation{1}; b, S, ob = 0)
function SorptivityCauchyProblem(eq::Equation{1}; b, S, ob = 0)
new{typeof(eq), typeof(b), typeof(ob), typeof(S)}(eq, b, S, ob)
end
function SorptivityProblem(eq::Equation; b, S, ob)
function SorptivityCauchyProblem(eq::Equation; b, S, ob)
@argcheck ob > zero(ob)
new{typeof(eq), typeof(b), typeof(ob), typeof(S)}(eq, b, S, ob)
end
end

function SorptivityProblem(D; b, S, ob = 0)
SorptivityProblem(DiffusionEquation(D), b = b, S = S, ob = ob)
function SorptivityCauchyProblem(D; b, S, ob = 0)
SorptivityCauchyProblem(DiffusionEquation(D), b = b, S = S, ob = ob)
end

function Base.show(io::IO, prob::SorptivityProblem)
function Base.show(io::IO, prob::SorptivityCauchyProblem)
if iszero(prob.ob)
println(io, "", prob.eq, ", r>0,t>0")
println(io, "", prob.eq.sym, "(0,t) = ", prob.b, ", t>0")
Expand All @@ -281,6 +281,6 @@ function Base.show(io::IO, prob::SorptivityProblem)
end
end

monotonicity(prob::SorptivityProblem)::Int = -sign(prob.S)
monotonicity(prob::SorptivityCauchyProblem)::Int = -sign(prob.S)

sorptivity(prob::SorptivityProblem) = prob.S
sorptivity(prob::SorptivityCauchyProblem) = prob.S
8 changes: 5 additions & 3 deletions src/shooting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ function solve(prob::FlowrateProblem; alg::BoltzmannODE = BoltzmannODE(),
resid = prob.i - oneunit(prob.i) * monotonicity(prob)
S = 2prob.Qb / prob._αh / ob

integrator = _init(SorptivityProblem(prob.eq, b = b_hint, S = S, ob = ob),
integrator = _init(SorptivityCauchyProblem(prob.eq, b = b_hint, S = S, ob = ob),
alg,
limit = limit,
verbose = false)

if iszero(direction)
_reinit!(integrator, SorptivityProblem(prob.eq, b = prob.i, S = zero(S), ob = ob))
_reinit!(integrator,
SorptivityCauchyProblem(prob.eq, b = prob.i, S = zero(S), ob = ob))
solve!(integrator)

@assert integrator.sol.retcode != ReturnCode.Success
Expand All @@ -157,7 +158,8 @@ function solve(prob::FlowrateProblem; alg::BoltzmannODE = BoltzmannODE(),
b_trial = bracket_bisect(prob.i, b_hint)

for niter in 1:maxiters
_reinit!(integrator, SorptivityProblem(prob.eq, b = b_trial(resid), S = S, ob = ob))
_reinit!(integrator,
SorptivityCauchyProblem(prob.eq, b = b_trial(resid), S = S, ob = ob))
solve!(integrator)

@assert integrator.sol.retcode != ReturnCode.Success
Expand Down
4 changes: 2 additions & 2 deletions test/test_cauchy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
end
end

@testset "SorptivityProblem" begin
@testset "SorptivityCauchyProblem" begin
@testset "exact" begin
# Reference: Philip (1960) Table 1, No. 13
# https://doi.org/10.1071/PH600001
D = θ -> 0.5 * (1 - NaNMath.log(θ))

prob = SorptivityProblem(D, b = 1, S = 1)
prob = SorptivityCauchyProblem(D, b = 1, S = 1)
@test sorptivity(prob) == 1

θ = solve(prob)
Expand Down

0 comments on commit 5c2180a

Please sign in to comment.