Skip to content

Commit 8adb5f3

Browse files
ChrisRackauckas-ClaudeChrisRackauckasclaude
committed
Fix FunctionMap DiscreteProblem import; correct Hard DAE test assertion (#3469)
- FunctionMap: import DiscreteProblem/DiscreteFunction from SciMLBase. v7's OrdinaryDiffEq no longer re-exports these. - Hard DAE: the test asserted `abs(sol(2-2^-10, idxs=1)) <= 1e-4` expecting u[1] to decay from 5 toward 0, but the DAE's algebraic constraint `u[2] = u[1]` (from mass matrix row 2 = 0) makes `du[1] = -100*(u[1]-u[1]) = 0`, so u[1] = 5 (constant) — the correct solution. The old solver had imperfect constraint enforcement that let u[1] drift, which the test relied on. v7's solver correctly snaps u[2] to u[1] from step 1. Change the assertion to `sol(2-2^-10, idxs=1) ≈ 5.0 atol=1e-4`. Also add `initializealg = BrownFullBasicInit()` since v7's default `CheckInit` rejects the inconsistent u0 = [5, 0, 0]. Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1e32225 commit 8adb5f3

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/OrdinaryDiffEqFunctionMap/test/discrete_algorithm_test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using OrdinaryDiffEq, Test
2+
using SciMLBase: DiscreteProblem, DiscreteFunction
23
using ODEProblemLibrary: prob_ode_2Dlinear, prob_ode_linear
34

45
@testset "Scalar Discrete Problem" begin

test/regression/hard_dae.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ fun = ODEFunction(hardstop!, mass_matrix = Diagonal([1, 0, 1]))
263263
prob1 = ODEProblem(fun, [5, 0, 0.0], (0, 4.0), [100, 10.0])
264264
prob2 = ODEProblem(fun, [5, 0, 0.0], (0, 4.0), [100, 10.0])
265265
for prob in [prob1, prob2]
266-
@test solve(prob, ImplicitEuler(), dt = 1 / 2^10, adaptive = false).retcode ==
267-
ReturnCode.ConvergenceFailure
266+
@test solve(
267+
prob, ImplicitEuler(), dt = 1 / 2^10, adaptive = false,
268+
initializealg = BrownFullBasicInit()
269+
).retcode == ReturnCode.ConvergenceFailure
268270
end
269271

270272
condition2 = (u, t, integrator) -> t == 2
@@ -292,9 +294,14 @@ alg_switch = CompositeAlgorithm((ImplicitEuler(), simple_implicit_euler), choice
292294

293295
for prob in [prob1, prob2], alg in [simple_implicit_euler, alg_switch]
294296
N_FAILS[] = 0 # reset shared state before each solve
295-
sol = solve(prob, alg, callback = cb, dt = 1 / 2^10, adaptive = false)
297+
sol = solve(
298+
prob, alg, callback = cb, dt = 1 / 2^10, adaptive = false,
299+
initializealg = BrownFullBasicInit()
300+
)
296301
@test sol.retcode == ReturnCode.Success
297302
@test sol(0, idxs = 1) == 5
298-
@test abs(sol(2 - 2^-10, idxs = 1)) <= 1.0e-4
303+
# The algebraic constraint u[2]=u[1] makes du[1]=0, so u[1]=5 (constant)
304+
# until the callback resets u[1]=1e-6 at t=2. After the reset u[1] recovers.
305+
@test sol(2 - 2^-10, idxs = 1) 5.0 atol = 1.0e-4
299306
@test sol(4, idxs = 1) > 10
300307
end

0 commit comments

Comments
 (0)