I am trying to solve a PDE with NDSolve, but it turns out that it uses a lot of RAM memory. In fact my PC stalled serveral times. I tried with two different computers and with Mathematica versions v11.0 and v11.1, with the same results. The memory used goes up till filling all the RAM. I think it is because I am trying to use a large resolution and over a large period of time.
As a solution I tried to reinitialize the code, with the hope of freeing some memory. My simplifyied code (the real one is more complex) is
a = 10;
xl = yl = -a;
xr = yr = a;
tmax = 1;
ClearAll[vortex];
vortex[x_, y_] := (1/Sqrt[6 π ] ) Exp[-(x^2 + y^2)/(6)];
eqn = I*Derivative[0, 0, 1][ψ][x,y,t] == -0.5 Laplacian[ψ[x,y,t],{x,y}] +
(Abs[ψ[x, y, t]]^2 + (x^2 + y^2)/2)*ψ[x,y,t];
bcs ={ψ[xl,y,t]==vortex[xl, y], ψ[xr,y,t] == vortex[xr, y],
ψ[x,yl,t] ==vortex[x,yl], ψ[x,yr,t] == vortex[x,yr]};
ics = ψ[x,y,0] == vortex[x,y];
nxy = 200;
ndssdata =
First[NDSolve`ProcessEquations[{eqn,ics,bcs}, ψ, {x,xl,xr}, {y,yl,yr},
{t,0,tmax},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> nxy, "MaxPoints" -> 2 nxy}}]];
and
NDSolve`Iterate[ndssdata, 0.1];
ndsol = NDSolve`ProcessSolutions[ndssdata, "Forward"]
Then I want to reinitialize the code using the solution at time t=0.1, I got:
newstate = First[NDSolve`Reinitialize[ndssdata, {ics=ψ[x, y, 0]==
Evaluate[ψ[x,y,0.1]/.ndsol]}]]
(* {NDSolve`StateData["<" 0. ">"]} *)
and now I want to iterate another 0.1 timestep:
NDSolve`Iterate[newstate, 0.1]
The problem is that the original code use too much memory when I set a large resolution -nxy large or spatial resolution better than 0.01-. The procedure above seems to bound the total memory used if I reinitialize every small timestep. There is some other way to solve this issue? I mean to keep the memory bounded, or a more elegant way of reinitializing the code automatically. I also find different solutions depending on the method. The pseudoespectal method, I think is the method to use in my case, is the one which approach the correct solution. Thankx.