Skip to content

Commit 22ef643

Browse files
committed
evaluate all discrete conditions on same parameters
1 parent 0a241fc commit 22ef643

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/callbacks.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,11 @@ function _batch_affect(dcw::DiscreteCallbackWrapper)
569569

570570
(integrator) -> begin
571571
# Re-evaluate all conditions to determine which affects to execute
572+
# the affects might mutate p, therfor we ceate a copy to evaluate all
573+
# conditions on the unaltered state!
572574
cus = PreallocationTools.get_tmp(cucache, integrator.u)
573575
cobsf(integrator.u, integrator.p, integrator.t, cus)
576+
cps = copy(integrator.p)
574577

575578
any_uchanged = false
576579
any_pchanged = false
@@ -580,7 +583,7 @@ function _batch_affect(dcw::DiscreteCallbackWrapper)
580583
cuv = view(cus, condition_urange(dcw, i))
581584
c_u = SymbolicView(cuv, dcw.callbacks[i].condition.sym)
582585
cpidxsv = view(cpidxs, condition_prange(dcw, i))
583-
cpv = view(integrator.p, cpidxsv)
586+
cpv = view(cps, cpidxsv)
584587
c_p = SymbolicView(cpv, dcw.callbacks[i].condition.psym)
585588

586589
# Only execute affect if condition is true

0 commit comments

Comments
 (0)