Skip to content

Commit

Permalink
Merge pull request #370 from ErikQQY/master
Browse files Browse the repository at this point in the history
Add BVPFunction
  • Loading branch information
ChrisRackauckas authored Sep 4, 2023
2 parents eed78d0 + 30fb3c2 commit 4c0fcdf
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/SciMLBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ function specialization(::Union{ODEFunction{iip, specialize},
ImplicitDiscreteFunction{iip, specialize},
RODEFunction{iip, specialize},
NonlinearFunction{iip, specialize},
OptimizationFunction{iip, specialize}}) where {iip,
OptimizationFunction{iip, specialize},
BVPFunction{iip, specialize}}) where {iip,
specialize}
specialize
end

specialization(f::AbstractSciMLFunction) = FullSpecialize
Expand Down Expand Up @@ -787,7 +787,7 @@ export remake

export ODEFunction, DiscreteFunction, ImplicitDiscreteFunction, SplitFunction, DAEFunction,
DDEFunction, SDEFunction, SplitSDEFunction, RODEFunction, SDDEFunction,
IncrementingODEFunction, NonlinearFunction, IntervalNonlinearFunction
IncrementingODEFunction, NonlinearFunction, IntervalNonlinearFunction, BVPFunction

export OptimizationFunction

Expand Down
32 changes: 10 additions & 22 deletions src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,53 +78,41 @@ every solve call.
* `p`: The parameters for the problem. Defaults to `NullParameters`
* `kwargs`: The keyword arguments passed onto the solves.
"""
struct BVProblem{uType, tType, isinplace, P, F, bF, PT, K} <:
struct BVProblem{uType, tType, isinplace, P, F, BF, PT, K} <:
AbstractBVProblem{uType, tType, isinplace}
f::F
bc::bF
bc::BF
u0::uType
tspan::tType
p::P
problem_type::PT
kwargs::K
@add_kwonly function BVProblem{iip}(f::AbstractODEFunction, bc, u0, tspan,

@add_kwonly function BVProblem{iip}(f::AbstractBVPFunction{iip}, bc, u0, tspan,
p = NullParameters(),
problem_type = StandardBVProblem();
kwargs...) where {iip}
_tspan = promote_tspan(tspan)
warn_paramtype(p)
new{typeof(u0), typeof(_tspan), iip, typeof(p),
typeof(f), typeof(bc),
typeof(problem_type), typeof(kwargs)}(f, bc, u0, _tspan, p,
typeof(f.f), typeof(bc),
typeof(problem_type), typeof(kwargs)}(f.f, bc, u0, _tspan, p,
problem_type, kwargs)
end

function BVProblem{iip}(f, bc, u0, tspan, p = NullParameters(); kwargs...) where {iip}
BVProblem(ODEFunction{iip}(f), bc, u0, tspan, p; kwargs...)
BVProblem(BVPFunction{iip}(f, bc), bc, u0, tspan, p; kwargs...)
end
end

TruncatedStacktraces.@truncate_stacktrace BVProblem 3 1 2

function BVProblem(f::AbstractODEFunction, bc, u0, tspan, args...; kwargs...)
BVProblem{isinplace(f, 4)}(f, bc, u0, tspan, args...; kwargs...)
end

function BVProblem(f, bc, u0, tspan, p = NullParameters(); kwargs...)
BVProblem(ODEFunction(f), bc, u0, tspan, p; kwargs...)
BVProblem(BVPFunction(f, bc), u0, tspan, p; kwargs...)
end

# convenience interfaces:
# Allow any previous timeseries solution
function BVProblem(f::AbstractODEFunction, bc, sol::T, tspan::Tuple, p = NullParameters();
kwargs...) where {T <: AbstractTimeseriesSolution}
BVProblem(f, bc, sol.u, tspan, p)
end
# Allow a function of time for the initial guess
function BVProblem(f::AbstractODEFunction, bc, initialGuess, tspan::AbstractVector,
p = NullParameters(); kwargs...)
u0 = [initialGuess(i) for i in tspan]
BVProblem(f, bc, u0, (tspan[1], tspan[end]), p)
function BVProblem(f::AbstractBVPFunction, u0, tspan, p = NullParameters(); kwargs...)
BVProblem{isinplace(f)}(f.f, f.bc, u0, tspan, p; kwargs...)
end

"""
Expand Down
Loading

0 comments on commit 4c0fcdf

Please sign in to comment.