9

I'm solving an eigenvalue problem with special b.c. mentioned in the paper Edge states in gated bilayer-monolayer graphene ribbons and bilayer domain walls. (See Eq.(3)(6)(7) and the paragraph after (9). ) The paper author claims the problem is solved with COMSOL MULTIPHYSICS. I tried with NDEigensystem but failed.

The system involves four coupled ODE [$A1(x),B1(x),A2(x),B2(x)$] defined in the interval $x=\{-\infty,0\}$ and 2 ODE [$A(x),B(x)$] Eqs for $x=\{0,W\}$, The b.c.s are:

$A1(0)=A(0)$
$B1(0)=B(0)$
$B2(0)=0$
$B(W)=0$

and all functions $(A1,B1,A2,B2)$ in the left interval go to zero as $x$ goes to $-\infty$. Here is my trivial try

systm1[k_]:=Module[{a=400,hv = 0.65875 10^3, W = 23.86},{vals,funs}=NDEigensystem[{

hv(-B1'[x]-k B1[x]) +50 A1[x], hv(A1'[x]-k A1[x]) +50 B1[x]+a A2[x], hv(B2'[x]+k B2[x]) -50 A2[x]+a B1[x], hv(-A2'[x]+k A2[x]) -50 B2[x],

hv(-B'[x]-k B[x])+50A[x] , hv(A'[x]-k A[x])+50B[x] ,

DirichletCondition[{A1[0]==A[0],B1[0]==B[0],B2[0]==0,B[W]==0},True]},{A1[x],B1[x],A2[x],B2[x],A[x],B[x]},{x,-10W,10W},6,Method->{"SpatialDiscretization"->{"FiniteElement",{"MeshOptions"->{MaxCellMeasure->0.2}}}}]; Return[vals];]

systm1[0.]

NDEigensystem::femcscd: The PDE is convection dominated and the result may not be stable. Adding artificial diffusion may help.

NDEigensystem::fembdcc: Cross-coupling of dependent variables in DirichletCondition[A1 == A, True] is not supported in this version.

Kindly how can I implement the desired BCs?


Update 1

According to the answer by @xzczd, the problem can be reduced to 4 coupled odes considering the continuity at x=0 so the system with new BCs can be seen as in this picture

enter image description here


Update 2

So, following the answer by @xzczd we consider only the first 4 ode in the question and restrict the A2 and B2 (using If)to be only in the interval $(-\infty,0)$ which becomes

{a = 400, hv = 0.65875 10^3, W = 23.86, k = 0., inf = 10 W, bR = W};
<< NDSolve`FEM`;
meshline = 
  ToElementMesh[ImplicitRegion[-inf <= x <= bR, x], {{-inf, bR}}, 
   IncludePoints -> {{0}}, MaxCellMeasure -> 1];

