From 97631c54e15c74c6397255df0433e854270aec26 Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Wed, 27 Dec 2023 16:01:45 -0300 Subject: [PATCH] Rename AbstractProblem to AbstractSemiinfiniteProblem --- docs/src/problems.md | 2 +- src/Fronts.jl | 4 ++-- src/ParamEstim.jl | 19 ++++++++++++------- src/problems.jl | 32 ++++++++++++++++---------------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/docs/src/problems.md b/docs/src/problems.md index 3706f949..0b28cf80 100644 --- a/docs/src/problems.md +++ b/docs/src/problems.md @@ -5,7 +5,7 @@ CurrentModule = Fronts # Problems ```@docs -AbstractProblem +AbstractSemiinfiniteProblem DirichletProblem FlowrateProblem SorptivityProblem diff --git a/src/Fronts.jl b/src/Fronts.jl index c9dc5132..9d5db553 100644 --- a/src/Fronts.jl +++ b/src/Fronts.jl @@ -43,8 +43,8 @@ include("finite.jl") export DiffusionEquation, diffusivity, conductivity, capacity export d_do, d_dr, d_dt, boltzmann export sorptivity -export AbstractProblem, Problem, DirichletProblem, FlowrateProblem, CauchyProblem, - SorptivityProblem, SorptivityCauchyProblem, monotonicity +export AbstractSemiinfiniteProblem, Problem, DirichletProblem, FlowrateProblem, + CauchyProblem, SorptivityProblem, SorptivityCauchyProblem, monotonicity export BoltzmannODE export MathiasAndSander export solve diff --git a/src/ParamEstim.jl b/src/ParamEstim.jl index 312bef00..ce2e22e8 100644 --- a/src/ParamEstim.jl +++ b/src/ParamEstim.jl @@ -1,7 +1,7 @@ module ParamEstim import ..Fronts -using ..Fronts: InverseProblem, AbstractProblem, Solution, ReturnCode, solve +using ..Fronts: InverseProblem, AbstractSemiinfiniteProblem, Solution, ReturnCode, solve import ..Fronts: sorptivity using LsqFit: curve_fit @@ -75,19 +75,23 @@ function (cf::AbstractCostFunction)(params::AbstractVector, end _solve(cf::AbstractCostFunction, params::AbstractVector) = _solve(cf, cf._func(params)) -_solve(::AbstractCostFunction, prob::AbstractProblem) = solve(prob, verbose = false) +function _solve(::AbstractCostFunction, prob::AbstractSemiinfiniteProblem) + solve(prob, verbose = false) +end _solve(::AbstractCostFunction, sol::Solution) = sol """ candidate(cf::AbstractCostFunction, ::AbstractVector) - candidate(cf::AbstractCostFunction, ::Fronts.AbstractProblem) + candidate(cf::AbstractCostFunction, ::Fronts.AbstractSemiinfiniteProblem) candidate(cf::AbstractCostFunction, ::Fronts.Solution) Return the candidate solution for a given cost function and parameter values, problem, or solution. """ candidate(cf::AbstractCostFunction, params::AbstractVector) = candidate(cf, _solve(cf, params)) -candidate(cf::AbstractCostFunction, prob::AbstractProblem) = candidate(cf, _solve(cf, prob)) +function candidate(cf::AbstractCostFunction, prob::AbstractSemiinfiniteProblem) + candidate(cf, _solve(cf, prob)) +end candidate(::AbstractCostFunction{false}, sol::Solution) = sol """ @@ -104,8 +108,9 @@ 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.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`. +`Fronts.AbstractSemiinfiniteProblem`. If func returns an `AbstractSemiinfiniteProblem`, 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 @@ -119,7 +124,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.AbstractProblem`](@ref) +See also: [`candidate`](@ref), [`ScaledSolution`](@ref), [`Fronts.Solution`](@ref), [`Fronts.AbstractSemiinfiniteProblem`](@ref) --- diff --git a/src/problems.jl b/src/problems.jl index 57d03827..ec33f82a 100644 --- a/src/problems.jl +++ b/src/problems.jl @@ -1,5 +1,5 @@ """ - abstract type AbstractProblem{Eq <: DiffusionEquation} end + abstract type AbstractSemiinfiniteProblem{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 AbstractProblem{Eq <: DiffusionEquation} end +abstract type AbstractSemiinfiniteProblem{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]) <: AbstractProblem{typeof(eq)} - DirichletProblem(D; i, b[, ob]) <: AbstractProblem{DiffusionEquation{1}} + DirichletProblem(eq::DiffusionEquation; i, b[, ob]) <: AbstractSemiinfiniteProblem{typeof(eq)} + DirichletProblem(D; i, b[, ob]) <: AbstractSemiinfiniteProblem{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} <: AbstractProblem{Teq} +struct DirichletProblem{Teq, _T, _To} <: AbstractSemiinfiniteProblem{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]) <: AbstractProblem{typeof(eq)} + FlowrateProblem(eq::DiffusionEquation{2}; i, Qb[, angle, height, ob]) <: AbstractSemiinfiniteProblem{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} <: AbstractProblem{Teq} +struct FlowrateProblem{Teq, _T, _To, _TQ, _Th} <: AbstractSemiinfiniteProblem{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]) <: AbstractProblem{typeof(eq)} - SorptivityProblem(D; i, S[, ob]) <: AbstractProblem{typeof(eq)} + SorptivityProblem(eq::DiffusionEquation; i, S[, ob]) <: AbstractSemiinfiniteProblem{typeof(eq)} + SorptivityProblem(D; i, S[, ob]) <: AbstractSemiinfiniteProblem{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} <: AbstractProblem{Teq} +struct SorptivityProblem{Teq, _T, _To, _TS} <: AbstractSemiinfiniteProblem{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]) <: AbstractProblem{typeof(eq)} - CauchyProblem(D; b, d_dob[, ob]) <: AbstractProblem{DiffusionEquation{1}} + CauchyProblem(eq::DiffusionEquation; b, d_dob[, ob]) <: AbstractSemiinfiniteProblem{typeof(eq)} + CauchyProblem(D; b, d_dob[, ob]) <: AbstractSemiinfiniteProblem{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} <: AbstractProblem{Teq} +struct CauchyProblem{Teq, _T, _To, _Td_do} <: AbstractSemiinfiniteProblem{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]) <: AbstractProblem{typeof(eq)} - SorptivityCauchyProblem(D; b, S[, ob]) <: AbstractProblem{DiffusionEquation{1}} + SorptivityCauchyProblem(eq::DiffusionEquation; b, S[, ob]) <: AbstractSemiinfiniteProblem{typeof(eq)} + SorptivityCauchyProblem(D; b, S[, ob]) <: AbstractSemiiinfiniteProblem{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} <: AbstractProblem{Teq} +struct SorptivityCauchyProblem{Teq, _T, _To, _TS} <: AbstractSemiinfiniteProblem{Teq} eq::Teq b::_T S::_TS