Skip to content

Commit

Permalink
Merge pull request #666 from ErikQQY/qqy/secondorderbvp
Browse files Browse the repository at this point in the history
Add SecondOrderBVProblem
  • Loading branch information
ChrisRackauckas authored Apr 15, 2024
2 parents 7fbd1cf + 139522d commit 9e49323
Show file tree
Hide file tree
Showing 5 changed files with 547 additions and 4 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.32.0"
version = "2.32.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
5 changes: 3 additions & 2 deletions src/SciMLBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ function specialization(::Union{ODEFunction{iip, specialize},
NonlinearFunction{iip, specialize},
OptimizationFunction{iip, specialize},
BVPFunction{iip, specialize},
DynamicalBVPFunction{iip, specialize},
IntegralFunction{iip, specialize},
BatchIntegralFunction{iip, specialize}}) where {iip,
specialize}
Expand Down Expand Up @@ -796,14 +797,14 @@ export SDDEProblem
export PDEProblem
export IncrementingODEProblem

export BVProblem, TwoPointBVProblem
export BVProblem, TwoPointBVProblem, SecondOrderBVProblem

export remake

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

export OptimizationFunction

Expand Down
111 changes: 111 additions & 0 deletions src/problems/bvp_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,114 @@ function TwoPointBVProblem(f::AbstractODEFunction, bc, initialGuess, tspan::Abst
u0 = [initialGuess(i) for i in tspan]
return TwoPointBVProblem(f, bc, u0, (tspan[1], tspan[end]), p; kwargs...)
end

"""
$(TYPEDEF)
"""
struct StandardSecondOrderBVProblem end

@doc doc"""
Defines a second order BVP problem.
Documentation Page: [https://docs.sciml.ai/DiffEqDocs/stable/types/bvp_types/](https://docs.sciml.ai/DiffEqDocs/stable/types/bvp_types/)
## Mathematical Specification of a second order BVP Problem
To define a second order BVP Problem, you simply need to give the function ``f`` and the initial
condition ``u_0`` which define an ODE:
```math
\frac{ddu}{dt} = f(du,u,p,t)
```
along with an implicit function `bc` which defines the residual equation, where
```math
bc(du,u,p,t) = 0
```
is the manifold on which the solution must live.
## Problem Type
### Constructors
```julia
SecondOrderBVProblem{isinplace}(f, bc, u0, tspan, p=NullParameters(); kwargs...)
```
or if we have an initial guess function `initialGuess(p, t)` for the given BVP,
we can pass the initial guess to the problem constructors:
```julia
SecondOrderBVProblem{isinplace}(f, bc, initialGuess, tspan, p=NullParameters(); kwargs...)
```
For any BVP problem type, `bc` must be inplace if `f` is inplace. Otherwise it must be
out-of-place.
If the bvp is a StandardSecondOrderBVProblem (also known as a Multi-Point BV Problem) it must define
either of the following functions
```julia
bc!(residual, du, u, p, t)
residual = bc(du, u, p, t)
```
where `residual` computed from the current `u`. `u` is an array of solution values
where `u[i]` is at time `t[i]`, while `p` are the parameters. For a `TwoPointBVProblem`,
`t = tspan`. For the more general `BVProblem`, `u` can be all of the internal
time points, and for shooting type methods `u=sol` the ODE solution.
Note that all features of the `ODESolution` are present in this form.
In both cases, the size of the residual matches the size of the initial condition.
Parameters are optional, and if not given, then a `NullParameters()` singleton
will be used which will throw nice errors if you try to index non-existent
parameters. Any extra keyword arguments are passed on to the solvers. For example,
if you set a `callback` in the problem, then that `callback` will be added in
every solve call.
### Fields
* `f`: The function for the ODE.
* `bc`: The boundary condition function.
* `u0`: The initial condition. Either the initial condition for the ODE as an
initial value problem, or a `Vector` of values for ``u(t_i)`` for collocation
methods.
* `tspan`: The timespan for the problem.
* `p`: The parameters for the problem. Defaults to `NullParameters`
* `kwargs`: The keyword arguments passed onto the solves.
"""
struct SecondOrderBVProblem{uType, tType, isinplace, nlls, P, F, PT, K} <:
AbstractBVProblem{uType, tType, isinplace, nlls}
f::F
u0::uType
tspan::tType
p::P
problem_type::PT
kwargs::K

@add_kwonly function SecondOrderBVProblem{iip}(f::DynamicalBVPFunction{iip, TP}, u0, tspan,
p = NullParameters(); problem_type = nothing, nlls = nothing,
kwargs...) where {iip, TP}
_u0 = prepare_initial_state(u0)
_tspan = promote_tspan(tspan)
warn_paramtype(p)

return new{typeof(_u0), typeof(_tspan), iip, typeof(nlls), typeof(p), typeof(f),
typeof(problem_type), typeof(kwargs)}(f, _u0, _tspan, p, problem_type, kwargs)
end

function SecondOrderBVProblem{iip}(f, bc, u0, tspan, p = NullParameters(); kwargs...) where {iip}
SecondOrderBVProblem(DynamicalBVPFunction{iip}(f, bc), u0, tspan, p; kwargs...)
end
end

function SecondOrderBVProblem(f, bc, u0, tspan, p = NullParameters(); kwargs...)
iip = isinplace(f, 5)
return SecondOrderBVProblem{iip}(DynamicalBVPFunction{iip}(f, bc), u0, tspan, p; kwargs...)
end

function SecondOrderBVProblem(f::DynamicalBVPFunction, u0, tspan, p = NullParameters(); kwargs...)
return SecondOrderBVProblem{isinplace(f)}(f, u0, tspan, p; kwargs...)
end
Loading

0 comments on commit 9e49323

Please sign in to comment.