@@ -781,21 +781,24 @@ function generate_single_rootfinding_callback(
781
781
end
782
782
end
783
783
784
+ user_initfun = isnothing (affect_function. initialize) ? SciMLBase. INITIALIZE_DEFAULT : (c, u, t, i) -> affect_function. initialize (i)
784
785
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing &&
785
786
(save_idxs = get (ic. callback_to_clocks, cb, nothing )) != = nothing
786
787
initfn = let save_idxs = save_idxs
787
788
function (cb, u, t, integrator)
789
+ user_initfun (cb, u, t, integrator)
788
790
for idx in save_idxs
789
791
SciMLBase. save_discretes! (integrator, idx)
790
792
end
791
793
end
792
794
end
793
795
else
794
- initfn = SciMLBase . INITIALIZE_DEFAULT
796
+ initfn = user_initfun
795
797
end
798
+
796
799
return ContinuousCallback (
797
800
cond, affect_function. affect, affect_function. affect_neg, rootfind = cb. rootfind,
798
- initialize = isnothing (affect_function . initialize) ? SciMLBase . INITIALIZE_DEFAULT : (c, u, t, i) -> affect_function . initialize (i) ,
801
+ initialize = initfn ,
799
802
finalize = isnothing (affect_function. finalize) ? SciMLBase. FINALIZE_DEFAULT : (c, u, t, i) -> affect_function. finalize (i),
800
803
initializealg = reinitialization_alg (cb))
801
804
end
@@ -878,8 +881,8 @@ function compile_affect_fn(cb, sys::AbstractODESystem, dvs, ps, kwargs)
878
881
eq_aff = affects (cb)
879
882
eq_neg_aff = affect_negs (cb)
880
883
affect = compile_affect (eq_aff, cb, sys, dvs, ps; expression = Val{false }, kwargs... )
881
- function compile_optional_affect (aff)
882
- if isnothing (aff)
884
+ function compile_optional_affect (aff, default = nothing )
885
+ if isnothing (aff) || aff == default
883
886
return nothing
884
887
else
885
888
return compile_affect (aff, cb, sys, dvs, ps; expression = Val{false }, kwargs... )
@@ -890,8 +893,8 @@ function compile_affect_fn(cb, sys::AbstractODESystem, dvs, ps, kwargs)
890
893
else
891
894
affect_neg = compile_optional_affect (eq_neg_aff)
892
895
end
893
- initialize = compile_optional_affect (initialize_affects (cb))
894
- finalize = compile_optional_affect (finalize_affects (cb))
896
+ initialize = compile_optional_affect (initialize_affects (cb), NULL_AFFECT )
897
+ finalize = compile_optional_affect (finalize_affects (cb), NULL_AFFECT )
895
898
(affect = affect, affect_neg = affect_neg, initialize = initialize, finalize = finalize)
896
899
end
897
900
@@ -1097,11 +1100,11 @@ function compile_user_affect(affect::ImperativeAffect, cb, sys, dvs, ps; kwargs.
1097
1100
let user_affect = func (affect), ctx = context (affect)
1098
1101
function (integ)
1099
1102
# update the to-be-mutated values; this ensures that if you do a no-op then nothing happens
1100
- modvals = mod_og_val_fun (integ. u, integ. p... , integ. t)
1103
+ modvals = mod_og_val_fun (integ. u, integ. p, integ. t)
1101
1104
upd_component_array = NamedTuple {mod_names} (modvals)
1102
1105
1103
1106
# update the observed values
1104
- obs_component_array = NamedTuple {obs_sym_tuple} (obs_fun (integ. u, integ. p... , integ. t))
1107
+ obs_component_array = NamedTuple {obs_sym_tuple} (obs_fun (integ. u, integ. p, integ. t))
1105
1108
1106
1109
# let the user do their thing
1107
1110
modvals = if applicable (user_affect, upd_component_array, obs_component_array, ctx, integ)
0 commit comments