From 19fb77321e9945e44bdb674cfda59ff7aa71c9cd Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sun, 1 Oct 2023 21:40:12 -0400 Subject: [PATCH] make construction of type stable TP BVProblem easier --- Project.toml | 2 +- src/problems/bvp_problems.jl | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 364102ac5..332168cd1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SciMLBase" uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462" authors = ["Chris Rackauckas and contributors"] -version = "2.0.7" +version = "2.1.0" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/src/problems/bvp_problems.jl b/src/problems/bvp_problems.jl index 2e9f1feab..b15b5d6a9 100644 --- a/src/problems/bvp_problems.jl +++ b/src/problems/bvp_problems.jl @@ -6,7 +6,7 @@ struct StandardBVProblem end """ $(TYPEDEF) """ -struct TwoPointBVProblem end +struct TwoPointBVProblem{iip} end # The iip is needed to make type stable construction easier @doc doc""" @@ -112,7 +112,7 @@ struct BVProblem{uType, tType, isinplace, P, F, BF, PT, K} <: p = NullParameters(); problem_type=nothing, kwargs...) where {iip, TP} _tspan = promote_tspan(tspan) warn_paramtype(p) - prob_type = TP ? TwoPointBVProblem() : StandardBVProblem() + prob_type = TP ? TwoPointBVProblem{iip}() : StandardBVProblem() # Needed to ensure that `problem_type` doesn't get passed in kwargs if problem_type === nothing problem_type = prob_type @@ -149,11 +149,21 @@ struct TwoPointBVPFunction{iip} end return BVPFunction{iip}(args...; kwargs..., twopoint=true) end +function TwoPointBVProblem{iip}(f, bc, u0, tspan, p = NullParameters(); + bcresid_prototype=nothing, kwargs...) where {iip} + return TwoPointBVProblem(TwoPointBVPFunction{iip}(f, bc; bcresid_prototype), u0, tspan, p; + kwargs...) +end function TwoPointBVProblem(f, bc, u0, tspan, p = NullParameters(); bcresid_prototype=nothing, kwargs...) return TwoPointBVProblem(TwoPointBVPFunction(f, bc; bcresid_prototype), u0, tspan, p; kwargs...) end +function TwoPointBVProblem{iip}(f::AbstractBVPFunction{iip, twopoint}, u0, tspan, + p = NullParameters(); kwargs...) where {iip, twopoint} + @assert twopoint "`TwoPointBVProblem` can only be used with a `TwoPointBVPFunction`. Instead of using `BVPFunction`, use `TwoPointBVPFunction` or pass a kwarg `twopoint=true` during the construction of the `BVPFunction`." + return BVProblem{iip}(f, f.bc, u0, tspan, p; kwargs...) +end function TwoPointBVProblem(f::AbstractBVPFunction{iip, twopoint}, u0, tspan, p = NullParameters(); kwargs...) where {iip, twopoint} @assert twopoint "`TwoPointBVProblem` can only be used with a `TwoPointBVPFunction`. Instead of using `BVPFunction`, use `TwoPointBVPFunction` or pass a kwarg `twopoint=true` during the construction of the `BVPFunction`."