Skip to content

Commit

Permalink
make construction of type stable TP BVProblem easier
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 2, 2023
1 parent 75b1925 commit 19fb773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SciMLBase"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
authors = ["Chris Rackauckas <[email protected]> and contributors"]
version = "2.0.7"
version = "2.1.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
14 changes: 12 additions & 2 deletions src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Check warning on line 152 in src/problems/bvp_problems.jl

View check run for this annotation

Codecov / codecov/patch

src/problems/bvp_problems.jl#L152

Added line #L152 was not covered by tests
bcresid_prototype=nothing, kwargs...) where {iip}
return TwoPointBVProblem(TwoPointBVPFunction{iip}(f, bc; bcresid_prototype), u0, tspan, p;

Check warning on line 154 in src/problems/bvp_problems.jl

View check run for this annotation

Codecov / codecov/patch

src/problems/bvp_problems.jl#L154

Added line #L154 was not covered by tests
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,

Check warning on line 162 in src/problems/bvp_problems.jl

View check run for this annotation

Codecov / codecov/patch

src/problems/bvp_problems.jl#L162

Added line #L162 was not covered by tests
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...)

Check warning on line 165 in src/problems/bvp_problems.jl

View check run for this annotation

Codecov / codecov/patch

src/problems/bvp_problems.jl#L164-L165

Added lines #L164 - L165 were not covered by tests
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`."
Expand Down

0 comments on commit 19fb773

Please sign in to comment.