@@ -882,43 +882,63 @@ function (ia::ImplicitAffect)(integ)
882882 return ia. reset_jumps && reset_aggregated_jumps! (integ)
883883end
884884
885- """
886- VectorAffect{E2A, AFFS}
887-
888- Callable struct for the positive-edge arm of a `VectorContinuousCallback`. Routes an
889- integrator call to the appropriate per-equation affect based on the equation index `idx`.
890- Created inside [`generate_callback`](@ref) for vectors of `SymbolicContinuousCallback`s.
891-
892- # Fields
893- - `eq2affect`: maps condition equation index → affect index
894- - `affects`: vector of compiled affect callables, one per callback in the group
895- """
896- struct VectorAffect{E2A, AFFS}
897- eq2affect:: E2A
898- affects:: AFFS
899- end
900-
901- (va:: VectorAffect )(integ, idx) = va. affects[va. eq2affect[idx]](integ)
902-
903- """
904- VectorAffectNeg{E2A, AFFS}
885+ @static if pkgversion (SciMLBase) < v " 3"
886+ """
887+ VectorAffect{E2A, AFFS}
888+
889+ Callable struct for a `VectorContinuousCallback`. Routes an
890+ integrator call to the appropriate per-equation affect based on the equation index `idx`.
891+ Created inside [`generate_callback`](@ref) for vectors of `SymbolicContinuousCallback`s.
892+ Skips `nothing` affects.
893+
894+ # Fields
895+ - `eq2affect`: maps condition equation index → affect index
896+ - `affects`: vector of compiled affect callables (entries may be `nothing`)
897+ """
898+ struct VectorAffect{E2A, AFFS}
899+ eq2affect:: E2A
900+ affects:: AFFS
901+ end
905902
906- Callable struct for the negative-edge arm of a `VectorContinuousCallback`. Like
907- [`VectorAffect`](@ref) but skips `nothing` entries (callbacks with no negative-edge affect).
903+ function (va:: VectorAffect )(integ, idx)
904+ f = va. affects[va. eq2affect[idx]]
905+ f === nothing && return
906+ return f (integ)
907+ end
908908
909- # Fields
910- - `eq2affect`: maps condition equation index → affect index
911- - `affect_negs`: vector of compiled negative-edge affect callables (entries may be `nothing`)
912- """
913- struct VectorAffectNeg{E2A, AFFS}
914- eq2affect:: E2A
915- affect_negs:: AFFS
916- end
909+ else
910+ """
911+ $TYPEDEF
912+
913+ Callable struct for a `VectorContinuousCallback`. Routes an
914+ integrator call to the appropriate per-equation affect based on the equation index `idx`.
915+ Created inside [`generate_callback`](@ref) for vectors of `SymbolicContinuousCallback`s.
916+ Skips `nothing` affects.
917+
918+ # Fields
919+ - `eq2affect`: maps condition equation index → affect index
920+ - `affects`: vector of compiled positive-edge affect callables (entries may be `nothing`)
921+ - `affect_negs`: vector of compiled negative-edge affect callables (entries may be `nothing`)
922+ """
923+ struct VectorAffect{E2A, AFFS, NAFFS}
924+ eq2affect:: E2A
925+ affects:: AFFS
926+ affect_negs:: NAFFS
927+ end
917928
918- function (va:: VectorAffectNeg )(integ, idx)
919- f = va. affect_negs[va. eq2affect[idx]]
920- f === nothing && return
921- return f (integ)
929+ function (va:: VectorAffect )(integ, evts)
930+ for (i, evt) in enumerate (evts)
931+ if evt == 1
932+ f = va. affects[va. eq2affect[i]]
933+ f === nothing && continue
934+ f (integ)
935+ elseif evt == - 1
936+ f = va. affect_negs[va. eq2affect[i]]
937+ f === nothing && continue
938+ f (integ)
939+ end
940+ end
941+ end
922942end
923943
924944"""
@@ -1073,7 +1093,7 @@ one equation) from a homogeneous group of `SymbolicContinuousCallback`s that sha
10731093rootfinding class. Delegates to the single-callback overload when `sum(num_eqs) == 1`.
10741094
10751095Affect routing (from condition equation index to per-callback affect) is encoded in
1076- [`VectorAffect`](@ref) and [`VectorAffectNeg `](@ref) callable structs.
1096+ the [`VectorAffect `](@ref) callable structs.
10771097Initialize/finalize are wrapped in [`VectorOptionalAffect`](@ref) via
10781098[`wrap_vector_optional_affect`](@ref).
10791099"""
@@ -1101,17 +1121,30 @@ function generate_callback(cbs::Vector{SymbolicContinuousCallback}, sys; kwargs.
11011121 eq2affect = reduce (vcat, [fill (i, num_eqs[i]) for i in eachindex (compiled. affects)])
11021122 eqs = reduce (vcat, eqs)
11031123
1104- affect = VectorAffect (eq2affect, compiled. affects)
1105- affect_neg = VectorAffectNeg (eq2affect, compiled. affect_negs)
1106- initialize = wrap_vector_optional_affect (compiled. inits, SciMLBase. INITIALIZE_DEFAULT)
1107- finalize = wrap_vector_optional_affect (compiled. finals, SciMLBase. FINALIZE_DEFAULT)
1108-
1109- return VectorContinuousCallback (
1110- trigger, affect, affect_neg, length (eqs); initialize, finalize,
1111- rootfind = cbs[1 ]. rootfind, initializealg = cbs[1 ]. reinitializealg,
1112- saved_clock_partitions = compiled. saved_clock_partitions,
1113- initialize_save_discretes = cbs[1 ]. initialize_save_discretes
1114- )
1124+ @static if pkgversion (SciMLBase) < v " 3"
1125+ affect = VectorAffect (eq2affect, compiled. affects)
1126+ affect_neg = VectorAffect (eq2affect, compiled. affect_negs)
1127+ initialize = wrap_vector_optional_affect (compiled. inits, SciMLBase. INITIALIZE_DEFAULT)
1128+ finalize = wrap_vector_optional_affect (compiled. finals, SciMLBase. FINALIZE_DEFAULT)
1129+
1130+ return VectorContinuousCallback (
1131+ trigger, affect, affect_neg, length (eqs); initialize, finalize,
1132+ rootfind = cbs[1 ]. rootfind, initializealg = cbs[1 ]. reinitializealg,
1133+ saved_clock_partitions = compiled. saved_clock_partitions,
1134+ initialize_save_discretes = cbs[1 ]. initialize_save_discretes
1135+ )
1136+ else
1137+ affect = VectorAffect (eq2affect, compiled. affects, compiled. affect_negs)
1138+ initialize = wrap_vector_optional_affect (compiled. inits, SciMLBase. INITIALIZE_DEFAULT)
1139+ finalize = wrap_vector_optional_affect (compiled. finals, SciMLBase. FINALIZE_DEFAULT)
1140+
1141+ return VectorContinuousCallback (
1142+ trigger, affect, length (eqs); initialize, finalize,
1143+ rootfind = cbs[1 ]. rootfind, initializealg = cbs[1 ]. reinitializealg,
1144+ saved_clock_partitions = compiled. saved_clock_partitions,
1145+ initialize_save_discretes = cbs[1 ]. initialize_save_discretes
1146+ )
1147+ end
11151148end
11161149
11171150"""
0 commit comments