TerminateSteadyState callback on DiscreteProblem?

Hi all,

I’d like to use TerminateSteadyState from DiffEqCallbacks.jl on a DiscreteProblem, but the default test function is based on derivatives (which my model doesn’t have). I see that one can define their own test function based on the integrator - any tips on how this should be structured in order to correspond to the ‘allDerivPass’ function for continuous systems?

I assume you would define that as checking u_{n+1} - u_{n} being sufficiently small?

Yup - I just need to use the difference in states uprev and u - I didn’t know whether there was a canned function for this, or how to build the callback appropriately.

Looking closer, allDerivPass appears to be able to handle DiscreteProblem, but I get an error that the FunctionMap stepper doesn’t support derivatives, and the callback fails.

Although DiffEqBase.get_du! should be implemented for DiscreteProblem, here’s my placeholder test function that uses u and uprev:

function allDeltaPass(integrator, abstol, reltol, min_t)
    # Early exit
    if min_t !== nothing && integrator.t < min_t
        return false
    end
    testval = integrator.u .- integrator.uprev
    return all(abs.(testval) .<= max.(abstol, reltol .* abs.(integrator.u)))
end;

That looks right. We should add that to the library as the default way for DiscreteProblem. Do you have a good test case?