|
| 1 | +@testsetup module CoreRootfindTesting |
| 2 | + |
| 3 | +include("../../../common/common_core_testing.jl") |
| 4 | + |
| 5 | +end |
| 6 | + |
| 7 | +@testitem "DFSane" setup=[CoreRootfindTesting] tags=[:core] begin |
| 8 | + using BenchmarkTools: @ballocated |
| 9 | + using StaticArrays: @SVector |
| 10 | + |
| 11 | + u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0) |
| 12 | + |
| 13 | + @testset "[OOP] u0: $(typeof(u0))" for u0 in u0s |
| 14 | + sol = solve_oop(quadratic_f, u0; solver = DFSane()) |
| 15 | + @test SciMLBase.successful_retcode(sol) |
| 16 | + @test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) |
| 17 | + |
| 18 | + cache = init(NonlinearProblem{false}(quadratic_f, u0, 2.0), DFSane(), abstol = 1e-9) |
| 19 | + @test (@ballocated solve!($cache)) < 200 |
| 20 | + end |
| 21 | + |
| 22 | + @testset "[IIP] u0: $(typeof(u0))" for u0 in ([1.0, 1.0],) |
| 23 | + sol = solve_iip(quadratic_f!, u0; solver = DFSane()) |
| 24 | + @test SciMLBase.successful_retcode(sol) |
| 25 | + @test all(abs.(sol.u .* sol.u .- 2) .< 1e-9) |
| 26 | + |
| 27 | + cache = init(NonlinearProblem{true}(quadratic_f!, u0, 2.0), DFSane(), abstol = 1e-9) |
| 28 | + @test (@ballocated solve!($cache)) ≤ 64 |
| 29 | + end |
| 30 | +end |
| 31 | + |
| 32 | +@testitem "DFSane Iterator Interface" setup=[CoreRootfindTesting] tags=[:core] begin |
| 33 | + p = range(0.01, 2, length = 200) |
| 34 | + @test nlprob_iterator_interface(quadratic_f, p, false, DFSane()) ≈ sqrt.(p) |
| 35 | + @test nlprob_iterator_interface(quadratic_f!, p, true, DFSane()) ≈ sqrt.(p) |
| 36 | +end |
| 37 | + |
| 38 | +@testitem "DFSane NewtonRaphson Fails" setup=[CoreRootfindTesting] tags=[:core] begin |
| 39 | + u0 = [-10.0, -1.0, 1.0, 2.0, 3.0, 4.0, 10.0] |
| 40 | + p = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] |
| 41 | + sol = solve_oop(newton_fails, u0, p; solver = DFSane()) |
| 42 | + @test SciMLBase.successful_retcode(sol) |
| 43 | + @test all(abs.(newton_fails(sol.u, p)) .< 1e-9) |
| 44 | +end |
| 45 | + |
| 46 | +@testitem "DFSane: Kwargs" setup=[CoreRootfindTesting] tags=[:core] begin |
| 47 | + σ_min = [1e-10, 1e-5, 1e-4] |
| 48 | + σ_max = [1e10, 1e5, 1e4] |
| 49 | + σ_1 = [1.0, 0.5, 2.0] |
| 50 | + M = [10, 1, 100] |
| 51 | + γ = [1e-4, 1e-3, 1e-5] |
| 52 | + τ_min = [0.1, 0.2, 0.3] |
| 53 | + τ_max = [0.5, 0.8, 0.9] |
| 54 | + nexp = [2, 1, 2] |
| 55 | + η_strategy = [ |
| 56 | + (f_1, k, x, F) -> f_1 / k^2, (f_1, k, x, F) -> f_1 / k^3, |
| 57 | + (f_1, k, x, F) -> f_1 / k^4 |
| 58 | + ] |
| 59 | + |
| 60 | + list_of_options = zip(σ_min, σ_max, σ_1, M, γ, τ_min, τ_max, nexp, η_strategy) |
| 61 | + for options in list_of_options |
| 62 | + local probN, sol, alg |
| 63 | + alg = DFSane(; |
| 64 | + sigma_min = options[1], sigma_max = options[2], sigma_1 = options[3], |
| 65 | + M = options[4], gamma = options[5], tau_min = options[6], |
| 66 | + tau_max = options[7], n_exp = options[8], eta_strategy = options[9] |
| 67 | + ) |
| 68 | + |
| 69 | + probN = NonlinearProblem{false}(quadratic_f, [1.0, 1.0], 2.0) |
| 70 | + sol = solve(probN, alg, abstol = 1e-11) |
| 71 | + @test all(abs.(quadratic_f(sol.u, 2.0)) .< 1e-6) |
| 72 | + end |
| 73 | +end |
| 74 | + |
| 75 | +@testitem "DFSane Termination Conditions" setup=[CoreRootfindTesting] tags=[:core] begin |
| 76 | + @testset "TC: $(nameof(typeof(termination_condition)))" for termination_condition in TERMINATION_CONDITIONS |
| 77 | + @testset "u0: $(typeof(u0))" for u0 in ([1.0, 1.0], 1.0) |
| 78 | + probN = NonlinearProblem(quadratic_f, u0, 2.0) |
| 79 | + sol = solve(probN, DFSane(); termination_condition) |
| 80 | + @test all(abs.(quadratic_f(sol.u, 2.0)) .< 1e-10) |
| 81 | + end |
| 82 | + end |
| 83 | +end |
0 commit comments