Termination Cache API
This API is for solver-package developers that evaluate a nonlinear termination condition outside NonlinearSolve's standard solve loop. Application code should use solve and configured termination modes rather than constructing or inspecting termination caches.
NonlinearSolveBase.termination_condition_result — Function
termination_condition_result(cache, fallback_u, fallback_t, solver_retcode) -> (u, t, retcode)Return the state, time or iteration marker, and return code selected by a nonlinear termination cache.
This developer API is for solver packages that drive an AbstractNonlinearTerminationMode cache outside NonlinearSolve's standard solve loop. It applies the cache's termination policy without exposing cache storage. Safe-best modes return their recorded best state and saved marker when one is available; other modes return fallback_u and fallback_t.
Arguments
cache: A cache returned bySciMLBase.initfor a public nonlinear termination mode.fallback_u: Final state produced by the enclosing solver.fallback_t: Time or iteration marker associated withfallback_u.solver_retcode: Unmodified return code produced by the enclosing solver.
Returns
u: The selected state. A safe-best cache returns a copy of its retained best state when available; otherwise this isfallback_u.t: Marker associated withu. A safe-best cache returns its saved marker when available; otherwise this isfallback_t.retcode: The cache-adjusted solver return code. A standard termination event maps toReturnCode.Success; safe modes preserve a more specific cached result.
Developer Contract
Call this only after the final update of a cache returned by SciMLBase.init(prob, termination_condition, du, u; kwargs...). The fallback values must describe the enclosing solver's actual final result. This is a consumer API, not an extension point: solver packages must not extend it or access the cache's fields directly.
Example
using NonlinearSolveBase, SciMLBase
prob = NonlinearProblem((u, p) -> u, [1.0])
cache = init(prob, AbsNormTerminationMode(NonlinearSolveBase.Linf_NORM), [1.0], [1.0])
termination_condition_result(cache, [0.0], 1.0, ReturnCode.Terminated)