Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Problem to AbstractProblem #162

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/problems.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CurrentModule = Fronts
# Problems

```@docs
Problem
AbstractProblem
DirichletProblem
FlowrateProblem
SorptivityProblem
Expand Down
5 changes: 2 additions & 3 deletions src/Fronts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ include("finite.jl")
export DiffusionEquation, diffusivity, conductivity, capacity
export d_do, d_dr, d_dt, boltzmann
export sorptivity
export Problem,
DirichletProblem, FlowrateProblem, CauchyProblem, SorptivityProblem,
SorptivityCauchyProblem, monotonicity
export AbstractProblem, Problem, DirichletProblem, FlowrateProblem, CauchyProblem,
SorptivityProblem, SorptivityCauchyProblem, monotonicity
export BoltzmannODE
export MathiasAndSander
export solve
Expand Down
14 changes: 7 additions & 7 deletions src/ParamEstim.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ParamEstim

import ..Fronts
using ..Fronts: InverseProblem, Problem, Solution, ReturnCode, solve
using ..Fronts: InverseProblem, AbstractProblem, Solution, ReturnCode, solve
import ..Fronts: sorptivity

using LsqFit: curve_fit
Expand Down Expand Up @@ -69,8 +69,8 @@

# Arguments
- `func`: function that takes a vector of parameter values and returns either a `Fronts.Solution` or a
`Fronts.Problem`. If func returns a `Problem`, it is solved with `solve`. `Solution`s with a `ReturnCode`
of `Success` are passed to the cost function; otherwise, the cost is set to `Inf`.
`Fronts.AbstractProblem`. If func returns an `AbstractProblem`, it is solved with `solve`. `Solution`s
with successful `ReturnCode` are passed to the cost function; otherwise, the cost is set to `Inf`.
- `prob`: inverse problem. See [`InverseProblem`](@ref).

# Keyword arguments
Expand All @@ -84,7 +84,7 @@
inverse solving of horizontal capillary flow.
Capillarity, 2023, vol. 6, no. 2, p. 31-40.

See also: [`candidate`](@ref), [`ScaledSolution`](@ref), [`Fronts.Solution`](@ref), [`Fronts.Problem`](@ref)
See also: [`candidate`](@ref), [`ScaledSolution`](@ref), [`Fronts.Solution`](@ref), [`Fronts.AbstractProblem`](@ref)

---

Expand Down Expand Up @@ -140,18 +140,18 @@
end

_solve(cf::RSSCostFunction, params::AbstractVector) = _solve(cf, cf._func(params))
_solve(::RSSCostFunction, prob::Problem) = solve(prob, verbose = false)
_solve(::RSSCostFunction, prob::AbstractProblem) = solve(prob, verbose = false)
_solve(::RSSCostFunction, sol::Solution) = sol

"""
candidate(cf::RSSCostFunction, ::AbstractVector)
candidate(cf::RSSCostFunction, ::Fronts.Problem)
candidate(cf::RSSCostFunction, ::Fronts.AbstractProblem)
candidate(cf::RSSCostFunction, ::Fronts.Solution)

Return the candidate solution for a given cost function and parameter values, problem, or solution.
"""
candidate(cf::RSSCostFunction, params::AbstractVector) = candidate(cf, _solve(cf, params))
candidate(cf::RSSCostFunction, prob::Problem) = candidate(cf, _solve(cf, prob))
candidate(cf::RSSCostFunction, prob::AbstractProblem) = candidate(cf, _solve(cf, prob))

Check warning on line 154 in src/ParamEstim.jl

View check run for this annotation

Codecov / codecov/patch

src/ParamEstim.jl#L154

Added line #L154 was not covered by tests
candidate(::RSSCostFunction{false}, sol::Solution) = sol

function candidate(cf::RSSCostFunction{true}, sol::Solution)
Expand Down
32 changes: 16 additions & 16 deletions src/problems.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
abstract type Problem{Eq <: DiffusionEquation} end
abstract type AbstractProblem{Eq <: DiffusionEquation} end

Abstract supertype for problems that can be solved with this package.

Expand All @@ -8,7 +8,7 @@ Abstract supertype for problems that can be solved with this package.

See also: [`DiffusionEquation`](@ref)
"""
abstract type Problem{Eq <: DiffusionEquation} end
abstract type AbstractProblem{Eq <: DiffusionEquation} end

"""
monotonicity(prob) -> Int
Expand All @@ -18,8 +18,8 @@ Whether the solution to `prob` must be decreasing (`-1`), constant (`0`) or incr
function monotonicity end

"""
DirichletProblem(eq::DiffusionEquation; i, b[, ob]) <: Problem{typeof(eq)}
DirichletProblem(D; i, b[, ob]) <: Problem{DiffusionEquation{1}}
DirichletProblem(eq::DiffusionEquation; i, b[, ob]) <: AbstractProblem{typeof(eq)}
DirichletProblem(D; i, b[, ob]) <: AbstractProblem{DiffusionEquation{1}}

Semi-infinite problem with a Dirichlet boundary condition.

Expand All @@ -45,7 +45,7 @@ julia> prob = Fronts.DirichletProblem(D, i=1, b=2)

See also: [`DiffusionEquation`](@ref)
"""
struct DirichletProblem{Teq, _T, _To} <: Problem{Teq}
struct DirichletProblem{Teq, _T, _To} <: AbstractProblem{Teq}
eq::Teq
i::_T
b::_T
Expand Down Expand Up @@ -81,7 +81,7 @@ end
monotonicity(prob::DirichletProblem)::Int = sign(prob.i - prob.b)

"""
FlowrateProblem(eq::DiffusionEquation{2}; i, Qb[, angle, height, ob]) <: Problem{typeof(eq)}
FlowrateProblem(eq::DiffusionEquation{2}; i, Qb[, angle, height, ob]) <: AbstractProblem{typeof(eq)}

Semi-infinite radial (polar/cylindrical) problem with an imposed-flowrate boundary condition.

Expand Down Expand Up @@ -111,7 +111,7 @@ julia> prob = Fronts.FlowrateProblem(eq, i=1, Qb=1)

See also: [`DiffusionEquation`](@ref)
"""
struct FlowrateProblem{Teq, _T, _To, _TQ, _Th} <: Problem{Teq}
struct FlowrateProblem{Teq, _T, _To, _TQ, _Th} <: AbstractProblem{Teq}
eq::Teq
i::_T
Qb::_TQ
Expand Down Expand Up @@ -155,8 +155,8 @@ end
monotonicity(prob::FlowrateProblem)::Int = -sign(prob.Qb)

"""
SorptivityProblem(eq::DiffusionEquation; i, S[, ob]) <: Problem{typeof(eq)}
SorptivityProblem(D; i, S[, ob]) <: Problem{typeof(eq)}
SorptivityProblem(eq::DiffusionEquation; i, S[, ob]) <: AbstractProblem{typeof(eq)}
SorptivityProblem(D; i, S[, ob]) <: AbstractProblem{typeof(eq)}

Semi-infinite problem with a known initial condition and soprtivity.

Expand All @@ -182,7 +182,7 @@ julia> prob = Fronts.SorptivityProblem(D, i=0, S=1)

See also: [`DiffusionEquation`](@ref), [`sorptivity`](@ref)
"""
struct SorptivityProblem{Teq, _T, _To, _TS} <: Problem{Teq}
struct SorptivityProblem{Teq, _T, _To, _TS} <: AbstractProblem{Teq}
eq::Teq
i::_T
S::_TS
Expand Down Expand Up @@ -218,8 +218,8 @@ monotonicity(prob::SorptivityProblem)::Int = -sign(prob.S)
sorptivity(prob::SorptivityProblem) = prob.S

"""
CauchyProblem(eq::DiffusionEquation; b, d_dob[, ob]) <: Problem{typeof(eq)}
CauchyProblem(D; b, d_dob[, ob]) <: Problem{DiffusionEquation{1}}
CauchyProblem(eq::DiffusionEquation; b, d_dob[, ob]) <: AbstractProblem{typeof(eq)}
CauchyProblem(D; b, d_dob[, ob]) <: AbstractProblem{DiffusionEquation{1}}

Semi-infinite problem with a Cauchy boundary condition (and unknown initial condition).

Expand All @@ -246,7 +246,7 @@ julia> prob = Fronts.CauchyProblem(D, b=2, d_dob=-0.1)

See also: [`DiffusionEquation`](@ref)
"""
struct CauchyProblem{Teq, _T, _To, _Td_do} <: Problem{Teq}
struct CauchyProblem{Teq, _T, _To, _Td_do} <: AbstractProblem{Teq}
eq::Teq
b::_T
d_dob::_Td_do
Expand Down Expand Up @@ -282,8 +282,8 @@ monotonicity(prob::CauchyProblem)::Int = sign(prob.d_dob)
sorptivity(prob::CauchyProblem) = sorptivity(prob.eq, prob.b, prob.d_dob)

"""
SorptivityCauchyProblem(eq::DiffusionEquation; b, S[, ob]) <: Problem{typeof(eq)}
SorptivityCauchyProblem(D; b, S[, ob]) <: Problem{DiffusionEquation{1}}
SorptivityCauchyProblem(eq::DiffusionEquation; b, S[, ob]) <: AbstractProblem{typeof(eq)}
SorptivityCauchyProblem(D; b, S[, ob]) <: AbstractProblem{DiffusionEquation{1}}

Semi-infinite problem with a known boundary value and soprtivity (and unknown initial condition).

Expand All @@ -309,7 +309,7 @@ julia> prob = Fronts.SorptivityCauchyProblem(D, b=2, S=1)

See also: [`DiffusionEquation`](@ref), [`sorptivity`](@ref)
"""
struct SorptivityCauchyProblem{Teq, _T, _To, _TS} <: Problem{Teq}
struct SorptivityCauchyProblem{Teq, _T, _To, _TS} <: AbstractProblem{Teq}
eq::Teq
b::_T
S::_TS
Expand Down
Loading