Skip to content

Commit 8f4be5f

Browse files
authored
ForceFreeStates - BUGFIX! - Use a per-column absolute tolerance in the Riccati shooting integration (#413)
2 parents 9be3ac5 + 362662b commit 8f4be5f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/ForceFreeStates/Riccati.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,20 +1405,29 @@ function integrate_fm_with_ua_ic(
14051405
u0 = zeros(ComplexF64, N, N, 2)
14061406
u0[:, :, 1] .= ua[:, 1:N, 1]
14071407
u0[:, :, 2] .= ua[:, 1:N, 2]
1408+
# Per-column absolute tolerance so a batch's largest column cannot set the error floor of its smallest:
1409+
# otherwise the resonant small-solution column inherits an absolute error set by the big solution's magnitude.
1410+
abstol_arr = similar(u0, Float64)
1411+
for j in 1:N
1412+
abstol_arr[:, j, :] .= max(maximum(abs, @view u0[:, j, :]), 1e-30) * rtol
1413+
end
14081414
odet_proxy.spline_hint[] = 1
14091415
odet_proxy.ffit_hint[] = 1
14101416
prob = ODEProblem(sing_der!, u0, tspan, params)
1411-
sol = solve(prob, Vern9(); reltol=rtol, save_everystep=false, save_end=true)
1417+
sol = solve(prob, Vern9(); reltol=rtol, abstol=abstol_arr, save_everystep=false, save_end=true)
14121418
result[1:N, 1:N] .= sol.u[end][:, :, 1]
14131419
result[N+1:2N, 1:N] .= sol.u[end][:, :, 2]
14141420

14151421
# Batch 2: columns N+1:2N of T (small solutions)
14161422
u0[:, :, 1] .= ua[:, N+1:2N, 1]
14171423
u0[:, :, 2] .= ua[:, N+1:2N, 2]
1424+
for j in 1:N
1425+
abstol_arr[:, j, :] .= max(maximum(abs, @view u0[:, j, :]), 1e-30) * rtol
1426+
end
14181427
odet_proxy.spline_hint[] = 1
14191428
odet_proxy.ffit_hint[] = 1
14201429
prob = ODEProblem(sing_der!, u0, tspan, params)
1421-
sol = solve(prob, Vern9(); reltol=rtol, save_everystep=false, save_end=true)
1430+
sol = solve(prob, Vern9(); reltol=rtol, abstol=abstol_arr, save_everystep=false, save_end=true)
14221431
result[1:N, N+1:2N] .= sol.u[end][:, :, 1]
14231432
result[N+1:2N, N+1:2N] .= sol.u[end][:, :, 2]
14241433

0 commit comments

Comments
 (0)