Skip to content

Commit b27fede

Browse files
Merge pull request #485 from ChrisRackauckas-Claude/fix-484-vectorofarray-resize
Fix MIRK/FIRK adaptive mesh refinement under RAT v4 (closes #484)
2 parents 6e37525 + 9355a23 commit b27fede

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

lib/BoundaryValueDiffEqMIRK/test/mirk_basic_tests.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,39 @@ end
712712
sol2 = solve(bvp2, MIRK4(), dt = 0.1, adaptive = false, nlsolve_kwargs = (; maxiters = 0))
713713
@test sol2.u == u_guess
714714
end
715+
716+
# https://github.com/SciML/BoundaryValueDiffEq.jl/issues/484
717+
# Adaptive mesh refinement on a sufficiently nonlinear BVP must not throw
718+
# UndefRefError. The torus geodesic system is smooth and nonlinear enough
719+
# that the solver decides to refine the mesh.
720+
@testitem "Adaptive mesh refinement (issue 484)" begin
721+
using BoundaryValueDiffEqMIRK
722+
723+
R = 3.0
724+
r = 2.0
725+
726+
function f!(du, u, p, t)
727+
sinθ, cosθ = sincos(u[1])
728+
R_θ = R + r * cosθ
729+
du[1] = u[3]
730+
du[2] = u[4]
731+
du[3] = -u[4]^2 * R_θ * sinθ / r
732+
du[4] = 2 * r * sinθ / R_θ * u[3] * u[4]
733+
end
734+
735+
a1 = [0.5, -1.2]
736+
a2 = [-0.5, 0.3]
737+
738+
function bc!(residual, u, p, t)
739+
ua = u(0.0)
740+
ub = u(1.0)
741+
residual[1:2] = ua[1:2] - a1
742+
residual[3:4] = ub[1:2] - a2
743+
end
744+
745+
prob = BVProblem(f!, bc!, vcat(a1, zero(a1)), (0.0, 1.0))
746+
sol = solve(prob, MIRK4(); dt = 0.05)
747+
@test SciMLBase.successful_retcode(sol)
748+
@test sol.u[1][1:2] a1 atol = 1.0e-8
749+
@test sol.u[end][1:2] a2 atol = 1.0e-8
750+
end

lib/BoundaryValueDiffEqMIRKN/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BoundaryValueDiffEqMIRKN"
22
uuid = "9255f1d6-53bf-473e-b6bd-23f1ff009da4"
33
authors = ["Qingyu Qu <erikqqy123@gmail.com>"]
4-
version = "1.15.0"
4+
version = "1.15.1"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

lib/BoundaryValueDiffEqMIRKN/src/mirkn.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function SciMLBase.solve!(cache::MIRKNCache{iip, T}) where {iip, T}
137137
end
138138

139139
function __perform_mirkn_iteration(cache::MIRKNCache)
140-
nlprob = __construct_nlproblem(cache, vec(cache.y₀), copy(cache.y₀))
140+
nlprob = __construct_nlproblem(cache, copy(vec(cache.y₀)), copy(cache.y₀))
141141
solve_alg = __concrete_solve_algorithm(nlprob, cache.alg.nlsolve, cache.alg.optimize)
142142
kwargs = __concrete_kwargs(
143143
cache.alg.nlsolve, cache.alg.optimize, cache.nlsolve_kwargs, cache.optimize_kwargs,

0 commit comments

Comments
 (0)