0
$\begingroup$

I'm not very familiar with numerical resolution of partial derivatives equations in Mathematica, and I would like to optimize the following code. It's about a self-interacting wave propagating in 2D, with an Higgs-like potential:

Tmax = 20;

WaveEquation = 
  D[Phi[t, x, y], t, t] - D[Phi[t, x, y], x, x] - D[Phi[t, x, y], y, y] + 2(Phi[t, x, y]^2 - 1)Phi[t, x, y]== 0;

PHI0[x_, y_] = Tanh[x] + 1Sin[2 x - 2 y]; (* Initial field *)

BoundaryConditions = {
   Phi[t, -100, y] == PHI0[-100, y],
   Phi[t, 100, y] == PHI0[100, y],
   Phi[t, x, -100] == PHI0[x, -100],
   Phi[t, x, 100] == PHI0[x, 100]
   };

InitialConditions = {
   Phi[0, x, y] == PHI0[x, y],
   (D[Phi[t, x, y], t]/.t -> 0) == 0
   };

WaveSolution = NDSolve[
   Flatten@{WaveEquation, InitialConditions, BoundaryConditions},
    Phi,
   {t, 0, Tmax},
   {x, -100, 100},
   {y, -100, 100},
   PrecisionGoal -> 2
   ];

Manipulate[
 Plot3D[
  Evaluate[Phi[t, x, y]/.WaveSolution/.t -> time],
  {x, -10, 10},
  {y, -10, 10},
  PlotPoints -> {20, 20},
  PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
  Axes -> True,
  MeshFunctions -> (#3&),
  ColorFunction -> "Rainbow",
  ImageSize -> 700,
  Method -> {"RotationControl" -> "Globe"},
  SphericalRegion -> True
  ],
 {time, 0, Tmax, 0.01}
 ]

As you can see in this code, I'm only using the option PrecisionGoal -> 2 (which may be a wrong setting). I hear frequently of MaxSteps, MaxPoints and MinStepSize but I don't understand these options. There may be some other options that could help the numerical resolution.

So what could be the best setting in the NDSolve and Manipulate parts to help getting a more accurate resolution, faster and nicer rendering?

Currently, I'm frequently getting this kind of messages:

NDSolve::eerr: Warning: Scaled local spatial error estimate of 123.363575244 at = 20.' in the direction of independent variable x is much greater than prescribed error tolerance. Grid spacing with 101 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or you may want to specify a smaller grid spacing using the MaxStepSize or MinPoints method option.

Please, take note that I'm using the old Mathematica 7.0 so newer commands would be for an eventual upgrade (not yet, unfortunately!).


EDIT: Here's the simple 1+2D waves equation, and a simple sin wave as initial condition. This should give the exact same sin wave (before the boundaries have time to produce some reflections), since it's a solution to the waves equation. Yet, the shape output is very clumsy and inacurate, even at initial time! How can I improve the sin wave accuracy?

WaveEquation = D[Phi[t,x,y],t,t] - D[Phi[t,x,y],x,x] - D[Phi[t, x, y], y, y] == 0;

PHI0[t_, x_, y_] = Sin[2(x - t)]; (* Exact solution to the waves equation *)

BoundaryConditions = {
   Phi[t, -100, y] == PHI0[t, -100, y],
   Phi[t, 100, y] == PHI0[t, 100, y],
   Phi[t, x, -100] == PHI0[t, x, -100],
   Phi[t, x, 100] == PHI0[t, x, 100]
   };

InitialConditions = {
   Phi[0, x, y] == PHI0[t, x, y]/.t -> 0,
   (D[Phi[t, x, y], t]/.t -> 0) == D[PHI0[t, x, y], t]/.t -> 0
   };

WaveSolution = NDSolve[Flatten@{WaveEquation, InitialConditions, BoundaryConditions}, 
   Phi, {t, 0, 30}, {x, -100, 100}, {y, -100, 100}, 
   PrecisionGoal -> 2];

Manipulate[
 Plot3D[
  Evaluate[Phi[t, x, y]/.WaveSolution/.t -> time],
  {x, -10, 10},
  {y, -10, 10},
  PlotPoints -> {20, 20},
  PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}},
  Axes -> True,
  MeshFunctions -> (#3 &),
  ColorFunction -> "Rainbow",
  ImageSize -> 700,
  Method -> {"RotationControl" -> "Globe"},
  SphericalRegion -> True
  ],
 {time, 0, Tmax, 0.01}
 ]

Here's a preview, at initial time $t = 0$:

enter image description here

As you can see, this is not looking precisely as the initial sin wave! It's very crude and clumsy! What's wrong here? The boundaries (which are far away) don't have the time yet to modify this wave. How can I get a better representation of the initial wave?

$\endgroup$
1
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$
    – Kuba
    Dec 10 '20 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.