Skip to content

Commit f494526

Browse files
committed
save du and k for DAEs when dense==true
1 parent 18fc6d1 commit f494526

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/integrators/integrator_utils.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ function _savevalues!(integrator, force_save, reduce_size)::Tuple{Bool, Bool}
102102
[k[integrator.opts.save_idxs] for k in integrator.k],
103103
false)
104104
end
105+
if integrator.alg isa DAEAlgorithm
106+
if integrator.opts.save_idxs === nothing
107+
copyat_or_push!(integrator.sol.du, integrator.saveiter, integrator.du)
108+
else
109+
copyat_or_push!(integrator.sol.du, integrator.saveiter,
110+
integrator.du[integrator.opts.save_idxs], false)
111+
end
112+
end
105113
end
106114
end
107115
if integrator.alg isa OrdinaryDiffEqCompositeAlgorithm
@@ -134,6 +142,14 @@ function _savevalues!(integrator, force_save, reduce_size)::Tuple{Bool, Bool}
134142
[k[integrator.opts.save_idxs] for k in integrator.k],
135143
false)
136144
end
145+
if integrator.alg isa DAEAlgorithm
146+
if integrator.opts.save_idxs === nothing
147+
copyat_or_push!(integrator.sol.du, integrator.saveiter, integrator.du)
148+
else
149+
copyat_or_push!(integrator.sol.du, integrator.saveiter,
150+
integrator.du[integrator.opts.save_idxs], false)
151+
end
152+
end
137153
end
138154
end
139155
if integrator.alg isa OrdinaryDiffEqCompositeAlgorithm
@@ -346,6 +362,7 @@ function handle_callbacks!(integrator)
346362
discrete_modified, saved_in_cb = DiffEqBase.apply_discrete_callback!(integrator,
347363
discrete_callbacks...)
348364
end
365+
349366
if !saved_in_cb
350367
savevalues!(integrator)
351368
end
@@ -482,12 +499,10 @@ function handle_tstop!(integrator)
482499
end
483500

484501
function reset_fsal!(integrator)
485-
# Under these conditions, these algorithms are not FSAL anymore
502+
# call this when the conditions for FSAL are no longer true (e.g. u_modified)
486503
integrator.stats.nf += 1
487504

488-
if integrator.sol.prob isa DAEProblem
489-
DiffEqBase.initialize_dae!(integrator)
490-
else
505+
if integrator.sol.prob isa ODEProblem
491506
if integrator.cache isa OrdinaryDiffEqMutableCache ||
492507
(integrator.cache isa CompositeCache &&
493508
integrator.cache.caches[1] isa OrdinaryDiffEqMutableCache)
@@ -496,7 +511,7 @@ function reset_fsal!(integrator)
496511
integrator.fsalfirst = integrator.f(integrator.u, integrator.p, integrator.t)
497512
end
498513
end
499-
# Do not set false here so it can be checked in the algorithm
514+
# Do not set reeval_fsal false here so it can be checked in the algorithm
500515
# integrator.reeval_fsal = false
501516
end
502517

src/solve.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function DiffEqBase.__init(prob::Union{DiffEqBase.AbstractODEProblem,
2525
save_end = nothing,
2626
callback = nothing,
2727
dense = save_everystep &&
28-
!(alg isa Union{DAEAlgorithm, FunctionMap}) &&
28+
!(alg isa FunctionMap) &&
2929
isempty(saveat),
3030
calck = (callback !== nothing && callback !== CallbackSet()) ||
3131
(dense) || !isempty(saveat), # and no dense output
@@ -413,10 +413,17 @@ function DiffEqBase.__init(prob::Union{DiffEqBase.AbstractODEProblem,
413413
differential_vars = prob isa DAEProblem ? prob.differential_vars : get_differential_vars(f, u)
414414

415415
id = InterpolationData(f, timeseries, ts, ks, alg_choice, dense, cache, differential_vars, false)
416-
sol = DiffEqBase.build_solution(prob, _alg, ts, timeseries,
417-
dense = dense, k = ks, interp = id,
418-
alg_choice = alg_choice,
419-
calculate_error = false, stats = stats)
416+
if _alg isa DAEAlgorithm
417+
sol = DiffEqBase.build_solution(prob, _alg, ts, timeseries, Vector{typeof(du)}(undef,0),
418+
dense = dense, k = ks, interp = id,
419+
alg_choice = alg_choice,
420+
calculate_error = false, stats = stats)
421+
else
422+
sol = DiffEqBase.build_solution(prob, _alg, ts, timeseries,
423+
dense = dense, k = ks, interp = id,
424+
alg_choice = alg_choice,
425+
calculate_error = false, stats = stats)
426+
end
420427

421428
if recompile_flag == true
422429
FType = typeof(f)

0 commit comments

Comments
 (0)