@@ -218,10 +218,111 @@ concrete_jac(v::Bool) = v
218218concrete_jac (:: Val{false} ) = false
219219concrete_jac (:: Val{true} ) = true
220220
221+ """
222+ AbstractNonlinearSolveCache
223+
224+ Abstract Type for all NonlinearSolveBase Caches.
225+
226+ ### Interface Functions
227+
228+ - `get_fu(cache)`: get the residual.
229+ - `get_u(cache)`: get the current state.
230+ - `set_fu!(cache, fu)`: set the residual.
231+ - `has_time_limit(cache)`: whether or not the solver has a maximum time limit.
232+ - `not_terminated(cache)`: whether or not the solver has terminated.
233+
234+ - `SciMLBase.set_u!(cache, u)`: set the current state.
235+ - `SciMLBase.reinit!(cache, u0; kwargs...)`: reinitialize the cache with the initial state
236+ `u0` and any additional keyword arguments.
237+ - `SciMLBase.step!(cache; kwargs...)`: See [`SciMLBase.step!`](@ref) for more details.
238+ - `SciMLBase.isinplace(cache)`: whether or not the solver is inplace.
239+
240+ Additionally implements `SymbolicIndexingInterface` interface Functions.
241+
242+ #### Expected Fields in Sub-Types
243+
244+ For the default interface implementations we expect the following fields to be present in
245+ the cache:
246+
247+ - `fu`: the residual.
248+ - `u`: the current state.
249+ - `maxiters`: the maximum number of iterations.
250+ - `nsteps`: the number of steps taken.
251+ - `force_stop`: whether or not the solver has been forced to stop.
252+ - `retcode`: the return code.
253+ - `stats`: `NLStats` object.
254+ - `alg`: the algorithm.
255+ - `maxtime`: the maximum time limit for the solver. (Optional)
256+ - `timer`: the timer for the solver. (Optional)
257+ - `total_time`: the total time taken by the solver. (Optional)
258+ """
221259abstract type AbstractNonlinearSolveCache <: AbstractNonlinearSolveBaseAPI end
222260
223- function get_u end
224- function get_fu end
261+ get_u (cache:: AbstractNonlinearSolveCache ) = cache. u
262+ get_fu (cache:: AbstractNonlinearSolveCache ) = cache. fu
263+ set_fu! (cache:: AbstractNonlinearSolveCache , fu) = (cache. fu = fu)
264+ SciMLBase. set_u! (cache:: AbstractNonlinearSolveCache , u) = (cache. u = u)
265+
266+ function has_time_limit (cache:: AbstractNonlinearSolveCache )
267+ maxtime = Utils. safe_getproperty (cache, Val (:maxtime ))
268+ return maxtime != = missing && maxtime != = nothing
269+ end
270+
271+ function not_terminated (cache:: AbstractNonlinearSolveCache )
272+ return ! cache. force_stop && cache. nsteps < cache. maxiters
273+ end
274+
275+ function SciMLBase. reinit! (cache:: AbstractNonlinearSolveCache ; kwargs... )
276+ return InternalAPI. reinit! (cache; kwargs... )
277+ end
278+ function SciMLBase. reinit! (cache:: AbstractNonlinearSolveCache , u0; kwargs... )
279+ return InternalAPI. reinit! (cache; u0, kwargs... )
280+ end
281+
282+ SciMLBase. isinplace (cache:: AbstractNonlinearSolveCache ) = SciMLBase. isinplace (cache. prob)
283+
284+ # # SII Interface
285+ SII. symbolic_container (cache:: AbstractNonlinearSolveCache ) = cache. prob
286+ SII. parameter_values (cache:: AbstractNonlinearSolveCache ) = SII. parameter_values (cache. prob)
287+ SII. state_values (cache:: AbstractNonlinearSolveCache ) = SII. state_values (cache. prob)
288+
289+ function Base. getproperty (cache:: AbstractNonlinearSolveCache , sym:: Symbol )
290+ if sym === :ps
291+ ! hasfield (typeof (cache), :ps ) && return SII. ParameterIndexingProxy (cache)
292+ return getfield (cache, :ps )
293+ end
294+ return getfield (cache, sym)
295+ end
296+
297+ Base. getindex (cache:: AbstractNonlinearSolveCache , sym) = SII. getu (cache, sym)(cache)
298+ function Base. setindex! (cache:: AbstractNonlinearSolveCache , val, sym)
299+ return SII. setu (cache, sym)(cache, val)
300+ end
301+
302+ # XXX : Implement this
303+ # function Base.show(io::IO, cache::AbstractNonlinearSolveCache)
304+ # __show_cache(io, cache, 0)
305+ # end
306+
307+ # function __show_cache(io::IO, cache::AbstractNonlinearSolveCache, indent = 0)
308+ # println(io, "$(nameof(typeof(cache)))(")
309+ # __show_algorithm(io, cache.alg,
310+ # (" "^(indent + 4)) * "alg = " * string(get_name(cache.alg)), indent + 4)
311+
312+ # ustr = sprint(show, get_u(cache); context = (:compact => true, :limit => true))
313+ # println(io, ",\n" * (" "^(indent + 4)) * "u = $(ustr),")
314+
315+ # residstr = sprint(show, get_fu(cache); context = (:compact => true, :limit => true))
316+ # println(io, (" "^(indent + 4)) * "residual = $(residstr),")
317+
318+ # normstr = sprint(
319+ # show, norm(get_fu(cache), Inf); context = (:compact => true, :limit => true))
320+ # println(io, (" "^(indent + 4)) * "inf-norm(residual) = $(normstr),")
321+
322+ # println(io, " "^(indent + 4) * "nsteps = ", cache.stats.nsteps, ",")
323+ # println(io, " "^(indent + 4) * "retcode = ", cache.retcode)
324+ # print(io, " "^(indent) * ")")
325+ # end
225326
226327"""
227328 AbstractLinearSolverCache
0 commit comments