@@ -7,6 +7,13 @@ function SciMLBase.__solve(
77end
88
99function CommonSolve. solve! (cache:: AbstractNonlinearSolveCache )
10+ if cache. retcode == ReturnCode. InitialFailure
11+ return SciMLBase. build_solution (
12+ cache. prob, cache. alg, get_u (cache), get_fu (cache);
13+ cache. retcode, cache. stats, cache. trace
14+ )
15+ end
16+
1017 while not_terminated (cache)
1118 CommonSolve. step! (cache)
1219 end
4047 sol_syms = [gensym (" sol" ) for i in 1 : N]
4148 u_result_syms = [gensym (" u_result" ) for i in 1 : N]
4249
50+ push! (calls,
51+ quote
52+ if cache. retcode == ReturnCode. InitialFailure
53+ u = $ (SII. state_values)(cache)
54+ return build_solution_less_specialize (
55+ cache. prob, cache. alg, u, $ (Utils. evaluate_f)(cache. prob, u);
56+ retcode = cache. retcode
57+ )
58+ end
59+ end )
60+
4361 for i in 1 : N
4462 push! (calls,
4563 quote
111129
112130@generated function __generated_polysolve (
113131 prob:: AbstractNonlinearProblem , alg:: NonlinearSolvePolyAlgorithm{Val{N}} , args... ;
114- stats = NLStats (0 , 0 , 0 , 0 , 0 ), alias_u0 = false , verbose = true , kwargs...
132+ stats = NLStats (0 , 0 , 0 , 0 , 0 ), alias_u0 = false , verbose = true ,
133+ initializealg = NonlinearSolveDefaultInit (), kwargs...
115134) where {N}
116135 sol_syms = [gensym (" sol" ) for _ in 1 : N]
117136 prob_syms = [gensym (" prob" ) for _ in 1 : N]
123142 immutable (checked using `ArrayInterface.ismutable`)."
124143 alias_u0 = false # If immutable don't care about aliasing
125144 end
145+ end ]
146+
147+ push! (calls,
148+ quote
149+ prob, success = $ (run_initialization!)(prob, initializealg, prob)
150+ if ! success
151+ u = $ (SII. state_values)(prob)
152+ return build_solution_less_specialize (
153+ prob, alg, u, $ (Utils. evaluate_f)(prob, u);
154+ retcode = $ (ReturnCode. InitialFailure))
155+ end
156+ end )
157+
158+ push! (calls, quote
126159 u0 = prob. u0
127160 u0_aliased = alias_u0 ? zero (u0) : u0
128- end ]
161+ end )
129162 for i in 1 : N
130163 cur_sol = sol_syms[i]
131164 push! (calls,
246279 alg
247280 args
248281 kwargs:: Any
282+ initializealg
283+
284+ retcode:: ReturnCode.T
249285end
250286
287+ function get_abstol (cache:: NonlinearSolveNoInitCache )
288+ get (cache. kwargs, :abstol , get_tolerance (nothing , eltype (cache. prob. u0)))
289+ end
290+ function get_reltol (cache:: NonlinearSolveNoInitCache )
291+ get (cache. kwargs, :reltol , get_tolerance (nothing , eltype (cache. prob. u0)))
292+ end
293+
294+ SII. parameter_values (cache:: NonlinearSolveNoInitCache ) = SII. parameter_values (cache. prob)
295+ SII. state_values (cache:: NonlinearSolveNoInitCache ) = SII. state_values (cache. prob)
296+
251297get_u (cache:: NonlinearSolveNoInitCache ) = SII. state_values (cache. prob)
252298
253299function SciMLBase. reinit! (
@@ -264,11 +310,20 @@ end
264310
265311function SciMLBase. __init (
266312 prob:: AbstractNonlinearProblem , alg:: AbstractNonlinearSolveAlgorithm , args... ;
313+ initializealg = NonlinearSolveDefaultInit (),
267314 kwargs...
268315)
269- return NonlinearSolveNoInitCache (prob, alg, args, kwargs)
316+ cache = NonlinearSolveNoInitCache (
317+ prob, alg, args, kwargs, initializealg, ReturnCode. Default)
318+ run_initialization! (cache)
319+ return cache
270320end
271321
272322function CommonSolve. solve! (cache:: NonlinearSolveNoInitCache )
323+ if cache. retcode == ReturnCode. InitialFailure
324+ u = SII. state_values (cache)
325+ return SciMLBase. build_solution (
326+ cache. prob, cache. alg, u, Utils. evaluate_f (cache. prob, u); cache. retcode)
327+ end
273328 return CommonSolve. solve (cache. prob, cache. alg, cache. args... ; cache. kwargs... )
274329end
0 commit comments