I'm solving an ODE system with multiple events and find the discrete variable not updated as expected because one of the events is not triggered. During narrowing down the problem, I find something strange and cannot explain. Here are the simplified cases.
Case 1 works perfectly in the sense that the two events occur as expected. Case 2 does not work. Case 3 works by removing the action a[t] -> t in case 2 although the discrete variable won't get updated any longer.
Case 1
NDSolveValue[{y'[t] == Cos[t], y[0] == a[0] == 0,
WhenEvent[y[t], {Print[1], a[t] -> t}],
WhenEvent[t == a[t] + 0.1, Print[3]]}, y, {t, 0, 20}, DiscreteVariables -> a]
Case 2
NDSolveValue[{y'[t] == Cos[t], y[0] == a[0] == 0,
WhenEvent[y'[t], {Print[1], a[t] -> t}],
WhenEvent[t == a[t] + 0.1, Print[3]]}, y, {t, 0, 20}, DiscreteVariables -> a]
Case 3
NDSolveValue[{y'[t] == Cos[t], y[0] == a[0] == 0,
WhenEvent[y'[t], Print[1]],
WhenEvent[t == a[t] + 0.1, Print[3]]}, y, {t, 0, 20}, DiscreteVariables -> a]
Maybe this issue is not relevant to the real case. But how to understand the action a[t] -> t will stop the event from happening while it is not even part of the ODE? And why is only y' affected in this case?
t == 0. The events never happen. So, to me, the first question to investigate is whyNDSolve[]quits right away. $\endgroup$Null, the value returned byPrint[1], is not really a valid action. Sometimes it causes trouble, sometimes it doesn't (~ GIGO). If the action is{Print[1]; a[t] -> t}, then it seems to work. $\endgroup$