Skip to content

Commit a065303

Browse files
committed
Reset fsal when necessary for first tstep
1 parent d4e22f1 commit a065303

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

lib/OrdinaryDiffEqCore/src/integrators/integrator_utils.jl

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ function loopheader!(integrator)
88

99
# Accept or reject the step
1010
if integrator.iter > 0
11-
if ((integrator.opts.adaptive && integrator.accept_step) ||
12-
!integrator.opts.adaptive) && !integrator.force_stepfail
13-
integrator.success_iter += 1
14-
apply_step!(integrator)
15-
elseif integrator.opts.adaptive && !integrator.accept_step
11+
if (integrator.opts.adaptive && !integrator.accept_step) || integrator.force_stepfail
1612
if integrator.isout
1713
integrator.dt = integrator.dt * integrator.opts.qmin
1814
elseif !integrator.force_stepfail
1915
step_reject_controller!(integrator, integrator.alg)
2016
end
17+
else
18+
integrator.success_iter += 1
19+
apply_step!(integrator)
2120
end
2221
elseif integrator.u_modified # && integrator.iter == 0
2322
update_uprev!(integrator)
23+
update_fsal!(integrator)
2424
end
2525

2626
integrator.iter += 1
@@ -31,6 +31,43 @@ function loopheader!(integrator)
3131
return nothing
3232
end
3333

34+
35+
function apply_step!(integrator)
36+
update_uprev!(integrator)
37+
38+
#Update dt if adaptive or if fixed and the dt is allowed to change
39+
if integrator.opts.adaptive || integrator.dtchangeable
40+
integrator.dt = integrator.dtpropose
41+
elseif integrator.dt != integrator.dtpropose && !integrator.dtchangeable
42+
error("The current setup does not allow for changing dt.")
43+
end
44+
45+
update_fsal!(integrator)
46+
return nothing
47+
end
48+
49+
function update_fsal!(integrator)
50+
if has_discontinuity(integrator) &&
51+
first_discontinuity(integrator) == integrator.tdir * integrator.t
52+
handle_discontinuities!(integrator)
53+
get_current_isfsal(integrator.alg, integrator.cache) && reset_fsal!(integrator)
54+
elseif all_fsal(integrator.alg, integrator.cache) ||
55+
get_current_isfsal(integrator.alg, integrator.cache)
56+
if integrator.reeval_fsal || integrator.u_modified ||
57+
(isdp8(integrator.alg) && !integrator.opts.calck) ||
58+
(only_diagonal_mass_matrix(integrator.alg) &&
59+
!integrator.opts.adaptive)
60+
reset_fsal!(integrator)
61+
else # Do not reeval_fsal, instead copyto! over
62+
if isinplace(integrator.sol.prob)
63+
recursivecopy!(integrator.fsalfirst, integrator.fsallast)
64+
else
65+
integrator.fsalfirst = integrator.fsallast
66+
end
67+
end
68+
end
69+
end
70+
3471
function last_step_failed(integrator::ODEIntegrator)
3572
integrator.last_stepfail && !integrator.opts.adaptive
3673
end
@@ -386,39 +423,6 @@ function update_uprev!(integrator)
386423
nothing
387424
end
388425

389-
function apply_step!(integrator)
390-
update_uprev!(integrator)
391-
392-
#Update dt if adaptive or if fixed and the dt is allowed to change
393-
if integrator.opts.adaptive || integrator.dtchangeable
394-
integrator.dt = integrator.dtpropose
395-
elseif integrator.dt != integrator.dtpropose && !integrator.dtchangeable
396-
error("The current setup does not allow for changing dt.")
397-
end
398-
399-
# Update fsal if needed
400-
if has_discontinuity(integrator) &&
401-
first_discontinuity(integrator) == integrator.tdir * integrator.t
402-
handle_discontinuities!(integrator)
403-
get_current_isfsal(integrator.alg, integrator.cache) && reset_fsal!(integrator)
404-
elseif all_fsal(integrator.alg, integrator.cache) ||
405-
get_current_isfsal(integrator.alg, integrator.cache)
406-
if integrator.reeval_fsal || integrator.u_modified ||
407-
(isdp8(integrator.alg) && !integrator.opts.calck) ||
408-
(only_diagonal_mass_matrix(integrator.alg) &&
409-
!integrator.opts.adaptive)
410-
reset_fsal!(integrator)
411-
else # Do not reeval_fsal, instead copyto! over
412-
if isinplace(integrator.sol.prob)
413-
recursivecopy!(integrator.fsalfirst, integrator.fsallast)
414-
else
415-
integrator.fsalfirst = integrator.fsallast
416-
end
417-
end
418-
end
419-
return nothing
420-
end
421-
422426
handle_discontinuities!(integrator) = pop_discontinuity!(integrator)
423427

424428
function calc_dt_propose!(integrator, dtnew)

0 commit comments

Comments
 (0)