Skip to main content
4 of 6
added 672 characters in body
Nobody
  • 823
  • 4
  • 11

How to solve PDE with complex-valued function?

I need to solve the PDE for a complex function $A(x,t)=A_r(x,t)+iA_i(x,t)$

eq = D[A[x, t], t] + 1/4*Conjugate[A[x, t]]*A[x, t]^2 - D[A[x, t], {x, 2}] - 2*A[x, t] == 0; 

over $[-L,L]$ and $[0,t_\text{max}]$. The equation is subject to a random initial condition and the boundary conditions as follows: $A_r(-L,t)=A_r(L,t)$ and $A_i(-L,t)=-A_i(L,t)$

L = 30; tmax = 30; ini[x_] = 1/10*BSplineFunction[RandomReal[{-1, 1}, 20], SplineClosed -> True, SplineDegree -> 5][x/(2*L)]; ibcs = {Re[A[-L, t]] == Re[A[L, t]], Im[A[-L, t]] == -Im[A[L, t]], A[x, 0] == ini[x]}; 

Then, I solve it with NDSolve

sol = NDSolve[{eq, ibcs}, A, {x, -L, L}, {t, 0, tmax}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 201, "MaxPoints" -> 201, "DifferenceOrder" -> "Pseudospectral"}}, AccuracyGoal -> 20] 

But I received the error

NDSolve::bcedge: Boundary condition Im[A[-30,t]]==-Im[A[30,t]] is not specified on a single edge of the boundary of the computational domain.>>

I didn't understand the error. Why the boundary conditions (bcs) must be specified on a single edge. Should not we set the bcs at both sides? Any suggestion is highly appreciated.

Thank for @xzczd's comment:

I just knew that NDSolve could not handle anti-periodic bc. Yes, the equation can be solved with a periodic bc:

periodbcs = {A[-L, t] == A[L, t], A[x, 0] == ini[x]} 

But the solution should be incorrect because the solution is a real function by observing its imaginary part.

 ContourPlot[Evaluate[Im[A[x, t] /. sol]], {x, -L, L}, {t, 0, tmax}, Contours -> 10, PlotRange -> All, PlotLegends -> Automatic, ColorFunction -> Hue, FrameLabel -> {"x", "t"}, PlotLabel -> "Ai", ImageSize -> 200] 

enter image description here

Response to @user64494's comment:

Yes, I can split the real and imaginary parts by writing the 2nd term as

$(A^\ast A)A=\vert A\vert^2A=(A_r^2+A_i^2)(A_r+i A_i)=A_r^3+A_i^2A_r+i(A_r^2A_i+A_i^3)$

Then the equation can be split into

eqs = {D[Ar[x, t], t] + 1/4*(Ar[x, t]^3*Ai[x, t]^2*Ar[x, t]) - D[Ar[x, t], {x, 2}] - 2*Ar[x, t] == 0, D[Ai[x, t], t] + 1/4*(Ar[x, t]^2*Ai[x, t] + Ai[x, t]^3) - D[Ai[x, t], {x, 2}] - 2*Ai[x, t] == 0}; 

But I don't know how to make an anti-periodic initial condition to be consistent with the boundary condition.

ibcs = {Ar[-L, t] == Ar[L, t], Ai[-L, t] == -Ai[L, t], Ar[x, 0] == ini[x], Ai[x, 0] = inianti[x]}; 
Nobody
  • 823
  • 4
  • 11