@@ -963,7 +963,7 @@ function unassignable_variables(sys, expr)
963963 x -> ! any (isequal (x), assignable_syms), reduce (vcat, vars (expr); init = []))
964964end
965965
966- function compile_user_affect (affect:: MutatingFunctionalAffect , sys, dvs, ps; kwargs... )
966+ function compile_user_affect (affect:: MutatingFunctionalAffect , cb, sys, dvs, ps; kwargs... )
967967 #=
968968 Implementation sketch:
969969 generate observed function (oop), should save to a component array under obs_syms
@@ -1049,6 +1049,13 @@ function compile_user_affect(affect::MutatingFunctionalAffect, sys, dvs, ps; kwa
10491049 collect (mkzero (size (e)) for e in first .(mod_unk_pairs))]))
10501050 upd_params_view = view (upd_component_array, last .(mod_param_pairs))
10511051 upd_unks_view = view (upd_component_array, last .(mod_unk_pairs))
1052+
1053+ if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
1054+ save_idxs = get (ic. callback_to_clocks, cb, Int[])
1055+ else
1056+ save_idxs = Int[]
1057+ end
1058+
10521059 let user_affect = func (affect), ctx = context (affect)
10531060 function (integ)
10541061 # update the to-be-mutated values; this ensures that if you do a no-op then nothing happens
@@ -1074,11 +1081,16 @@ function compile_user_affect(affect::MutatingFunctionalAffect, sys, dvs, ps; kwa
10741081 # write the new values back to the integrator
10751082 upd_params_fun (integ, upd_params_view)
10761083 upd_unk_fun (integ, upd_unks_view)
1084+
1085+
1086+ for idx in save_idxs
1087+ SciMLBase. save_discretes! (integ, idx)
1088+ end
10771089 end
10781090 end
10791091end
10801092
1081- function compile_affect (affect:: FunctionalAffect , cb, sys, dvs, ps; kwargs... )
1093+ function compile_affect (affect:: Union{ FunctionalAffect, MutatingFunctionalAffect} , cb, sys, dvs, ps; kwargs... )
10821094 compile_user_affect (affect, cb, sys, dvs, ps; kwargs... )
10831095end
10841096
0 commit comments