BoundaryValueDiffEq.jl icon indicating copy to clipboard operation
BoundaryValueDiffEq.jl copied to clipboard

Seemingly weird result with very large errors with MIRK5()

Open vyudu opened this issue 11 months ago • 1 comments

I have this problem that MIRK3, MIRK4, and MIRK6 seem to handle fine, but MIRK5 ends up having very large errors on:

using BoundaryValueDiffEq, BenchmarkTools 

function lotkavolterra!(du, u, p, t) 
    du[1] = p[1]*u[1] - p[2]*u[1]*u[2]
    du[2] = -p[4]*u[2] + p[3]*u[1]*u[2]
end

function bc!(du, u, p, t) 
    du[1] = u(0.6)[1] - 3.5
    du[2] = u(0.3)[1] - 7.0 
end

p = [1.5, 1., 1., 3.]
bvp = BVProblem(lotkavolterra!, bc!, [4., 2.], (0., 1.), p)

du = zeros(2)
sol = @btime solve($bvp, MIRK3(), dt = 0.05) # time: 3.134 ms
bc!(du, sol, p, 1.) # [0.00014751435360382814, -0.0001928704283686855]

sol = @btime solve($bvp, MIRK4(), dt = 0.05) # time: 411.375 μs
bc!(du, sol, p, 1.) # [0.00026448435797687964, -0.00031431123142944273]

sol = @btime solve($bvp, MIRK5(), dt = 0.05) # time: 8.272 ms
bc!(du, sol, p, 1.) # [2.0705889974019476, -0.9358530914362078]

sol = @btime solve($bvp, MIRK6(), dt = 0.05) # time: 499.292 μs
bc!(du, sol, p, 1.) # [0.0002639321800703698, -0.000315300179799749]

It also returns a successful retcode in this case. Not sure if this is something wrong or expected weirdness, but thought i'd report in case.

vyudu avatar Jan 17 '25 21:01 vyudu

I think there is something wrong with the solutions passed to boundary conditions evaluations, but it's weird that it differs with different MIRK solvers, I need to investigate which part is going wrong

ErikQQY avatar Jan 18 '25 09:01 ErikQQY