4

Now I am trying to solve the following 2D+1 type of PDE:

$\partial_t u(t,x,y)=-y\partial_{x}u+\partial_{y}\left[a y+b sin(x)u+c\partial_{y}u\right]$

with $u(0,x,y)=\frac{1}{2\pi}e^{-((x-\pi/4)^2+y^2)/2}$

and periodic boundary condition:

$u(t,-\pi,y)=u(t,\pi,y)$

In $y$-direction, it is unbounded.

Here is the code:

a = 1;
T = 1;
ωcb = -50;
ωct = 50;
ωb = -5;
ωt = 5;
A = 10;
γ = 0.1;
kT = 0.1;
ufun = NDSolveValue[{D[u[t, θ, ω], t] == -D[ω u[t, θ, ω], θ] - 
       D[-A Sin[θ] u[t, θ, ω] - γ kT D[u[t, θ, ω], ω], ω] + 0.1 D[ω u[t, θ, ω], ω], 
    u[0, θ, ω] == 
     1/(2 a π)
       E^(-((θ - π/4)^2/(2 a^2)) - (ω)^2/(2 a^2)),
    u[t, -π, ω] == u[t, π, ω], 
    u[t, θ, ωcb] == u[t, θ, ωct]}, 
   u, {t, 0, 
    T}, {θ, -π, π}, {ω, ωcb, ωct},
    Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> {"TensorProductGrid", 
       "MinPoints" -> 200, "MaxPoints" -> 1000}}];
plots = Table[
   Plot3D[Abs[
     ufun[t, θ, ω]], {θ, -π, π}, {ω, ωb, ωt}, PlotRange -> All, 
    ColorFunction -> "LakeColors"], {t, 0, T, .1}];
ListAnimate[plots]

The solution is a mess. I believe there are some problem on mesh?

enter image description here

Also there are some message

NDSolveValue::mxsst: Using maximum number of grid points 1000 allowed by the MaxPoints or MinStepSize options for independent variable $\theta$.

NDSolveValue::ibcinc: Warning: boundary and initial conditions are inconsistent.

NDSolveValue::eerr: Warning: scaled local spatial error estimate of 62.663959713694915at t = 1. in the direction of independent variable θ is much greater than the prescribed error tolerance. Grid spacing with 1001 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.

But when I try

Method -> {"MethodOfLines", 
         "SpatialDiscretization" -> {"TensorProductGrid", 
           "MinPoints" -> 200, "MaxPoints" -> 10000}}

It cannot manage to finish the program. What's going on ? Thanks for any suggestion!

Reference: enter image description here

Bob Lin
  • 445
  • 2
  • 8
  • Is this equation taken from literature or derived by yourself? Can you add some background information? – xzczd Aug 16 '18 at 09:06
  • Yes, I derive it by myself. It's the Klein-Kramers equation or 2D Fokker-Planck equation in rotational coordinate with sinusoidal potential. – Bob Lin Aug 16 '18 at 10:09
  • The initial data is not symmetric, so the periodic boundary conditions for the variable θ are inconsistent with the initial data. – Alex Trounev Aug 16 '18 at 11:25
  • 1
    We must pay attention to the code or the equations that are declared by the author? The equations in the code and in the beginning of the topic do not coincide. – Alex Trounev Aug 16 '18 at 12:00
  • @AlexTrounev I guess OP's equation in the code is a variant of the one in the reference. (He mentioned that "I derive it by myself" in his first comment. ) Of course this is something that OP should clarify. – xzczd Aug 16 '18 at 12:12
  • @AlexTrounev as xzczd said. These two equation on indeed in a same form. – Bob Lin Aug 16 '18 at 13:48
  • And what equation do you propose to solve? I see at the beginning of the topic one equation, in the code - second, and the third in the end. In the formulation of the problem, the initial data are symmetric, while in the codes it is not symmetric. Why? – Alex Trounev Aug 16 '18 at 14:10
  • The exact equation is shown in code. For the initial condition, sorry about that... it is a typo. The initial condition in equation should be asymmetric in the code also. – Bob Lin Aug 16 '18 at 14:17
  • Since you've mentioned $u$ is probability density in your subsequent question, are you sure the i.c. is E^(-((θ - π/4)^2/(2 a^2)) - ω^2/(2 a^2))/(2 a π) rather than E^(-((θ - π/4)^2/(2 a^2)) - ω^2/(2 a^2))/(2 a^2 π)? (Notice the difference in denominator. ) I find the original i.c. suspicious because Integrate[E^(-((\[Theta] - \[Pi]/ 4)^2/(2 a^2)) - \[Omega]^2/(2 a^2))/(2 a \[Pi]), {\[Theta], -Infinity, Infinity}, {\[Omega], -Infinity, Infinity}, Assumptions -> a > 0] outputs a. – xzczd Aug 17 '18 at 07:28
  • Yeah, you are right. Since I set a=1, I didn't realize the problem here. Thanks for pointing out. – Bob Lin Aug 17 '18 at 07:34

