24
24
# pseudo transient continuation has a fixed cost per iteration, iteration statistics are
25
25
# not interesting here.
26
26
@inline function __siam_fanl_equations_stats_mapping (method, sol)
27
- method === :pseudotransient && return nothing
27
+ ( method === :pseudotransient ) || (method === :anderson ) && return nothing
28
28
return SciMLBase. NLStats (sum (sol. stats. ifun), sum (sol. stats. ijac), 0 , 0 ,
29
29
sum (sol. stats. iarm))
30
30
end
@@ -36,16 +36,14 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
36
36
@assert (termination_condition ===
37
37
nothing )|| (termination_condition isa AbsNormTerminationMode) " SIAMFANLEquationsJL does not support termination conditions!"
38
38
39
- (; method, delta, linsolve) = alg
40
-
41
- iip = SciMLBase. isinplace (prob)
39
+ (; method, delta, linsolve, m, beta) = alg
42
40
43
41
T = eltype (prob. u0)
44
42
atol = NonlinearSolve. DEFAULT_TOLERANCE (abstol, T)
45
43
rtol = NonlinearSolve. DEFAULT_TOLERANCE (reltol, T)
46
44
47
45
if prob. u0 isa Number
48
- f = ( u) -> prob. f (u, prob. p)
46
+ f = method == :anderson ? (du, u) -> (du = prob. f (u, prob. p)) : ((u) -> prob . f (u, prob . p) )
49
47
50
48
if method == :newton
51
49
sol = nsolsc (f, prob. u0; maxit = maxiters, atol, rtol, printerr = ShT)
@@ -54,17 +52,22 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
54
52
printerr = ShT)
55
53
elseif method == :secant
56
54
sol = secant (f, prob. u0; maxit = maxiters, atol, rtol, printerr = ShT)
55
+ elseif method == :anderson
56
+ f, u = NonlinearSolve. __construct_f (prob; alias_u0,
57
+ make_fixed_point = Val (true ), can_handle_arbitrary_dims = Val (true ))
58
+ sol = aasol (f, [prob. u0], m, __zeros_like (u, 1 , 2 * m+ 4 ); maxit = maxiters,
59
+ atol, rtol, beta = beta)
57
60
end
58
61
59
62
retcode = __siam_fanl_equations_retcode_mapping (sol)
60
63
stats = __siam_fanl_equations_stats_mapping (method, sol)
61
- resid = NonlinearSolve. evaluate_f (prob, sol. solution)
64
+ resid = NonlinearSolve. evaluate_f (prob, sol. solution[ 1 ] )
62
65
return SciMLBase. build_solution (prob, alg, sol. solution, resid; retcode,
63
66
stats, original = sol)
64
67
end
65
68
66
69
f!, u = NonlinearSolve. __construct_f (prob; alias_u0,
67
- can_handle_arbitrary_dims = Val (true ))
70
+ can_handle_arbitrary_dims = Val (true ), make_fixed_point = Val ( true ) )
68
71
69
72
# Allocate ahead for function
70
73
N = length (u)
@@ -104,6 +107,10 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
104
107
elseif method == :pseudotransient
105
108
sol = ptcsol (f!, u, FS, FPS; atol, rtol, maxit = maxiters,
106
109
delta0 = delta, printerr = ShT)
110
+ elseif method == :anderson
111
+ println (u[:])
112
+ sol = aasol (f!, u[:], m, zeros (eltype (u), N, 2 * m+ 4 ), atol, rtol,
113
+ maxit = maxiters, beta = beta)
107
114
end
108
115
else
109
116
AJ! (J, u, x) = prob. f. jac (J, x, prob. p)
0 commit comments