Skip to content

Commit e2de813

Browse files
committed
Cover more tests
Signed-off-by: ErikQQY <2283984853@qq.com>
1 parent c0ece9d commit e2de813

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

ext/NonlinearSolveSIAMFANLEquationsExt.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ using NonlinearSolve, SciMLBase
44
using SIAMFANLEquations
55
import ConcreteStructs: @concrete
66
import UnPack: @unpack
7-
import FiniteDiff, ForwardDiff
87

98
function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, args...; abstol = nothing,
109
reltol = nothing, alias_u0::Bool = false, maxiters = 1000, termination_condition = nothing, kwargs...)
1110
@assert (termination_condition === nothing) || (termination_condition isa AbsNormTerminationMode) "SIAMFANLEquationsJL does not support termination conditions!"
1211

13-
@unpack method, autodiff, show_trace, delta, linsolve = alg
12+
@unpack method, show_trace, delta, linsolve = alg
1413

1514
iip = SciMLBase.isinplace(prob)
1615
T = eltype(prob.u0)
@@ -52,8 +51,6 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
5251
u = NonlinearSolve.__maybe_unaliased(prob.u0, alias_u0)
5352
end
5453

55-
fu = NonlinearSolve.evaluate_f(prob, u)
56-
5754
if iip
5855
f! = function (du, u)
5956
prob.f(du, u, prob.p)

src/extension_algs.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,6 @@ end
331331
### Keyword Arguments
332332
333333
- `method`: the choice of method for solving the nonlinear system.
334-
- `autodiff`: the choice of method for generating the Jacobian. Defaults to `:central` or
335-
central differencing via FiniteDiff.jl. The other choices are `:forward`.
336334
- `show_trace`: whether to show the trace.
337335
- `delta`: initial pseudo time step, default is 1e-3.
338336
- `linsolve` : JFNK linear solvers, choices are `gmres` and `bicgstab`.
@@ -345,15 +343,14 @@ end
345343
"""
346344
@concrete struct SIAMFANLEquationsJL <: AbstractNonlinearAlgorithm
347345
method::Symbol
348-
autodiff::Symbol
349346
show_trace::Bool
350347
delta
351348
linsolve::Union{Symbol, Nothing}
352349
end
353350

354-
function SIAMFANLEquationsJL(; method = :newton, autodiff = :central, show_trace = false, delta = 1e-3, linsolve = nothing)
351+
function SIAMFANLEquationsJL(; method = :newton, show_trace = false, delta = 1e-3, linsolve = nothing)
355352
if Base.get_extension(@__MODULE__, :NonlinearSolveSIAMFANLEquationsExt) === nothing
356353
error("SIAMFANLEquationsJL requires SIAMFANLEquations.jl to be loaded")
357354
end
358-
return SIAMFANLEquationsJL(method, autodiff, show_trace, delta, linsolve)
355+
return SIAMFANLEquationsJL(method, show_trace, delta, linsolve)
359356
end

test/siamfanlequations.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ for alg in [SIAMFANLEquationsJL()]
7070
@test maximum(du) < 1e-6
7171
end
7272

73-
# tolerance tests
73+
# tolerance tests for scalar equation solvers
7474
f_tol(u, p) = u^2 - 2
7575
prob_tol = NonlinearProblem(f_tol, 1.0)
7676
for tol in [1e-1, 1e-3, 1e-6, 1e-10, 1e-11]
77-
sol = solve(prob_tol, SIAMFANLEquationsJL(), abstol = tol)
77+
for method = [:newton, :pseudotransient, :secant]
78+
sol = solve(prob_tol, SIAMFANLEquationsJL(method = method), abstol = tol)
79+
@test abs(sol.u[1] - sqrt(2)) < tol
80+
end
81+
end
82+
83+
# Test the JFNK technique
84+
f_jfnk(u, p) = u^2 - 2
85+
prob_jfnk = NonlinearProblem(f_jfnk, 1.0)
86+
for tol in [1e-1, 1e-3, 1e-6, 1e-10, 1e-11]
87+
sol = solve(prob_jfnk, SIAMFANLEquationsJL(linsolve = :gmres), abstol = tol)
7888
@test abs(sol.u[1] - sqrt(2)) < tol
7989
end
8090

@@ -85,7 +95,7 @@ function f!(fvec, x, p)
8595
end
8696

8797
prob = NonlinearProblem{true}(f!, [0.1; 1.2])
88-
sol = solve(prob, SIAMFANLEquationsJL(autodiff = :central))
98+
sol = solve(prob, SIAMFANLEquationsJL())
8999

90100
du = zeros(2)
91101
f!(du, sol.u, nothing)
@@ -98,7 +108,7 @@ function f!(fvec, x, p)
98108
end
99109

100110
prob = NonlinearProblem{true}(f!, [0.1; 1.2])
101-
sol = solve(prob, SIAMFANLEquationsJL(autodiff = :forward))
111+
sol = solve(prob, SIAMFANLEquationsJL())
102112

103113
du = zeros(2)
104114
f!(du, sol.u, nothing)
@@ -131,7 +141,9 @@ f = NonlinearFunction(f!, jac = j!)
131141
p = A
132142

133143
ProbN = NonlinearProblem(f, init, p)
134-
sol = solve(ProbN, SIAMFANLEquationsJL(), reltol = 1e-8, abstol = 1e-8)
144+
for method = [:newton, :pseudotransient]
145+
sol = solve(ProbN, SIAMFANLEquationsJL(method = method), reltol = 1e-8, abstol = 1e-8)
146+
end
135147

136148
#= doesn't support complex numbers handling
137149
init = ones(Complex{Float64}, 152);

0 commit comments

Comments
 (0)