stop_engine_if_stalling function

an utility function to easily generate a stop function that stops when the convergence is stalling