Skip to content

Commit 73ba237

Browse files
Merge pull request #2807 from ChrisRackauckas-Claude/update-tests-for-diffeqproblemlibrary-153
Update Van der Pol test implementations for DiffEqProblemLibrary.jl PR #153
2 parents 6a1cd65 + 8daa514 commit 73ba237

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ for i in [5, 9, 13, 17, 21, 25], prob in [prob_ode_linear_big, prob_ode_2Dlinear
4444
@test sim21.𝒪est[:final] i atol=testTol
4545
end
4646

47-
sys = prob_ode_vanderpol.f.sys
47+
# Create Van der Pol stiff problem using the same ordering as ODEProblemLibrary
48+
# New implementation: u[1] = x, u[2] = y, p[1] = μ
49+
# Initial conditions: [x, y] = [sqrt(3), 0] (matching original [sys.x => sqrt(3), sys.y => 0])
50+
function vanderpol_firk(du, u, p, t)
51+
x, y = u[1], u[2]
52+
μ = p[1]
53+
du[1] = y # dx/dt = y
54+
du[2] = μ * ((1 - x^2) * y - x) # dy/dt = μ * ((1 - x^2) * y - x)
55+
end
4856

4957
# test adaptivity
5058
for iip in (true, false)
51-
vanstiff = ODEProblem{iip}(sys, [sys.y => 0, sys.x => sqrt(3), sys.μ => 1e6], (
52-
0.0, 1.0))
59+
vanstiff = ODEProblem{iip}(vanderpol_firk, [sqrt(3), 0.0], (0.0, 1.0), [1e6])
5360
sol = solve(vanstiff, RadauIIA5())
5461
if iip
5562
@test sol.stats.naccept + sol.stats.nreject > sol.stats.njacs # J reuse

test/interface/stiffness_detection_test.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@ using OrdinaryDiffEq, Test, ADTypes
22
import ODEProblemLibrary: prob_ode_vanderpol
33
using ForwardDiff: Dual
44

5-
sys = prob_ode_vanderpol.f.sys
6-
prob1 = ODEProblem(sys, [sys.y => 0, sys.x => 2.0, sys.μ => inv(0.003)], (0.0, 6))
5+
# Create Van der Pol problem with same structure as the new ODEProblemLibrary implementation
6+
# New implementation uses: u[1] = x, u[2] = y, p[1] = μ
7+
# Van der Pol equations: dx/dt = y, dy/dt = μ * ((1 - x^2) * y - x)
8+
# Initial conditions: [x, y] = [2.0, 0] (matching the original [sys.x => 2.0, sys.y => 0])
79
function __van(du, u, p, t)
10+
x, y = u[1], u[2]
811
μ = p[1]
9-
du[1] = μ * ((1 - u[2]^2) * u[1] - u[2])
10-
du[2] = 1 * u[1]
12+
du[1] = y # dx/dt = y
13+
du[2] = μ * ((1 - x^2) * y - x) # dy/dt = μ * ((1 - x^2) * y - x)
1114
end
12-
prob2 = ODEProblem(__van, [0, 2.0], (0.0, 6), inv(0.003))
15+
prob1 = ODEProblem(__van, [2.0, 0.0], (0.0, 6), [inv(0.003)])
16+
prob2 = ODEProblem(__van, [2.0, 0.0], (0.0, 6), [inv(0.003)])
1317
# out-of-place test
1418
function _van(u, p, t)
19+
x, y = u[1], u[2]
1520
μ = p[1]
16-
[μ * ((1 - u[2]^2) * u[1] - u[2]),
17-
1 * u[1]]
21+
[y, # dx/dt = y
22+
μ * ((1 - x^2) * y - x)] # dy/dt = μ * ((1 - x^2) * y - x)
1823
end
19-
prob3 = ODEProblem(_van, [0, 2.0], (0.0, 6), inv(0.003))
24+
prob3 = ODEProblem(_van, [2.0, 0.0], (0.0, 6), [inv(0.003)])
2025
probArr = [prob1, prob2, prob3]
2126

2227
for prob in [prob2, prob3], u0 in [prob.u0, Dual.(prob.u0, prob.u0)]

0 commit comments

Comments
 (0)