Why is it not possible to use "LocationMethod" -> "Brent" to locate an event when the action is "DiscontinuitySignature"? The following code produces NDSolve::jevlm (in version 13.3):
NDSolve[{x'[t] == y[t], x[0] == 0, y[0] == 1,
WhenEvent[1 - x[t] == 0, y[t] -> "DiscontinuitySignature", "LocationMethod" -> "Brent"]},
{x, y}, {t, 0, 2}, DiscreteVariables -> {y \[Element] {-1, 1}}]
(* NDSolve: The location method "BrentBracketRoot" may only be used when
the event can be handled as a real-valued function. *)
It seems like the "DiscontinuitySignature" action is important to reproduce the error. With another action, the code works as expected, for instance:
NDSolve[{x'[t] == y[t], x[0] == 0, y[0] == 1,
WhenEvent[1 - x[t] == 0, "StopIntegration", "LocationMethod" -> "Brent"]},
{x, y}, {t, 0, 2}, DiscreteVariables -> {y \[Element] {-1, 1}}]
Context: I have an application where I suspect that WhenEvent is not locating the event precisely enough, leading to imprecise results. To solve this, I tried "LocationMethod" -> "Brent" but then encountered the above problem. I have also tried "IntegrateEvent" -> True with a different error.
"LocationMethod" -> "BrentBracketRoot"seems to work fine (no error message). I think you will find an explanation in the tutorial on Events and Discontinuities in Differential Equations: For events that are set up to handle discontinuity crossings, it is very useful for the event handler to have a bracketing interval $t{a-}<t_a<t_{a+}$ so that it can do proper evaluations on either side of the discontinuity and ensure the crossing is done correctly. This is done with the method "BrentBracketRoot"._ – Domen Jan 23 '24 at 11:31"BrentBracketRoot"is the default method chosen for"DiscontinuitySignature". The event is removed from the system, so the error has serious consequences. Perhaps report it to WRI. As far the main goal to getNDSolveto try Brent's method, it seems it is done automatically. – Goofy Jan 23 '24 at 11:47"LocationMethod" -> "Brent"instead of"LocationMethod" -> "BrentBracketRoot"(I would be happy to accept it if you post it as an answer). – Escall Jan 23 '24 at 14:55"LocationMethod" -> "BrentBracketRoot"I get the same results as with no options, so it indeed seems like this is the default. (Unfortunately, it did not solve my underlying problem but that's off-topic.) – Escall Jan 23 '24 at 14:57