2424# pseudo transient continuation has a fixed cost per iteration, iteration statistics are
2525# not interesting here.
2626@inline function __siam_fanl_equations_stats_mapping (method, sol)
27- method === :pseudotransient && return nothing
27+ (( method === :pseudotransient ) || (method === :anderson )) && return nothing
2828 return SciMLBase. NLStats (sum (sol. stats. ifun), sum (sol. stats. ijac), 0 , 0 ,
2929 sum (sol. stats. iarm))
3030end
@@ -36,16 +36,14 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
3636 @assert (termination_condition ===
3737 nothing )|| (termination_condition isa AbsNormTerminationMode) " SIAMFANLEquationsJL does not support termination conditions!"
3838
39- (; method, delta, linsolve) = alg
40-
41- iip = SciMLBase. isinplace (prob)
39+ (; method, delta, linsolve, m, beta) = alg
4240
4341 T = eltype (prob. u0)
4442 atol = NonlinearSolve. DEFAULT_TOLERANCE (abstol, T)
4543 rtol = NonlinearSolve. DEFAULT_TOLERANCE (reltol, T)
4644
4745 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) )
4947
5048 if method == :newton
5149 sol = nsolsc (f, prob. u0; maxit = maxiters, atol, rtol, printerr = ShT)
@@ -54,11 +52,16 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
5452 printerr = ShT)
5553 elseif method == :secant
5654 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)
5760 end
5861
5962 retcode = __siam_fanl_equations_retcode_mapping (sol)
6063 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 ] )
6265 return SciMLBase. build_solution (prob, alg, sol. solution, resid; retcode,
6366 stats, original = sol)
6467 end
@@ -104,6 +107,11 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SIAMFANLEquationsJL, arg
104107 elseif method == :pseudotransient
105108 sol = ptcsol (f!, u, FS, FPS; atol, rtol, maxit = maxiters,
106109 delta0 = delta, printerr = ShT)
110+ elseif method == :anderson
111+ f!, u = NonlinearSolve. __construct_f (prob; alias_u0,
112+ can_handle_arbitrary_dims = Val (true ), make_fixed_point = Val (true ))
113+ sol = aasol (f!, u, m, zeros (T, N, 2 * m+ 4 ), atol = atol, rtol = rtol,
114+ maxit = maxiters, beta = beta)
107115 end
108116 else
109117 AJ! (J, u, x) = prob. f. jac (J, x, prob. p)
0 commit comments