SciML / BoundaryValueDiffEq.jl

Boundary value problem (BVP) solvers for scientific machine learning (SciML)
Other
41 stars 31 forks source link

Solution interpolation in BC with MIRK solver not working? #145

Closed cpf-work closed 7 months ago

cpf-work commented 7 months ago

I follow the simple pendulum example 3

using BoundaryValueDiffEq
using Plots
const g = 9.81
L = 1.0
tspan = (0.0, pi / 2)
function simplependulum!(du, u, p, t)
    θ = u[1]
    dθ = u[2]
    du[1] = dθ
    du[2] = -(g / L) * sin(θ)
end

using OrdinaryDiffEq
u₀_2 = [-1.6, -1.7] # the initial guess
function bc3!(residual, sol, p, t)
    residual[1] = sol(pi / 4)[1] + pi / 2 # use the interpolation here, since indexing will be wrong for adaptive methods
    residual[2] = sol(pi / 2)[1] - pi / 2
end

bvp3 = BVProblem(simplependulum!, bc3!, u₀_2, tspan)
sol3 = solve(bvp3, Shooting(Vern7()))

which works as expected.

However, when I try to solve with MIRK4(), the solution interpolation in the BC does not seem to work. Is this expected?

sol3 = solve(bvp3, MIRK4(), dt=0.05)

MethodError: objects of type Vector{Vector{Float64}} are not callable
Use square brackets [] for indexing an Array.

Issue #107 looks to me as if it should be working?

Pkg.status()

  [764a87c0] BoundaryValueDiffEq v5.4.0
  [1dea7af3] OrdinaryDiffEq v6.59.2
  [91a5bcdd] Plots v1.39.0
  [aa65fe97] SnoopCompile v2.10.8
avik-pal commented 7 months ago

Yes that is currently expected. https://github.com/SciML/BoundaryValueDiffEq.jl/pull/143 is supposed to fix it

cpf-work commented 7 months ago

I see. Thanks for the feedback.