4
$\begingroup$

I would like to use EventLocator to stop NDSolve with the Event command

"Event" -> Abs[D[f[x,y,t],t]] < threshold

That is, I need to check the time derivative of function f[x,y,t] over a spatial domain a >= 0 && a <= L, b >= 0 && b <= L at each integration step. Beside, it is clear that at that moment the temporal boundary is t. When I run it, NDSolve gives:

"The function value \ Abs[InterpolatingFunction[...]+<<1>><<<1>> is not True or False \ when the arguments are {3.187144811900335`*^-8,<<4>>}"

I am not familiar with Event, but I understand that one should use a and b instead of x and y in the Abs[...], because x and y are NDSolve variables and it is better to avoid inserting them in the numerical functions.

Actually, what I need is something like this:

"Event" -> Abs[D[f[a,b,t],t], a >= 0 && a <= L, b >= 0 && b <= L] < threshold

Obviously, it is not correct in the syntax of Abs, how can I implement the 'Event' properly to this end. Thank you!

$\endgroup$

1 Answer 1

1
$\begingroup$

Here is an example for a 1D PDE modified from the documentation, where the integration will stop as long as Derivative[1, 0][u][t, x] > 1:

eqn = {
 D[u[t, x], t, t] == D[u[t, x], x, x] - Sin[u[t, x]], 
 u[0, x] == E^(-(x - 5)^2) + E^(-(x + 5)^2/2), Derivative[1, 0][u][0, x] == 0, 
 u[t, -50] == u[t, 50]
}

NDSolve[eqn, u, {t, 0, 100}, {x, -50, 50},
 Method -> {
   "MethodOfLines", "DiscretizedMonitorVariables" -> True,
   "SpatialDiscretization" -> {"TensorProductGrid", "DifferenceOrder" -> "Pseudospectral"},
   Method -> {
     "EventLocator",
     "Event" :> 
      If[And @@ (# < 1 & /@ Abs[Derivative[1, 0][u][t, x]]), 0, 1],
     "EventLocationMethod" -> "StepBegin"
   }
 }
]
$\endgroup$
5
  • $\begingroup$ Perhaps you could add a link to the relevant documentation page as well. $\endgroup$
    – MarcoB
    Jun 1, 2016 at 17:15
  • $\begingroup$ @MarcoB Thanks for the editing. I have added the link. $\endgroup$ Jun 1, 2016 at 17:51
  • $\begingroup$ @can Derivative[1, 0][u][t, x] represents a series of values corresponding to different x in the solving region at the current time t. For example, {u[t,x1],u[t,x2],...}.I'm trying to check whether there is at least one of those values breaks our condition, so we will stop the integration. $\endgroup$ Jun 2, 2016 at 1:59
  • $\begingroup$ @ xslittlegrass, thanks for your answer. In the condition of the If I understand that you Map the pure function #<1 & onto Abs to give 0 or 1 when the condition is true or false, respectively. But I don't understand that why you Apply the And to (...)? What is the intention that And only Apply only one argument? $\endgroup$
    – Enter
    Jun 2, 2016 at 2:00
  • $\begingroup$ @xslittlegrass, in my real problem, when I run the NDSolve it gives >"The function value If[<<1>>,0,1] is not True or False when the arguments are {...}." After three warning like this, and this line: >Further output of NDSolve::nbnum1 will be suppressed during this calculation. >>. It runs normally so far, however I will accept it if the solution is numerical reasonably. Thank you! $\endgroup$
    – Enter
    Jun 4, 2016 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.