@@ -963,7 +963,7 @@ function unassignable_variables(sys, expr)
963
963
x -> ! any (isequal (x), assignable_syms), reduce (vcat, vars (expr); init = []))
964
964
end
965
965
966
- function compile_user_affect (affect:: MutatingFunctionalAffect , sys, dvs, ps; kwargs... )
966
+ function compile_user_affect (affect:: MutatingFunctionalAffect , cb, sys, dvs, ps; kwargs... )
967
967
#=
968
968
Implementation sketch:
969
969
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
1049
1049
collect (mkzero (size (e)) for e in first .(mod_unk_pairs))]))
1050
1050
upd_params_view = view (upd_component_array, last .(mod_param_pairs))
1051
1051
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
+
1052
1059
let user_affect = func (affect), ctx = context (affect)
1053
1060
function (integ)
1054
1061
# 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
1074
1081
# write the new values back to the integrator
1075
1082
upd_params_fun (integ, upd_params_view)
1076
1083
upd_unk_fun (integ, upd_unks_view)
1084
+
1085
+
1086
+ for idx in save_idxs
1087
+ SciMLBase. save_discretes! (integ, idx)
1088
+ end
1077
1089
end
1078
1090
end
1079
1091
end
1080
1092
1081
- function compile_affect (affect:: FunctionalAffect , cb, sys, dvs, ps; kwargs... )
1093
+ function compile_affect (affect:: Union{ FunctionalAffect, MutatingFunctionalAffect} , cb, sys, dvs, ps; kwargs... )
1082
1094
compile_user_affect (affect, cb, sys, dvs, ps; kwargs... )
1083
1095
end
1084
1096
0 commit comments