|
| 1 | +using OrdinaryDiffEqPDIRK |
| 2 | +using OrdinaryDiffEqCore |
| 3 | +using OrdinaryDiffEqNonlinearSolve: nlsolve! |
| 4 | +using SciMLBase |
| 5 | +using Test |
| 6 | + |
| 7 | +# The out-of-place branch used to pass `γ * dt` where `nlsolve!` takes the |
| 8 | +# integrator cache. Nothing complained: the `NLNewton` guard only rejected |
| 9 | +# `nothing`, and `update_W!` happens not to read that argument on the |
| 10 | +# out-of-place path. Both halves are covered here. |
| 11 | +@testset "PDIRK44 out-of-place agrees with in-place" begin |
| 12 | + oop = ODEProblem((u, p, t) -> -u * (1 + 0.1u), 1.0, (0.0, 1.0)) |
| 13 | + iip = ODEProblem((du, u, p, t) -> (du[1] = -u[1] * (1 + 0.1u[1]); nothing), [1.0], (0.0, 1.0)) |
| 14 | + for threading in (false, true) |
| 15 | + a = solve(oop, PDIRK44(; threading); dt = 0.05, adaptive = false) |
| 16 | + b = solve(iip, PDIRK44(; threading); dt = 0.05, adaptive = false) |
| 17 | + @test SciMLBase.successful_retcode(a) |
| 18 | + @test a.u[end] ≈ b.u[end][1] rtol = 1.0e-10 |
| 19 | + end |
| 20 | +end |
| 21 | + |
| 22 | +@testset "nlsolve! rejects a third argument that is not a cache" begin |
| 23 | + prob = ODEProblem((du, u, p, t) -> (du[1] = -u[1]; nothing), [1.0], (0.0, 1.0)) |
| 24 | + integrator = init(prob, PDIRK44(threading = false); dt = 0.1, adaptive = false) |
| 25 | + nlsolver = first(integrator.cache.nlsolver) |
| 26 | + @test_throws ArgumentError nlsolve!(nlsolver, integrator, 0.5, false) |
| 27 | + @test_throws ArgumentError nlsolve!(nlsolver, integrator, nothing, false) |
| 28 | +end |
0 commit comments