BoundaryValueDiffEqShooting
Single shooting method and multiple shooting method. To only use the Shooting methods form BoundaryValueDiffEq.jl, you need to install them use the Julia package manager:
using Pkg
Pkg.add("BoundaryValueDiffEqShooting")Shooting algorithms operate on problem definitions and solver functions owned by SciMLBase, and require an ODE algorithm from its owning solver package:
using BoundaryValueDiffEqShooting: MultipleShooting, Shooting
using OrdinaryDiffEqTsit5: Tsit5
using SciMLBase: BVProblem, ReturnCode, solve
function f!(du, u, p, t)
du[1] = u[2]
du[2] = 0
end
function bc!(residual, u, p, t)
residual[1] = u(0.0)[1] - 1
residual[2] = u(1.0)[1]
end
prob = BVProblem(f!, bc!, [1.0, -1.0], (0.0, 1.0); nlls = Val(false))
sol = solve(prob, Shooting(Tsit5()); abstol = 1e-8)
@assert sol.retcode == ReturnCode.Success
@assert isapprox(sol(0.0)[1], 1.0; atol = 1e-6)
@assert isapprox(sol(1.0)[1], 0.0; atol = 1e-6)
# outputFull List of Methods
Shooting: Single shooting methods, reduces BVP to an initial value problem and solves the IVP.MultipleShooting: Reduces BVP to an initial value problem and solves the IVP. Significantly more stable than Single Shooting.
Detailed Solvers Explanation
BoundaryValueDiffEqShooting.Shooting — Type
Shooting(ode_alg; kwargs...)
Shooting(ode_alg, nlsolve; kwargs...)
Shooting(; ode_alg = nothing, nlsolve = nothing, optimize = nothing, jac_alg = nothing) -> ShootingConfigures the single-shooting algorithm for a boundary value problem. Single shooting integrates one initial value problem and solves for the initial condition that satisfies the boundary conditions.
Arguments
ode_alg: algorithm used to solve the internalSciMLBase.ODEProblem. Pass this as the first positional argument or keyword argument.nothingselects a loaded polyalgorithm; otherwise an ODE algorithm must be supplied.nlsolve: nonlinear-solver algorithm for the shooting residual. Its autodiff setting is superseded byjac_algwhen a Jacobian algorithm is materialized.
Keywords
ode_alg = nothing: ODE algorithm, as described above.nlsolve = nothing: nonlinear-solver algorithm, as described above.optimize = nothing: optimization-solver algorithm used when the selected BVP solve path formulates the residual as an optimization problem.jac_alg = nothing:BVPJacobianAlgorithmconfiguration. When omitted, the constructor derives it fromnlsolveand the problem during solve initialization. For single shooting, only itsdiffmodesetting is used; the default isAutoForwardDiffwhen applicable and otherwiseAutoFiniteDiff.
Fields
ode_alg: configured ODE algorithm ornothing.nlsolve: configured nonlinear-solver algorithm ornothing.optimize: configured optimization-solver algorithm ornothing.jac_alg::BVPJacobianAlgorithm: materialized Jacobian-algorithm configuration.
Returns
Shooting: an algorithm object accepted bySciMLBase.solvefor a boundary value problem.
Examples
using BoundaryValueDiffEqShooting: Shooting
using OrdinaryDiffEqTsit5: Tsit5
alg = Shooting(Tsit5())
@assert alg isa Shooting
# outputBoundaryValueDiffEqShooting.MultipleShooting — Type
MultipleShooting(; nshoots::Int, ode_alg = nothing, nlsolve = nothing,
optimize = nothing, grid_coarsening = true, jac_alg = nothing) -> MultipleShooting
MultipleShooting(nshoots::Int; kwargs...)
MultipleShooting(nshoots::Int, ode_alg; kwargs...)
MultipleShooting(nshoots::Int, ode_alg, nlsolve; kwargs...)Configures the multiple-shooting algorithm for a boundary value problem. Multiple shooting integrates an IVP on nshoots subintervals and solves for their matching initial conditions; it is generally more stable than Shooting.
Arguments
nshoots::Int: number of shooting subintervals.ode_alg: algorithm used to solve each internalSciMLBase.ODEProblem. Pass this as the second positional argument or keyword argument.nothingselects a loaded polyalgorithm; otherwise an ODE algorithm must be supplied.nlsolve: nonlinear-solver algorithm for the multiple-shooting residual.
Keywords
ode_alg = nothing: ODE algorithm, as described above.nlsolve = nothing: nonlinear-solver algorithm, as described above.optimize = nothing: optimization-solver algorithm used when the selected BVP solve path formulates the residual as an optimization problem.jac_alg = nothing:BVPJacobianAlgorithmconfiguration. When omitted, the constructor derives it fromnlsolveand the problem during solve initialization.- For
TwoPointBVProblem, onlydiffmodeis used (defaults toAutoSparse(AutoForwardDiff())if possible elseAutoSparse(AutoFiniteDiff())). - For
BVProblem,bc_diffmodeandnonbc_diffmodeare used. Fornonbc_diffmodewe default toAutoSparse(AutoForwardDiff())if possible elseAutoSparse(AutoFiniteDiff()). Forbc_diffmode, we default toAutoForwardDiffif possible elseAutoFiniteDiff.
- For
grid_coarsening = true: coarsens the multiple-shooting grid while generating a stable IVP solution. Supported values are:true: Halve the grid size, till we reach a grid size of 1.false: Do not coarsen the grid. Solve a Multiple Shooting Problem and finally solve a Single Shooting Problem.AbstractVector{<:Int}orNtuple{N, <:Integer}: Use the provided grid coarsening. For example, ifnshoots = 10andgrid_coarsening = [5, 2], then the grid will be coarsened to[5, 2]. Note that1should not be present in the grid coarsening.Function: Takes the current number of shooting points and returns the next number of shooting points. For example, ifnshoots = 10andgrid_coarsening = n -> n ÷ 2, then the grid will be coarsened to[5, 2].
Fields
ode_alg: configured ODE algorithm ornothing.nlsolve: configured nonlinear-solver algorithm ornothing.optimize: configured optimization-solver algorithm ornothing.jac_alg::BVPJacobianAlgorithm: materialized Jacobian-algorithm configuration.nshoots::Int: configured number of shooting subintervals.grid_coarsening: configured grid-coarsening strategy.
Returns
MultipleShooting: an algorithm object accepted bySciMLBase.solvefor a boundary value problem.
Examples
using BoundaryValueDiffEqShooting: MultipleShooting
using OrdinaryDiffEqTsit5: Tsit5
alg = MultipleShooting(8, Tsit5(); grid_coarsening = true)
@assert alg isa MultipleShooting
# output