{val, vec} = NDEigensystem[Flatten@{

 hv (-B1'[x] - k B1[x]) + 50 A1[x],
 hv (A1'[x] - k A1[x]) + 50 B1[x] + If[x &lt; 0, a, 0] A2[x],
 hv (B2'[x] + k B2[x]) - If[x &lt; 0, 50, 0] A2[x] + a B1[x],
 hv (-A2'[x] + k A2[x]) - If[x &lt; 0, 50, 0] B2[x],

 DirichletCondition[B2[x] == 0, x == 0], 
 DirichletCondition[B1[x] == 0, x == bR], 
 DirichletCondition[#, x == -inf] &amp; /@ {A1[x] == 0, B1[x] == 0, 
   A2[x] == 0, B2[x] == 0}}, {A1[x], B1[x], A2[x], 
B2[x]}, {x} \[Element] meshline, 6];      

but the eigenfunctions do not satisfy the some of BCs.

func = {A1, B1, A2, B2};
Plot[Abs[vec[[1, #]]], {x, -3 W, W}, PlotRange -> All, Frame -> True, 
   PlotStyle -> Red, PlotLabel -> ToString[func[[#]]]] & /@ Range[4]    

enter image description here


Update 3: Exact solution for k=0

For k=0, we can find an analytic solution, I will use here dimensionless units such that hv=1;a=1. So for $x<0$ we have these coupled equations

-B1'[x] +u A1[x]==En A1[x];
 A1'[x] +u B1[x]+A2[x]==En B1[x];
 B2'[x] -u A2[x]+B1[x]==En A2[x];
-A2'[x] -u B2[x]==En B2[x]; 

En is the eigenvalue, these equations can be decoupled and we obtain:

A1[x_]=(b1 E^(g1 x) g1)/(-En + u) + (b3 E^(g2 x) g2)/(-En + u);
B1[x_]=b1 E^(g1 x) + b3 E^(g2 x);
A2[x_]=(b1 E^(g1 x) (g1^2 + (En - u)^2) + 
 b3 E^(g2 x) (g2^2 + (En - u)^2))/(En - u);
B2[x_]=-((b1 E^(g1 x) g1 (g1^2 + (En - u)^2) + 
  b3 E^(g2 x) g2 (g2^2 + (En - u)^2))/((En - u) (En + u)));   

The constants b1 nad b3 to be determined using BCs and g1 , g2 are:

g1=Sqrt[-En^2 - u^2 + Sqrt[En^2 - u^2 + 4 En^2 u^2]];
g2=Sqrt[-En^2 - u^2 - Sqrt[En^2 - u^2 + 4 En^2 u^2]];    

for $x>0$ the equations become

-B'[x] +u A[x]==En A[x];
A'[x] +u B[x]==En B[x];    

solutions are

A[x_]=(E^(-r x) (a2 - a1 E^(2 r x)) r)/(En - u);
B[x_]=a2 E^(-r x) + a1 E^(r x);    

a1 and a2 constant to be determined r=Sqrt[-(En - u)^2].

Finally, applying the BCS with u = 0.125; gives

MM2[W_] = 1. {Coefficient[A[0] - A1[0], {a1, a2 , b1, b3}] // Simplify,
    Coefficient[B[0] - B1[0], {a1, a2 , b1, b3}] // Simplify,
    Coefficient[B[W], {a1, a2 , b1, b3}] // Simplify,
    Coefficient[B2[0], {a1, a2 , b1, b3}] // Simplify};   

then we can get the eigenvalue

In[18]:= Eng = FindRoot[Det[MM2[20]], {En, 0}]

Out[18]= {En -> -0.0184422 + 0. I}

Solving for a1,a2,b1,b3 we get

{a1, a2, b1, b3}={0.404367 + 0.519605 I, -0.615275 - 0.234391 I, 
 0.045056 + 0.253905 I, -0.255964 + 0.0313093 I};   

this gives

Block[{x1 = -20, x2 = 20, En = Re@Eng[[1, 2]]}, 
 Show[Plot[{Abs[A[x]^2], (Abs@B[x])^2}, {x, 0, x2}, Frame -> True, 
       PlotRange -> {{x1, x2}, All}], 
  Plot[{(Abs@A1[x])^2, (Abs@B1[x])^2, (Abs@A2[x])^2, (Abs@
      B2[x])^2}, {x, x1, 0},  
   Frame -> True, PlotRange -> All, 
   PlotLegends -> {"A1", "B1", "A2", "B2"}]]]    

enter image description here

xzczd
  • 65,995
  • 9
  • 163
  • 468
MMA13
  • 4,664
  • 3
  • 15
  • 21
  • Your statement that this returns nothing, is not quite correct. It does return messages and you'd need to take care of them. Click on the blue circle-i for more information. – user21 Jan 05 '23 at 06:38
  • @xzczd, thanks for the link, does that mean such a problem can not be handled by MMA? – MMA13 Jan 05 '23 at 07:15
  • @user21, you are right! The question is updated! – MMA13 Jan 05 '23 at 07:16
  • @xzczd, I don't understand why it is NOT allowed! OR you meant not allowed in MMA? this paper used the finite element method to solve the problem but using COMSOL! check Eqs3,6,7 and 5th line after Eq9. – MMA13 Jan 05 '23 at 08:30
  • Oops… seems that I'm too tired. The b.c.s A1[0]==A[0],B1[0]==B[0] are not inhomogeneous. (Incorrect comments deleted. ) "I have four coupled ODE [$A1(x),B1(x),A2(x),B2(x)$] defined in the interval $x={-\infty,0}$ and 2 ODE [$A(x),B(x)$] Eqs for $x={0,W}$" If so, then the problem cannot be directly handled by NDEigensystem, "different equations for different region" is not supported by NDEigensystem (at least for now). – xzczd Jan 05 '23 at 09:47
  • These DirichletCondition[{B2[0] == 0, B[W] == 0}, True] are homogeneous conditions, For {A1[0] == A[0], B1[0] == B[0]}, try a periodic boundary condition. – user21 Jan 06 '23 at 07:06
  • 1
    @xzczd, this solves a different PDE in different regions: NDEigensystem[ Inactive[ Div][-{{If[x < \[Pi]/2, 1, 10]}} . Inactive[Grad][u[x], {x}], {x}], u[x], {x, 0, \[Pi]}, 4] where did you find the statement that is not possible. I'd need to fix that. thanks. – user21 Jan 06 '23 at 07:09
  • @xzczd, here is another, more extreme, example: NDEigensystem[{-Laplacian[u[x], {x}] - If[x < \[Pi]/2, 1, 0]*u[x]}, u[x], {x, 0, \[Pi]}, 6] – user21 Jan 06 '23 at 07:14
  • @user21 When the different PDEs can be combined to one PDE with piecewise coefficients, NDSolve/NDEigensystem/... can of course handle the problem, but………………OK, OP's problem is exactly such a problem 囧. Let me write an answer. – xzczd Jan 06 '23 at 08:24
  • @xzczd, I have done this for NDSolve - but I have never done it for NDEigensystem. I just hope that 'PeriodicBoundaryCondition' is not a trouble maker this time :-( – user21 Jan 06 '23 at 08:34
  • 1
    @user21 If I understand the question correctly, the conditions $A1(0)=A(0), B1(0)=B(0)$ are not periodic b.c.s but continuity conditions. (The first 4 equations are defined in $(-\infty,0)$, but the last 2 are defined in $(0,W)$, they're linked by continuity of $A1$ and $A$, $B1$ and $B$ at $x=0$. ) – xzczd Jan 06 '23 at 08:44
  • @xzczd, I think you are correct, I did not read carefully enough. Even the better. – user21 Jan 06 '23 at 08:46
  • @user21, exactly, it is a continuity – MMA13 Jan 06 '23 at 11:17
  • I looked at this some more, and I see that B1[bR] is not zero. The others are satisfied, correct? I have tried a lot of things but I am unsure why this does not work. One thing could be the Eigensytem message but even the direct solver does not get a result with that bc satisfied. Refining the mesh leads to more problems. Are you sure the PDE is what you want to be? I have tired rearranging the variable names because of this but no cookie. I tried inserting the DirichletConditions... – user21 Jan 12 '23 at 10:22
  • ...into the equations. Again, nope. Sorry I do not know what the issue is. – user21 Jan 12 '23 at 10:30
  • @user21, thanks for the effort. I provided exact solution for k=0, kindly see update 3 – MMA13 Jan 12 '23 at 13:27
  • If I understand it right, this analytic solution is correct only around the given eigenvalue -0.0184422? Actually I also tried deducing the analytic solution, and then noticed that, when imposing the boundary condition at $-\infty$, the value of En involves in and the discussion becomes rather involved. – xzczd Jan 13 '23 at 04:29
  • By making use of that seldom used syntax of DirichletCondition, all the b.c.s are satsified for system in update 3, but the FEM solution is still not great, so I turn to FDM. See my update. @user21 and valar – xzczd Jan 13 '23 at 06:03
  • @xzczd, this is a strange equation. – user21 Jan 13 '23 at 07:02
  • @valarmorghulis can say something about where this system comes from? I mean, what is the application? – user21 Jan 13 '23 at 07:02
  • @xzczd, that is the iegenvalue the satisfy DetM=0 which gives also the correct constants that satisfy BCs. the might be other eigenvalues but did not check. – MMA13 Jan 13 '23 at 08:51
  • @user21, kindly check the paper I mentioned – MMA13 Jan 13 '23 at 08:52
  • 1
    Oops, I didn't notice Reduce[ForAll[{a, b}, {a, b} \[Element] Reals, Re@Sqrt[a + b I] >= 0]] is True. I see, -0.0184422 indeed looks like the only solution. – xzczd Jan 13 '23 at 09:53
  • A quick question. You have six first order differential equations, with 3 continuity conditions and one boundary conditions on the right hand side. So you can only specify two more conditions. Which of the functions, {A1,A2,B1,B2} do you actually want to set to be zero? Are A1, A2 actually derivatives of each other, written in a first order system? If so, can you write the actual differential equation you are trying to solve out directly please. – SPPearce Jan 13 '23 at 10:55
  • @SPPearce It's 2 continuity conditions, 1 b.c. at middle and 1 b.c. at right boundary. Symbolic analysis shows the 4 b.c.s at $-\infty$ are not independent. (These 4 b.c.s only remove 2 constants, see Addendum in my answer for more info. ) But it's not immediately clear to me if we can arbitrarily remove any 2 of them… – xzczd Jan 13 '23 at 11:14
  • @valarmorghulis, was my answer useful to you? – SPPearce Feb 14 '23 at 09:44

2 Answers2

9

"Different equations for different region" is not directly supported by NDSolve, NDEigensystem, etc. (at least for now), but in many cases, the different PDEs can be combined to one PDE with piecewise coefficients, and your problem luckily belongs to such cases. The following is a solution that at least produces a solution:

{a = 400, hv = 0.65875 10^3, W = 23.86, k = 0., inf = 2 W, bR = 10 W};
<< NDSolve`FEM`;
meshline = 
  ToElementMesh[ImplicitRegion[-inf <= x <= bR, x], {{-inf, bR}}, 
   IncludePoints -> {{0}}, MaxCellMeasure -> 1];

eps = 10^-3;

{val, vec} = NDEigensystem[Flatten@{ hv (-B1'[x] - k B1[x]) + If[x < 0, 50, 0] A1[x] + eps A1''[x], hv (A1'[x] - k A1[x]) + If[x < 0, 50, 0] B1[x] + If[x < 0, a, 0] A2[x] + eps B1''[x], hv (B2'[x] + k B2[x]) - 50 A2[x] + a B1[x] + eps A2''[x], hv (-A2'[x] + k A2[x]) - 50 B2[x] + eps B2''[x], DirichletCondition[B2[x] == 0, x == 0], DirichletCondition[B1[x] == 0, x == bR], DirichletCondition[#, x == -inf] & /@ {A1[x] == 0, B1[x] == 0, A2[x] == 0, B2[x] == 0}}, {A1, B1, A2, B2}, {x} ∈ meshline, 6];

Eigensystem::chnpdef: Warning: there is a possibility that the second matrix SparseArray[...] in the first argument is not positive definite, which is necessary for the Arnoldi method to give accurate results.

Further check shows the b.c. at x == bR isn't satisfied. Other b.c.s are satisfied well, though:

index = 3;

{vec[[index, 2]][bR], vec[[index, 4]][0], vec[[index]][-inf] // Through} (* {163.436 - 136.252 I, 5.5511210^-17 + 1.9428910^-16 I, {0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I}} *)

I'm not familiar with the corresponding physics background and haven't looked into the linked paper so cannot tell what's wrong, but I'd suggest double-checking if the system itself is correct as the next step.

Remark

  1. The IncludePoints -> {{0}} is necessary for the boundary condition at x == 0.

  2. Since the equations for A1 and A, B1 and B are combined, the junction conditions A1[0]==A[0], B1[0]==B[0] are automatically satisfied and don't need to be set explicitly.

  3. The eps is to suppress the NDEigensystem::femcscd warning, taking it away doesn't influence the solution much actually.


FDM based solution

FEM is having difficulty with the problem, so let me add a finite difference method (FDM) based solution. Here I'm solving the system in update 3 so we can compare with the deduced analytic solution. As usual, I'll use pdetoae for generation of difference equations:

{xL, xR} = {-20, 20};
vars = {A1, B1, A2, B2};

unitStepExpand = Simplify`PWToUnitStep@PiecewiseExpand@# &; oper = {-B1'[x] + u A1[x], A1'[x] + u B1[x] + unitStepExpand@If[x < 0, 1, 0] A2[x], B2'[x] - u A2[x] + B1[x], -A2'[x] - u B2[x]}

intervals = 500; points = intervals + 1; mid = intervals/2 + 1; grid = Subdivide[xL, xR, intervals]; difforder = 8; (* Definition of pdetoae isn't included in this post, please find it in the link above. *) ptoafunc = pdetoae[vars[x], grid, difforder]; disvars = Flatten@Outer[#[#2] &, vars, grid]; marray = CoefficientArrays[ptoafunc@oper // Flatten, disvars] // Last;

(* Impose the Dirichlet b.c.: *)
pos = {1, points + 1, 2 points + 1, 3 points + 1, 2 points, 3 points + mid};
(marray[[#, All]] = 0) & /@ pos;

{val, veclst} = Block[{u = 1/8}, Eigensystem[N[marray], 6, Method -> {"Arnoldi", "Shift" -> -0.1}]]; val (* {-0.18626, -0.168633, -0.136571, -0.122453 + 0.000729685 I, -0.122453 - 0.000729685 I, -0.0183314} *) vec = (ListInterpolation[#, grid] & /@ Partition[#, points]) & /@ veclst;

Block[{A1, B1, A2, B2}, {A1, B1, A2, B2} = #; Show[Plot[{A1[x], B1[x]}^2 // Abs // Evaluate, {x, 0, xR}, Frame -> True, PlotRange -> {{xL, xR}, All}], Plot[Through[{A1, B1, A2, B2}[x]]^2 // Abs // Evaluate, {x, xL, 0}, PlotRange -> All, PlotLegends -> {"A1", "B1", "A2", "B2"}]]] & /@ vec

enter image description here

As we can see, this method is far beyond perfect: the graphics of corresponding eigenvectors indicate the first 5 eigenvalues are fake. Nevertheless, the last eigenvalue is clearly the one found analytically by OP.

Remark

  1. The "Shift" sub-option is critical for this solution.

  2. difforder = 2 can be used, but then we need to set an even closer "Shift" e.g. "Shift" -> -0.01.

  3. If we take the issue discussed in the tutorial Ordering of Dependent Variable Names into account, the FEM solution will satisfy all the b.c.s, but still, the eigenvectors are rather inaccurate (incorrect?). The following is my failed trial:

    meshline = 
      NDSolve`FEM`ToElementMesh[ImplicitRegion[xL <= x <= xR, x], {{xL, xR}}, 
       IncludePoints -> {{0}}, MaxCellMeasure -> .02];
    bcL = DirichletCondition[#[x] == 0, x == xL] & /@ vars;
    Block[{u = 1/8},
      {val, vec} = 
       NDEigensystem[
        oper + bcL + {0, DirichletCondition[B1[x] == 0, x == xR], 0, 
                      DirichletCondition[B2[x] == 0, x == 0]} // Flatten,
        vars, {x} ∈ meshline, 6, Method -> {"Arnoldi", "Shift" -> -0.018}]];
    val
    

    Map[vec |-> {vec[[2]][xR], vec[[4]][0], vec[xL] // Through}]@vec (* Very close to 0. *)


Addendum: Mathematica Aided Deduction for the Symbolic Solution

The following is a deduction for the analytic solution shown by OP with the help of Mathematica. We first find the general solutions of the system:

eq = {-B1'[x] + u A1[x] == En A1[x],
   A1'[x] + u B1[x] + A2[x] == En B1[x],
   B2'[x] - u A2[x] + B1[x] == En A2[x],
   -A2'[x] - u B2[x] == En B2[x],
   -B'[x] + u A[x] == En A[x],
   A'[x] + u B[x] == En B[x]};

vars = {A1, B1, A2, B2, A, B};

sol = DSolve[eq, vars[x] // Through, x][[1]] // Expand // Collect[#, Exp[_]] &

By observing sol, we see A1, B1, A2, B2 are summation of _ Exp[Sqrt[_]] and _ Exp[-Sqrt[_]]. Since A1, B1, A2, B2 vanish at $-\infty$, and:

Reduce[ForAll[{a, b}, {a, b} ∈ Reals, Re@Sqrt[a + b I] >= 0]]
(* True *)

We know the coefficients of A1, B1, A2, B2 in form Exp[-_] should be zero:

term = Cases[sol[[;; 4]], a_ Exp[-_] :> a, Infinity] // Simplify // Union;

const = Cases[sol[[;; 4]], C[_], Infinity] // Union (* {C[1], C[2], C[3], C[4]} *)

rulec1 = Solve[term == 0, const] // Flatten;

constrest = Complement[Cases[sol, C[_], Infinity] // Union, rulec1[[All, 1]]] (* {C[1], C[2], C[5], C[6]} *)

Using the b.c. at $-\infty$, we manage to eliminate C[3] and C[4]. We continue to determine the rest 4 constants with the other 4 b.c.s:

{xL, xR} = {-20, 20};

bcsys = {A[x] == A1[x] /. sol /. x -> 0, B[x] == B1[x] /. sol /. x -> 0, B[x] == 0 /. sol /. x -> xR, B2[x] == 0 /. sol /. x -> 0} /. rulec1;

Reduce[bcsys, constrest] should work in principle, but it's too slow, so we still follow OP's method to find non-trivial solution:

det[u_, En_] = CoefficientArrays[bcsys, constrest] // Last // Det;

By observing

Plot[det[1/8, En] // Abs // Evaluate, {En, -1/2, 1/2}]

enter image description here

Or directly use RootSearch:

ruleEn = RootSearch[det[1/8, En] == 0, {En, -1/2, 1/2}]
(* {{En -> -0.120949}, {En -> -0.0184422}, {En -> 0.12101}} *)

We see there seem to be 3 possible En. Let's check the corresponding eigenvalues:

rulec2 = FindInstance[bcsys /. # /. u -> 1/8, constrest, 2][[1]] & /@ ruleEn

solfinal = MapThread[sol[[All, -1]] /. rulec1 /. # /. u -> 1/8 /. #2 &, {rulec2, ruleEn}];

MapThread[Plot[#^2 // Abs // Evaluate, {x, xL, 0}, PlotRange -> All]~Show~ Plot[#2^2 // Abs // Evaluate, {x, 0, xR}, PlotRange -> All] &, {solfinal[Transpose][[;; 4]][Transpose], solfinal[Transpose][[5 ;;]][Transpose]}]

enter image description here

Only eigenvectors of En -> -0.0184422 satisfy the b.c.s at $-\infty$, so it seems to be the only valid eigenvalue.

This deduction is fully applicable for $k\neq 0$ case. If you just need to solve the problem, perhaps it's better to forget about numeric approach and stay with symbolic approach.

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • 2
    Great! This is definitely the right direction. I can't thank you enough for all the work you do here for NDSolve and friends. Much appreciated! – user21 Jan 06 '23 at 08:43
  • @xzczd, that is AWESOME, however, I don't understand why you restricted (using If) A1, B1,A2 to be zero for x<0 in some terms and free in others. I would expect to restrict A2 and B2 in all terms including terms with derivatives, may you please see the update in the question? – MMA13 Jan 06 '23 at 20:19
  • @valarmorghulis It's because the 5th and 6th operator in your code are hv(-B'[x]-k B[x]) ,hv(A'[x]-k A[x]). (I noticed they seem to be different from those in the paper, but still followed yours. ) Did you mistype the operators? – xzczd Jan 07 '23 at 02:01
  • @xzczd, yes missed terms with U1, but now considering 4 coupled ode (first 4 Eqs in the question) should not affect the results. – MMA13 Jan 07 '23 at 17:33
  • @valarmorghulis So, you're not solving the system in the paper in update 2? – xzczd Jan 08 '23 at 03:08
  • @xzczd, No. I am still trying to solve those equations, I am not familiar of the correct way to restrict eigenfunction in the specific intervals so might do something wrong using If in update2. I will try to provide an exact solution in update 3 today and then see if NDEigensystem can give same solutions – MMA13 Jan 08 '23 at 06:44
  • 1
    @valarmorghulis Yes, you misunderstand the technique. For example, suppose we have x'[t] + 2 x[t] == 0 for x < 0 and x'[t] + 3 x[t] == 0 for x >= 0 and x[t] is continuous at x == 0, then the equations are combined to x'[t] + If[x < 0, 2, 3] x[t] == 0. – xzczd Jan 08 '23 at 07:41
  • @xzczd, I see, I provided an exact solution for k=0, kindly see update 3 – MMA13 Jan 12 '23 at 13:27
  • @xzczd, thanks for the detailed answer. I tried for $k\neq 0$ but it seems that there is a problem with Arnoldi method, did you try that? – MMA13 Jan 14 '23 at 20:54
  • 1
    @valarmorghulis I've tried k = .1 and find -0.0511553. For larger k we may need cleverer "Shift". However, since so many fake eigenvalues have involved in, I'd say my FDM method isn't suitable for practical use. – xzczd Jan 15 '23 at 02:33
4

Update: I have updated my package to be able to work on this system, fixing the bugs I noted in my previous answer.

I have a package for solving eigenvalue boundary value problems using the method of compound matrices, that is suitable here. I have answered a number of other questions on this site using it(e.g. interface eigenvalue BVP question) although I haven't been actively working in this area for several years so development has stopped. The package github holds the package, including a Mathematica notebook with a number of worked examples. This search contains all the answers I have made on this site.

First, we install the most recent v0.9.2 version of the package:

Needs["PacletManager`"]
PacletInstall["https://github.com/SPPearce/CompoundMatrixMethod/raw/master/\
CompoundMatrixMethod-0.92.paclet"]

We need to transform the equations into a matrix system of first order equations, including the boundary conditions, i.e. as:

\begin{align} \mathbf{A}_y(\lambda, x) \cdot \mathbf{y} &= \frac{d \mathbf{y}}{dx}, \quad x_1 \leq x \leq x_2 \\ \mathbf{A}_z(\lambda, x) \cdot \mathbf{z} &= \frac{d \mathbf{z}}{dx}, \quad x_2 \leq x \leq x_3 \\ \\ \mathbf{B} \cdot \mathbf{y}(x_1) &= \mathbf{0}, \\ \mathbf{F} \cdot \mathbf{y}(x_2) +\mathbf{G} \cdot\mathbf{z}(x_2) &= \mathbf{0}, \\ \mathbf{C} \cdot \mathbf{z}(x_3) &= \mathbf{0}. \\ \end{align}

for some matrices $\mathbf{A}_y, \mathbf{A}_z, \mathbf{B}, \mathbf{C}, \mathbf{F}, \mathbf{G}$, which may all involve the eigenvalue $\lambda$ (and $\mathbf{A}_y$ and $\mathbf{A}_z$ may be functions of $x$).

Fortunately, the package has a function to do that, ToMatrixSystem, so we can do that automatically.

So we can setup your (reduced) equations and apply them:

Needs["CompoundMatrixMethod`"]

eqnLeft = {-B1'[x] + u A1[x] == λ A1[x], A1'[x] + u B1[x] + A2[x] == λ B1[x], B2'[x] - u A2[x] + B1[x] == λ A2[x], -A2'[x] - u B2[x] == λ B2[x]}; eqnRight = {(-B'[x]) + u A[x] == λ A[x], A'[x] + u B[x] == λ B[x]}; BCsRight = {B[W] == 0}; BCsInterface = {A1[0] == A[0], B1[0] == B[0], B2[0] == 0};

We will discuss the left-hand BCs later.

Now we will basically integrate from both the left-hand side, $x=x_a$, and the right-hand side, $x=x_c$, and meet in the middle with the matching condition. However, this is easier to do numerically if we transform to a higher-order manifold, by introducing compound matrices. I'm not going to go into the details here, as the package takes care of that, but there is a helpful explanation by my former PhD supervisor.

We end up with what is known as the Evans function (denoted $E(\lambda)$, or miss-distance function, that basically describes how far off the matching at the middle we are.

The left-hand BCs here is that they decay to zero. Now we could choose a pair of the functions to set to zero here, or we can formally require decay conditions. As $x \to -\infty$, the system will behave as a constant $\mathbf{y}' = \mathbf{A}_{y\inf}(\lambda)$, and so has an exponential solution, $\mathbf{y} = \sum_i \exp(- \xi_i x) \mathbf{y}_i^{-\inf}$, where $\xi_i$ and $\mathbf{y}_i^{-\inf}$ are the matrix eigenvalues and eigenvectors respectively. For $y$ to decay therefore, we require that only the eigenvalues with negative real parts of this matrix remain, else we'll have exponentially growing terms. So the boundary condition here is the $\mathbf{B}$ is the concatenation of these two eigenvectors corresponding to eigenvalues with negative real parts.

My package will assume missing boundary conditions are of this form, so we just provide:

sys = ToMatrixSystem[{eqnLeft, eqnRight}, {BCsRight, 
  BCsInterface}, {{A1, B1, A2, B2}, {A, B}}, {x, -L, 0, W}, λ]

Which spits out this, containing the matrices required. Note the {}, which is the missing boundary conditions to be filled in later.

{{{{0, \[FormalLambda] - u, -1, 0}, {-\[FormalLambda] + u, 0, 0, 
    0}, {0, 0, 0, -\[FormalLambda] - u}, {0, -1, \[FormalLambda] + u, 
    0}}, {{0, \[FormalLambda] - u}, {-\[FormalLambda] + u, 
    0}}}, {}, {{0, 1}}, {{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}}, {{-1, 0}, {0, -1}, {0, 0}}}, {x, -L, 0, W}}

Here \[FormalLambda] is the eigenvalue in this system.

Now we can put this into the second function in the package, Evans, to calculate $E(\lambda)$ for a given possible eigenvalue $\lambda$.

So we can evaluate the system with $u = 1/8$, right hand boundary $x_3 = W = 20$ and apply the left-hand boundary condition at $x_1 = L = -20$, and give a possible eigenvalue of $\lambda = 0$:

 Evans[0, sys /. {W -> 20, L -> 20, u -> 1/8}]
 (* -3.97135 + 2.13421*10^-17 I *)

This value is not zero, so $\lambda = 0$ is not an eigenvalue. We can then use FindRoot,

FindRoot[Evans[λ, sys /. {W -> 20, L -> 20, u -> 1/8}], {λ, 0}]
(* {λ -> -0.0184414 - 5.66513*10^-17 I} *)

to recover the analytically found eigenvalue.

We can also plot this function, to see how it behaves, showing one eigenvalue here.

Plot[Evans[λ, sys /. {W -> 20, L -> 20, u -> 1/8}], {λ, -0.1, 0.1}]

enter image description here

Note that there will be (possibly large) regions of parameter space where we can't apply this function because the matrix eigenvalues are purely imaginary. This is not caught gracefully and will just give you an error I'm afraid. The first part of the system is the matrix $\mathbf{A}_y$:

sys[[1, 1]] // MatrixForm

enter image description here

and you can look at what points the eigenvalues of this matrix are not purely imaginary.

This method should also work for the $k \neq 0 $ case, but I haven't tried that yet.

xzczd
  • 65,995
  • 9
  • 163
  • 468
SPPearce
  • 5,653
  • 2
  • 18
  • 40
  • I guess there's a copy-paste error somewhere? I encounter the warning Evans::MatrixSizesDiffer – xzczd Jan 15 '23 at 02:29
  • Hmm, I'll take a look when I can. I don't get much time for this any more, was trying to get it finished quickly and didn't test it. I suspect that means I have been using a local modified version of the package that I've never actually pushed to GitHub, as I think I made those changes about a year ago. – SPPearce Jan 15 '23 at 06:51
  • @xzczd, I should have fixed that error last February, with my last package release: https://github.com/SPPearce/CompoundMatrixMethod/releases/tag/v0.91 . – SPPearce Jan 15 '23 at 09:09
  • 1
    @xzczd, I have updated to v0.9.2. I'm not sure how to do that on the PacletServer, but can be installed directly from github. – SPPearce Jan 15 '23 at 09:44