2 Answers2

9

You need the magic of "Pseudospectral":

mol[n_Integer, o_:"Pseudospectral"] := {"MethodOfLines", 
  "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> n, 
    "MinPoints" -> n, "DifferenceOrder" -> o}}

With[{u = u[t, θ, ω]}, eq = D[u, t] == -D[ω u, θ] - D[-A Sin[θ] u, ω] - γ kT D[u, ω] + 1/10 D[ω u, ω];

ic = u == E^(-((θ - π/4)^2/(2 a^2)) - ω^2/(2 a^2))/(2 a π) /. t -> 0];

ufun = NDSolveValue[{eq, ic, u[t, -π, ω] == u[t, π, ω], u[t, θ, ωcb] == u[t, θ, ωct]}, u, {t, 0, T}, {θ, -π, π}, {ω, ωcb, ωct}, Method -> mol[81]]; // AbsoluteTiming (* {24.137131, Null} *)

plots = Table[ Plot3D[Abs[ufun[t, θ, ω]], {θ, -π, π}, {ω, ωb, ωt}, PlotRange -> All, AxesLabel -> Automatic, PlotPoints -> 50, BoxRatios -> {Pi, ωb, 1}], {t, 0, T, .04}]; ListAnimate[plots]

enter image description here


Update: A faster approach

Your equation turns out to be another example where the somewhat strange difference strategy discussed in this post causes trouble, so the problem can be solved With the fix function in that post:

(* The fix function isn't included in this post, 
   please find it in the link above. *)
ufun = fix[T, 4]@
    NDSolveValue[{eq, ic, u[t, -π, ω] == u[t, π, ω], 
      u[t, θ, ωcb] == u[t, θ, ωct]}, 
     u, {t, 0, T}, {θ, -π, π}, {ω, ωcb, ωct}, 
     Method -> mol[81]]; // AbsoluteTiming
(* {13.415239, Null} *)

The resulting animation is similar so I'd like to omit it here.

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • The method is good, but the problem is not correct, so we have a message on the output NDSolveValue::ibcinc: Warning: boundary and initial conditions are inconsistent. – Alex Trounev Aug 16 '18 at 11:34
  • @Alex ibcinc warning pops up because the i.c. isn't periodic technically, but it's close to constant near $\theta=\pm \pi$ i.e. approximately periodic, so the warning isn't a big deal, I think. One can eliminate the warning by e.g. modifying i.c. to With[{u = u[t, θ, ω]}, ic = u == Piecewise[{{E^(-((θ - π/4)^2/(2 a^2)) - ω^2/(2 a^2))/( 2 a π), Abs@θ < 0.9 Pi}}] /. t -> 0], and the solution won't change much. Of course when the b.c. involves derivative, ibcinc often means fatal error, see this post for more information. – xzczd Aug 16 '18 at 11:57
  • Note that the equations in the code and in the beginning of the topic do not coincide. – Alex Trounev Aug 16 '18 at 12:08
  • Thanks for pointing out the problem. Indeed, they looks different but essentially the same. – Bob Lin Aug 16 '18 at 13:41
  • Could someone explain what's going on? I am confused with the method. What's the problem with my original code? Anyway, thanks! – Bob Lin Aug 16 '18 at 13:43
  • Any way to accelerate the computational time? like applying FEM or so. – Bob Lin Aug 16 '18 at 13:50
  • If I change your code by setting T=10, then it becomes very difficult to solve. Is there any potential issue on time step? – Bob Lin Aug 16 '18 at 14:00
  • @BobLin The problem of your original code is, the default method for spatial discretization doesn't work well for your equation. It's a rule of thumb that, "Pseudospectral" method may work well on PDE related to quantum mechanics and fluid dynamics, so I give it a try, and it works. "Pseudospectral" method is time and memory consuming compared to the default method, if 81 makes the code too slow, you may try a coarser grid e.g. mol[35] and see if the solution is accurate enough for you. – xzczd Aug 16 '18 at 14:05
  • What's the meaning of the function mol and argument? Btw, do you think the Dirichlet boundary condition (specify by hand) in y-direction is necessary? In my original code, I set a periodic bc for y to mimic the situation without boundary. – Bob Lin Aug 16 '18 at 14:11
  • @bob As to FEM, I don't think it'll help in this case, because you're solving the PDE in a simple domain and the coefficient is continuous, so there won't be a big difference between using FiniteElement method and "{"TensorProductGrid", "DifferenceOrder" -> 2}, as far as I can tell. – xzczd Aug 16 '18 at 14:14
  • I see. Since the region is rectangle, there is no benefit from FEM. – Bob Lin Aug 16 '18 at 14:18
  • @bob The mol function is a function I placed in my SystemOpen@"init.m", because the options therein are frequently adjusted. Method -> mol[35] is amount to Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> 35, "MinPoints" -> 35, "DifferenceOrder" -> "Pseudospectral"}}, check the document of Pattern and Optional for more information. As to the b.c. in y direction, I don't think it's necessary to use Dirichlet b.c. for approximation of b.c. at infinity. You can try it out to see if it approximates the unbounded domain better, of course. – xzczd Aug 16 '18 at 14:28
  • Just change a parameter a from 1 to 0.1. The solution still becomes unstable, do I have to refine the mesh? – Bob Lin Aug 16 '18 at 14:48
  • @bob It's a possible choice, but I think it's better to make the domain smaller. Try Table[a = 1/mid; Plot3D[E^(-((θ - π/4)^2/(2 a^2)) - ω^2/(2 a^2))/( 2 a π), {ω, -3, 3}, {θ, -3, 3}, PlotRange -> All], {mid, 1, 5}] and you'll know what I mean. – xzczd Aug 16 '18 at 15:03
  • I know what you mean but the problem is time-dependent, unfortunately. Therefore, the peak is moving around. It's inevitable to specify such a large region, or? – Bob Lin Aug 16 '18 at 16:42
  • @bob Oh… then the only choice is using a denser grid, I'm afraid. – xzczd Aug 17 '18 at 01:58
