From ab8a5e40a9a23857a5751dfc3e5a7c21f1d6e192 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Thu, 25 Apr 2024 17:41:02 -0400 Subject: [PATCH] Add tests --- test/misc/linsolve_switching_tests.jl | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/misc/linsolve_switching_tests.jl diff --git a/test/misc/linsolve_switching_tests.jl b/test/misc/linsolve_switching_tests.jl new file mode 100644 index 000000000..d9724f89b --- /dev/null +++ b/test/misc/linsolve_switching_tests.jl @@ -0,0 +1,29 @@ +@testitem "Singular Systems -- Auto Linear Solve Switching" begin + using LinearSolve, NonlinearSolve + + function f!(du, u, p) + du[1] = 2u[1] - 2 + du[2] = (u[1] - 4u[2])^2 + 0.1 + end + + u0 = [0.0, 0.0] # Singular Jacobian at u0 + + prob = NonlinearProblem(f!, u0) + + sol = solve(prob) # This doesn't have a root so let's just test the switching + @test sol.u≈[1.0, 0.25] atol=1e-3 rtol=1e-3 + + function nlls!(du, u, p) + du[1] = 2u[1] - 2 + du[2] = (u[1] - 4u[2])^2 + 0.1 + du[3] = 0 + end + + u0 = [0.0, 0.0] + + prob = NonlinearProblem( + NonlinearFunction(nlls!, resid_prototype = zeros(3)), u0) + + solve(prob) + @test sol.u≈[1.0, 0.25] atol=1e-3 rtol=1e-3 +end