ptoafunc = pdetoae[Flatten[{e /@ {1, 2}, term, termx, termy}][x, y], {grid, grid},
difforder];
del = #[[2 ;; -2]] &;
ae = del /@ del@# & /@ ptoafunc@lhs; // AbsoluteTiming
(* {26.967, Null} *)
{aetermrhs, aetermxrhs, aetermyrhs} =
ptoafunc@{termrhs, termxrhs, termyrhs}; // AbsoluteTiming
(* {24.0939, Null} *)
vare = Outer[e[#][#2, #3] &, Range@2, del@grid, del@grid, 1] // Flatten;
Block[{e, term, termx, termy},
e[1 | 2][L | -L, y_] = e[1 | 2][x_, L | -L] = 0.;
Evaluate@ptoafunc@Through[{term, termx, termy}[x, y]] = {aetermrhs, aetermxrhs,
aetermyrhs};
{barray, marray} = CoefficientArrays[ae // Flatten, vare]; // AbsoluteTiming]
(* {58.6109, Null} *)
{val, vec} =
Eigensystem[marray, -6, Method -> {"Arnoldi", "Shift" -> k^2 glass}]; // AbsoluteTiming
(* {23.9645, Null}, in a 8-core machine. *)
mat = ArrayReshape[#, {2, points - 2, points - 2}] & /@ vec;
Parallelize@
MapThread[ArrayPlot[#[[1]], PlotLabel -> Sqrt@#2, PlotRange -> All,
ColorFunction -> "AvocadoColors"] &, {mat, val}]
NDEigenSystem
won't work without the replacement{e[1] -> e1, e[2] -> e2}
. (e[1]
ande[2]
causes the warningNDEigensystem::baddep
.) I'm not sure about the reason."FEAST"
method can't be used, otherwise the warningEigensystem::nosymh
pops up. I'm not sure about the reason.The utilization of Gauss's law in the deduction of $(10)$ seems to be critical. Actually one can still eliminate $E_z$ with $(1)$ and $(2)$ only, but the deduced equation just can't converge to the desired result. I guess this might be related to the observation that numeric algorithm that doesn't obey Gauss's law can be inaccurate. (Check Introduction section of this paper for more information. )
If you insists on solving the problem with Helmholtz equation with interface condition, notice the interface conditions in the question aren't sufficient. One still needs another 3 conditions for $\mathbf{H}$ i.e. the tangential component of $\mathbf{H}$ is continuous across the surface if there's no surface current present.
Dirichlet b.c.s are essentially set by
del@grid
invare
. Since the elements at the boundary of domain aren't included invare
, they will be treated as constant and moved tobarray
byCoefficientArray
, which is equivalent to setting zero Dirichlet b.c.s.