# Mathematica running out of RAM while executing NDSolve

I am playing with Mathematica to solve the 2D-wave equation with the code below:

tmin = 0; tmax = 1; xmin = -1; xmax = 5; ymin = -1; ymax = 1;
weqn = D[u[t, x, y], {t, 2}] == D[u[t, x, y], {x, 2}] + D[u[t, x, y], {y, 2}];
ic = {u[0, x, y] == Exp[-(x^2 + y^2)],Derivative[1, 0, 0][u][0, x, y] == 2*x*Exp[-(x^2 + y^2)]};
sol = NDSolve[{weqn, ic}, u, {t, tmin, tmax}, {x, xmin, xmax}, {y, ymin, ymax}, MaxStepSize -> 0.01]


At some point in my computation, my laptop runs out of RAM and Mathematica quits the Kernel. Is there any way I can make Mathematica save the solution as to free up RAM and continue the computation up to greater time?

Update Regarding initial conditions.

Consider, for simplicity, the 1D-wave equation. The solutions are of the form $$u(t,x) = f(x-t) + g(x+t)$$, the former and the latter represent solutions going to the right and left, respectively. If we run the following code on Mathematica:

weqn = D[u[t, x], {t, 2}] == D[u[t, x], {x, 2}];
icn = {u[0, x] == Exp[-x^2], Derivative[1, 0][u][0, x] == 0};
DSolve[{weqn, icn}, u[t, x], {t, x}]


We get

u[t, x] -> 1/2 (E^-(t - x)^2 + E^-(t + x)^2)


As expected. But it is possible to pick the solution going to the right by setting $$\partial_t u (0,x) = 2 x e^{-x^2}$$. In fact, by setting

ic = {u[0, x] == Exp[-x^2], Derivative[1, 0][u][0, x] == 2*x*Exp[-x^2]};


Mathematica gives

u[t, x] -> E^-(t - x)^2


And this completely describes the solution. However, when I solve the same equation with the same i.c. by using NDSolve, I get the bcart warning. But the numerical solution behaves exactly like the analytical solution.

I used the same reasoning to set the initial condition for the 2D-wave equation. It's a gaussian moving in the x-direction. In fact, for small times, this is what I'm getting.

So, even though there could be an issue with boundary conditions, I wanted to solve the equation in a larger grid in which the initial gaussian packet would not reach the boundary during my run.

I still would like to know if it would be possible to save the solution on the laptop's drive while NDSolve is still running.

• You are trying to solve numerically wave PDE on square, but you did not supply boundary conditions? I am afraid to try your code, because I do not want to run out of RAM and have to reboot. Strange that the code run. But try again with boundary conditions and see what happens. – Nasser May 27 '19 at 11:46
• Please notice the missing of b.c.s is a serious problem: mathematica.stackexchange.com/q/73961/1871 @Nasser Actually OP's code produces bcart warning, at least in v11.3. – xzczd May 27 '19 at 11:53
• As already mentioned under your last question, you need e.g. ABC or PML to approximate b.c. at infinity. – xzczd May 27 '19 at 12:20
• Ignoring the warnings, from a fresh kernel,I get a solution with your code without a crash using a maximum of 4GB of memory (V12, Mac, 16GB RAM). – Michael E2 May 27 '19 at 13:57
• To do what you want, you could probably adapt the MonitorMethod from this tutorial – Michael E2 May 27 '19 at 16:11