The following code works but it give several warnings that makes me feel nervous about the reliability and accuracy of the output:
NDSolve: Warning: estimated initial error on the specified spatial grid in the direction of independent variable x exceeds prescribed error tolerance.
How can I fix the warnings? Take note that I need an accurate and high resolution output.
The code below solves a partial differential equation for the propagation of a scalar field in 2D:
Clear["Global`*"]
size = 30; (* max distance from origin )
simulationtime = 20; ( time of the simulation )
alpha = 2; ( non-linear interaction parameter. *)
fieldequation = (D[field[t, x, y], t, t] - D[field[t, x, y], x, x] - D[field[t, x, y], y, y] + 2 alpha^2 (field[t, x, y]^2 - 1) field[t, x, y] == 0);
skeleton = Table[{x, y, RandomReal[{-1, 1}]}, {x, -size, size, 2}, {y, -size, size, 2}];
(* smooth initial conditions for the scalar field : *)
fluctuations = Interpolation[Flatten[skeleton, 1], Method -> "Spline"];
phi0[t_, x_, y_] = fluctuations[x, y]; (* static initial scalar field *)
bordersconditions = {
field[t, -size, y] == phi0[t, -size, y],
field[t, size, y] == phi0[t, size, y],
field[t, x, -size] == phi0[t, x, -size],
field[t, x, size] == phi0[t, x, size]
};
initialconditions = {
field[0, x, y] == phi0[0, x, y],
(D[field[t, x, y], t] /. t -> 0) == D[phi0[t, x, y], t] /. t -> 0
};
fieldsolution = NDSolve[
Flatten@{fieldequation, initialconditions, bordersconditions},
field,
{t, 0, simulationtime},
{x, -size, size},
{y, -size, size},
Method -> {
"MethodOfLines",
"SpatialDiscretization" -> {
"TensorProductGrid",
"MaxPoints" -> 200, (* slow compilation if > 200! )
"MinPoints" -> 200, ( less reliable if < 100. )
"DifferenceOrder" -> 4 ( At least 2. Very slow if > 6. *)
}}];
Manipulate[Plot3D[Evaluate[field[t, x, y] /. fieldsolution /. t -> time],
{x, -10, 10}, {y, -10, 10},
PlotPoints -> ControlActive[20, 60],
PlotRange -> {{-10, 10}, {-10, 10}, {-3, 3}}],
{{time, 0, "t"}, 0, simulationtime, 0.1}
]
Preview of what this code is doing:



NDSolvestill have trouble? – Michael E2 Jul 30 '23 at 17:24{x, y, Sin[x/30] Sin[y/30]}. I suspect it's the interpolation of random initial conditions that leads to theNDSolve::???message. I was suggesting you test take. But if the minimal-fluctuation fields gives the same message, then it's probably something else. – Michael E2 Jul 30 '23 at 17:37eerriwarning you've mentioned in the question), the really troublesome part is the posteriori error estimates (eerrwarning), for more info check how they are appraised in the document https://reference.wolfram.com/language/tutorial/NDSolveMethodOfLines.html#2081642391 – xzczd Jul 31 '23 at 02:29