From ca40c06bcd947e14becb29765ec449ef25eca4dc Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Sun, 24 Dec 2023 16:22:55 -0300 Subject: [PATCH] Rename Problem to AbstractProblem --- docs/src/problems.md | 2 +- src/Fronts.jl | 5 ++--- src/ParamEstim.jl | 14 +++++++------- src/problems.jl | 32 ++++++++++++++++---------------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/docs/src/problems.md b/docs/src/problems.md index aadfa592..3a421412 100644 --- a/docs/src/problems.md +++ b/docs/src/problems.md @@ -5,7 +5,7 @@ CurrentModule = Fronts # Problems ```@docs -Problem +AbstractProblem DirichletProblem FlowrateProblem SorptivityProblem diff --git a/src/Fronts.jl b/src/Fronts.jl index f75c0fbd..42d57ec2 100644 --- a/src/Fronts.jl +++ b/src/Fronts.jl @@ -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 diff --git a/src/ParamEstim.jl b/src/ParamEstim.jl index 9bbbe218..ce1a1c57 100644 --- a/src/ParamEstim.jl +++ b/src/ParamEstim.jl @@ -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 @@ -69,8 +69,8 @@ factors affecting the diffusivity are unknown, it is recommended not to fit thos # 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 @@ -84,7 +84,7 @@ GERLERO, G. S.; BERLI, C. L. A.; KLER, P. A. Open-source high-performance softwa 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) --- @@ -140,18 +140,18 @@ function (cf::RSSCostFunction)(params::AbstractVector, ::NullParameters = NullPa 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)) candidate(::RSSCostFunction{false}, sol::Solution) = sol function candidate(cf::RSSCostFunction{true}, sol::Solution) diff --git a/src/problems.jl b/src/problems.jl index 431698c6..57d03827 100644 --- a/src/problems.jl +++ b/src/problems.jl @@ -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. @@ -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 @@ -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. @@ -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 @@ -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. @@ -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 @@ -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. @@ -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 @@ -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). @@ -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 @@ -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). @@ -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