@@ -40,15 +40,12 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
40
40
atol = NonlinearSolve. DEFAULT_TOLERANCE (abstol, T)
41
41
rtol = NonlinearSolve. DEFAULT_TOLERANCE (reltol, T)
42
42
43
- f, u, resid = NonlinearSolve. __construct_extension_f (prob; alias_u0,
44
- can_handle_oop = Val (true ), can_handle_scalar = Val (true ),
45
- make_fixed_point = Val (method == :anderson ))
46
-
47
- if u isa Number
43
+ if prob. u0 isa Number
44
+ f = @closure u -> prob. f (u, prob. p)
48
45
if method == :newton
49
- sol = nsolsc (f, u ; maxit = maxiters, atol, rtol, printerr = ShT)
46
+ sol = nsolsc (f, prob . u0 ; maxit = maxiters, atol, rtol, printerr = ShT)
50
47
elseif method == :pseudotransient
51
- sol = ptcsolsc (f, u ; delta0 = delta, maxit = maxiters, atol, rtol,
48
+ sol = ptcsolsc (f, prob . u0 ; delta0 = delta, maxit = maxiters, atol, rtol,
52
49
printerr = ShT)
53
50
elseif method == :secant
54
51
sol = secant (f, u; maxit = maxiters, atol, rtol, printerr = ShT)
@@ -57,33 +54,30 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
57
54
atol, rtol, beta)
58
55
end
59
56
else
57
+ f, u, resid = NonlinearSolve. __construct_extension_f (prob; alias_u0)
60
58
N = length (u)
61
59
FS = __zeros_like (u, N)
62
60
63
61
# Jacobian Free Newton Krylov
64
62
if linsolve != = nothing
65
63
# Allocate ahead for Krylov basis
66
64
JVS = linsolve == :gmres ? __zeros_like (u, N, 3 ) : __zeros_like (u, N)
67
- # `linsolve` as a Symbol to keep unified interface with other EXTs,
68
- # SIAMFANLEquations directly use String to choose between different linear
69
- # solvers
70
65
linsolve_alg = String (linsolve)
71
-
72
66
if method == :newton
73
- sol = nsoli (f! , u, FS, JVS; lsolver = linsolve_alg, maxit = maxiters, atol,
67
+ sol = nsoli (f, u, FS, JVS; lsolver = linsolve_alg, maxit = maxiters, atol,
74
68
rtol, printerr = ShT)
75
69
elseif method == :pseudotransient
76
- sol = ptcsoli (f! , u, FS, JVS; lsolver = linsolve_alg, maxit = maxiters,
70
+ sol = ptcsoli (f, u, FS, JVS; lsolver = linsolve_alg, maxit = maxiters,
77
71
atol, rtol, printerr = ShT)
78
72
end
79
73
else
80
74
if prob. f. jac === nothing && alg. autodiff === missing
81
75
FPS = __zeros_like (u, N, N)
82
76
if method == :newton
83
- sol = nsol (f! , u, FS, FPS; sham = 1 , atol, rtol, maxit = maxiters,
77
+ sol = nsol (f, u, FS, FPS; sham = 1 , atol, rtol, maxit = maxiters,
84
78
printerr = ShT)
85
79
elseif method == :pseudotransient
86
- sol = ptcsol (f! , u, FS, FPS; atol, rtol, maxit = maxiters,
80
+ sol = ptcsol (f, u, FS, FPS; atol, rtol, maxit = maxiters,
87
81
delta0 = delta, printerr = ShT)
88
82
elseif method == :anderson
89
83
sol = aasol (f!, u, m, zeros (T, N, 2 * m + 4 ), atol, rtol,
@@ -92,14 +86,14 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
92
86
else
93
87
FPS = prob. f. jac_prototype != = nothing ? zero (prob. f. jac_prototype) :
94
88
__zeros_like (u, N, N)
95
- jac! = NonlinearSolve. __construct_extension_jac (prob, alg, u, resid;
89
+ jac = NonlinearSolve. __construct_extension_jac (prob, alg, u, resid;
96
90
alg. autodiff)
97
- AJ! = @closure (J, u, x) -> jac! (J, x)
91
+ AJ! = @closure (J, u, x) -> jac (J, x)
98
92
if method == :newton
99
- sol = nsol (f! , u, FS, FPS, AJ!; sham = 1 , atol, rtol, maxit = maxiters,
93
+ sol = nsol (f, u, FS, FPS, AJ!; sham = 1 , atol, rtol, maxit = maxiters,
100
94
printerr = ShT)
101
95
elseif method == :pseudotransient
102
- sol = ptcsol (f! , u, FS, FPS, AJ!; atol, rtol, maxit = maxiters,
96
+ sol = ptcsol (f, u, FS, FPS, AJ!; atol, rtol, maxit = maxiters,
103
97
delta0 = delta, printerr = ShT)
104
98
end
105
99
end
0 commit comments