I'm trying to use NDSolve
to solve a 1D Schrodinger's equation, and it seems that MaxStepFraction
has huge effect on the performance.
L = 5; Et[t_] := Cos[2 t];
eqn = I D[ψ[x, t], t] == -(1/2) (D[ψ[x, t], {x, 2}]) + Et[t]*x*ψ[x, t]
init = {ψ[x, 0] == Exp[-(4 x^2)], ψ[L, t] == ψ[-L, t]}
sol = NDSolve[{eqn}~Join~init, ψ, {x, -L, L}, {t, 0, 6}, MaxStepFraction -> 1/2000]; // AbsoluteTiming
Here are the timing information I get:
MaxStepFraction |time(second)|
----------------+------------+
1/1800 |not converge|
1/2000 | 4.5 |
1/2500 | 98.5 |
1/3000 | 9.1 |
For not converge, I mean it gives warning like:
NDSolve::eerr: Warning: scaled local spatial error estimate of 640.1602231577178
at t = 4.504519571558874
in the direction of independent variable x is much greater than the prescribed error tolerance. Grid spacing with 1801 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or a smaller grid spacing can be specified using the MaxStepSize or MinPoints method options. >>
If we slightly change L, and let L=7.5
, the performance is quit different:
MaxStepFraction |time(second)|
----------------+------------+
1/1800 |not converge|
1/2000 | 64 |
1/2500 |not converge|
1/3000 | 136 |
Questions:
- Why the value of MaxStepFraction affect the performance so dramatically? For example, sometimes converge very fast, and sometimes doesn't converge at all.
- Are there some guide lines for choose the the value of MaxStepFraction for optimal performance?
- General guide lines for better performance of NDSolve for PDEs (or should I leave NDSolve and build my own solver)?
PS: I'm using version 9 on Red Hat Enterprise Linux 6, on Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz.
m
? $\endgroup$MaxStepFraction
don't "converge" forL = 5
in v8.0.4. (Vista Home Basic 32bit. BTW, 2GB memory so it can't bear theL = 7.5
case 囧.) And according to my experience, warning messages ofNDSolve
isn't a big deal for many cases. With the method mentioned in this post your warning will disappear but in fact the result doesn't change much. $\endgroup$