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;
    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}, 
    Method -> {"MethodOfLines", 
    "SpatialDiscretization" -> {"TensorProductGrid", 
    "MinPoints" -> nxy, "MaxPoints" -> 2 nxy}}]];


    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]== 
   (* {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.

  • 1
    $\begingroup$ Is the current b.c. an approximation for infinite domain? If so, there exists example where improper approximation for infinity causes trouble: mathematica.stackexchange.com/q/145478/1871 $\endgroup$ – xzczd Jun 22 '18 at 13:31
  • $\begingroup$ @xzczd it is possible, I thought about that. Excellent method you suggested me, I will implement it and tell you. Thank you very much. $\endgroup$ – Gluoncito Jun 22 '18 at 13:47
  • $\begingroup$ @xzczd I gave a try to the Scrinzi method, and modified your code but it didn't work with this equation. The "neweq" is really awfull, and not a surprise that Mathematica didn't integrate it -without any warnings-. However, I liked the methods and the subroutines involved. I wonder if I must post another question with the full PDE's (which is frustrating because I know I'm close to the solution and do not want other's peoples to waste time). $\endgroup$ – Gluoncito Jun 23 '18 at 23:28
  • $\begingroup$ If the problem can't be reproduced with this simplified example, it's definitely OK to add a new example to your question. (Of course the new example should be as simple as possible. ) $\endgroup$ – xzczd Jun 24 '18 at 9:27

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.