0

I am trying to locate the time when $R=1,T=0,P=0$ in my system of equations, but I get the following errors:

enter image description here

here is the code:

m = 1;
q = 1;
V[t_] := 1;
B0[t_] := 1;
\[CapitalOmega] = 1/27;
Br[t_, r_, \[Theta]_, \[Phi]_] := B0[t]/r^2;
Bt[t_, r_, \[Theta]_, \[Phi]_] := 0;
Bp[t_, r_, \[Theta]_, \[Phi]_] := 
  B0[t]/r \[CapitalOmega]/V[t] Sin[\[Theta]];
eq1 = m D[R[t, r, \[Theta], \[Phi]], {t, 2}] == 
   q (D[T[t, r, \[Theta], \[Phi]], t] Bp[t, r, \[Theta], \[Phi]] - 
      D[P[t, r, \[Theta], \[Phi]], t] Bt[t, r, \[Theta], \[Phi]]);
eq2 = m D[T[t, r, \[Theta], \[Phi]], {t, 2}] == 
   q (D[P[t, r, \[Theta], \[Phi]], t] Br[t, r, \[Theta], \[Phi]] - 
      D[R[t, r, \[Theta], \[Phi]], t] Bp[t, r, \[Theta], \[Phi]]);
eq3 = m D[P[t, r, \[Theta], \[Phi]], {t, 2}] == 
   q (D[R[t, r, \[Theta], \[Phi]], t] Bt[t, r, \[Theta], \[Phi]] - 
      D[T[t, r, \[Theta], \[Phi]], t] Br[t, r, \[Theta], \[Phi]]);

{{Pr, Pt, Pp}, points} = NDSolveValue[{eq1, eq2, eq3, R[0, r, [Theta], [Phi]] == 0, Derivative[1, 0, 0, 0][R][0, r, [Theta], [Phi]] == 0.1, T[0, r, [Theta], [Phi]] == Pi/3, Derivative[1, 0, 0, 0][T][0, r, [Theta], [Phi]] == -1, P[0, r, [Theta], [Phi]] == -Pi/3, Derivative[1, 0, 0, 0][P][0, r, [Theta], [Phi]] == -1, WhenEvent[{R[t, r, [Theta], [Phi]] == 1, T[t, r, [Theta], [Phi]] == 0, P[t, r, [Theta], [Phi]] == 0}, Sow[t]]}, {R, T, P}, {t, 0, 10}, {r, 0.1, 2}, {[Theta], -(Pi/3), Pi/3}, {[Phi], -(Pi/3), Pi/3}]

I thought it happened because my functions never meet my conditions, so I tried changing the initial conditions, so that $R=1,T=0,P=0$ at the initial time, but I still got the same errors.

EDIT I have tried following the solution in the linked comment. I have defined a function

eval[if : InterpolatingFunction[___][x_]] :=  if /. x -> "ValuesOnGrid";

and substituted the WhenEvent with

WhenEvent[{eval[R[t, r, \[Theta], \[Phi]]] == 1,  eval[T[t, r, \[Theta], \[Phi]]] == 0,   eval[P[t, r, \[Theta], \[Phi]]] == 0}, Sow[t]]

but I still get the same error

mattiav27
  • 6,677
  • 3
  • 28
  • 64

0 Answers0