3

I took the equations and the statement of the problem at the beginning of the topic and wrote my code. I got the expected rotation of the wave as a result.

{a, b, c, k, L, T} = {1, 10, 1, 1, 5, 2};
    u0[x_, y_] := Exp[-(x^2 + y^2)/2]/(2*Pi)
eq = D[u[t, x, y], t] == -k*y*D[u[t, x, y], x] + 
    D[a*y + b*Sin[x]*u[t, x, y] + c*D[u[t, x, y], y], y];
ic = u[0, x, y] == u0[x, y];
bc = {u[t, x, -L] == u[t, x, L], u[t, -Pi, y] == u[t, Pi, y]};
   sol = NDSolveValue[{eq, ic, bc}, 
  u, {t, 0, T}, {x, -Pi, Pi}, {y, -L, L}, 
  Method -> {"MethodOfLines", 
    "SpatialDiscretization" -> {"TensorProductGrid", 
      "MinPoints" -> 40, "MaxPoints" -> 100, 
      "DifferenceOrder" -> "Pseudospectral"}}, MaxSteps -> 10^6]
plots = Table[
   Plot3D[Abs[sol[t, x, y]], {x, -Pi, Pi}, {y, -L, L}, 
    PlotRange -> All, ColorFunction -> "LakeColors", 
    Mesh -> None], {t, 0, T, .05*T}];
ListAnimate[plots]

fig1

Alex Trounev
  • 44,369
  • 3
  • 48
  • 106
  • The solution is perfect! Many thanks. Do you have any opinion on the mesh you use? I am not familiar with specifying these things. – Bob Lin Aug 16 '18 at 14:38
  • I used a very simple option Mesh -> None – Alex Trounev Aug 16 '18 at 14:46
  • Sorry I must misunderstand. What I want to ask is Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 40, "MaxPoints" -> 100, "DifferenceOrder" -> "Pseudospectral"}. How did you find those setup? – Bob Lin Aug 16 '18 at 14:50
  • I solved a similar equation, only non-linear in the complex plane. I picked up the parameters experimentally. – Alex Trounev Aug 16 '18 at 15:19
  • Sorry.. I copy your code but I cannot reproduce your solution. If your ic is centered at origin, I guess it won't rotate, right? – Bob Lin Aug 16 '18 at 17:33
  • Very sorry, I put the wrong parameters. Must be for this picture {a, b, c, k, L, T} = {10, 10, 1, 1, 5, 2}. Now I fixed the code. – Alex Trounev Aug 16 '18 at 18:03
  • I counted it again. For this picture {a, b, c, k, L, T} = {1, 10, 1, 1, 5, 2} – Alex Trounev Aug 16 '18 at 18:11
  • Thanks. Now it's fine. – Bob Lin Aug 16 '18 at 18:18