Skip to content

Commit 2073b24

Browse files
allow one fail for new Jacobian before error with fixed Newton
1 parent 6793c20 commit 2073b24

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/integrators/integrator_utils.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function loopheader!(integrator)
66

77
# Accept or reject the step
88
if integrator.iter > 0
9-
if (integrator.opts.adaptive && integrator.accept_step) || !integrator.opts.adaptive
9+
if ((integrator.opts.adaptive && integrator.accept_step) || !integrator.opts.adaptive) && !integrator.force_stepfail
1010
integrator.success_iter += 1
1111
apply_step!(integrator)
1212
elseif integrator.opts.adaptive && !integrator.accept_step
@@ -245,9 +245,13 @@ end
245245
function loopfooter!(integrator)
246246
ttmp = integrator.t + integrator.dt
247247
if integrator.force_stepfail
248+
if integrator.opts.adaptive
249+
integrator.dt = integrator.dt/integrator.opts.failfactor
250+
elseif integrator.last_stepfail
251+
error("Newton steps could not converge and algorithm is not adaptive. Use a lower dt.")
252+
end
248253
integrator.last_stepfail = true
249254
integrator.accept_step = false
250-
integrator.dt = integrator.dt/integrator.opts.failfactor
251255
elseif integrator.opts.adaptive
252256
q = stepsize_controller!(integrator,integrator.alg)
253257
integrator.isout = integrator.opts.isoutofdomain(ttmp,integrator.u)
@@ -273,6 +277,7 @@ function loopfooter!(integrator)
273277
else
274278
integrator.t = ttmp
275279
end
280+
integrator.last_stepfail = false
276281
integrator.accept_step = true
277282
integrator.dtpropose = integrator.dt
278283
handle_callbacks!(integrator)

0 commit comments

Comments
 (0)