# Issue concerning stopping NDSolve through EventLocator

Greetings. As the question-title is written I am having some trouble with getting a numerical integration stopped at a certain event. This integration is done through the use of NDSolve and I have specified more than one event for NDSolve to be on the lookout for via EventLocator.

Now you might say that this question is a bit funny because the default action that EventLocator takes at any event is that it stops the integration. I have two events that I am on the lookout for. I have specified one "EventAction" to take at a certain event. This is not to stop the integration but something else and it works fine throughout the integration. But when I want to end the integration I don't know what to do, since the EventAction I have specified comes in the way for this second event for which I want to end. Hold on now, I do know that I can specify an EventAction for each Event I am interested in, but my problem is that: if I leave it blank NDSolve sets it to be the same as the other "non-stopping" event, and I do not know of any command that stops NDSolve in its tracks to and let it finish there.

I looked around and found nothing that I could use from the page (linked above) describing EventLocator. Also I took a look at another post (link to post) here, and there Throw was used to stop the integration. I have myself tried to use Throw but I get complaints that "there's no enclosing Catch" and so on, so when I think of it I don't even know what to throw to catch with Catch. Also, in the link to the other post, the tag "StopIntegration" is used, is that something already predefined?

(Some code showing method-specification for NDSolve)

Method -> {"EventLocator",
"Event" :> {BooleanValuedFunctionConditionForStoppingNDSolve,
BooleanValuedFunctionForSomethingElse}, "EventAction" :> {
ThisStopsNDSolveInItsCurrentState,
SomeOtherEventAction
}, "Direction" -> {1, 1}, Method -> AdamsBM}


So what my problem is that I am unable to write some EventAction that make sense to stop NDSolve and let me have my solutions up to that point of integration. I feel I am unable to do this because I do not understand Throw that good, and that especially in this context.

I'd like to say that I am running two integrations through NDSolve in parallel on separate kernels. But I can't see how this would affect my issue here.

Any suggestions as to what to specify as EventAction for stopping the integration and returning the results? Seemingly from other posts (like the one I linked to) and the page describing the EventLocator method a Throw is used, and if it is the sensible option, how does it work? Also I'd gladly take any advice concerning programming methodology.

-
 Something like k = 0; Reap[y /. First@NDSolve[{y''[x] == -y[x], y[0] == 1, y'[0] == 0}, y, {x, 0, 7}, Method -> {"EventLocator", "Event" -> y[x], "EventAction" :> (Sow[x]; If[++k >= 2, Throw[Null, "StopIntegration"]])}]]? – J. M.♦ Oct 16 '12 at 23:40 Try Throw[Null , "StopIntegration"] for the action – acl Oct 16 '12 at 23:43 Check this out. This uses the EventLocator to stop when my time step gets too small as a result of stiffness. – drN Oct 16 '12 at 23:47