This page was generated from unit-2.4-Maxwell/Maxwellevp.ipynb.

2.4.1 Maxwell eigenvalue problem

We solve the Maxwell eigenvalue problem

\[\int \operatorname{curl} u \, \operatorname{curl} v = \lambda \int u v\]

for \(u, v \; \bot \; \nabla H^1\) using a PINVIT solver from the ngsolve solvers module.

The orthogonality to gradient fields is important to eliminate the huge number of zero eigenvalues. The orthogonal sub-space is implemented using a Poisson projection:

\[P u = u - \nabla \Delta^{-1} \operatorname{div} u\]

The algorithm and example is take form the Phd thesis of Sabine Zaglmayr, p 145-150.

[1]:
from ngsolve import *
from ngsolve.webgui import Draw
from netgen.occ import *
[2]:
from netgen.occ import *

cube1 = Box( (-1,-1,-1), (1,1,1) )

cube2 = Box( (0,0,0), (2,2,2) )
cube2.edges.hpref=1    # mark edges for geometric refinement

fichera = cube1-cube2

Draw (fichera);
[3]:
mesh = Mesh(OCCGeometry(fichera).GenerateMesh(maxh=0.4))
mesh.RefineHP(levels=2, factor=0.2)
Draw (mesh);
[4]:
# SetHeapSize(100*1000*1000)

fes = HCurl(mesh, order=3)
print ("ndof =", fes.ndof)
u,v = fes.TnT()

a = BilinearForm(curl(u)*curl(v)*dx)
m = BilinearForm(u*v*dx)

apre = BilinearForm(curl(u)*curl(v)*dx + u*v*dx)
pre = Preconditioner(apre, "direct", inverse="sparsecholesky")
ndof = 42562
[5]:
with TaskManager():
    a.Assemble()
    m.Assemble()
    apre.Assemble()

    # build gradient matrix as sparse matrix (and corresponding scalar FESpace)
    gradmat, fesh1 = fes.CreateGradient()


    gradmattrans = gradmat.CreateTranspose() # transpose sparse matrix
    math1 = gradmattrans @ m.mat @ gradmat   # multiply matrices
    math1[0,0] += 1     # fix the 1-dim kernel
    invh1 = math1.Inverse(inverse="sparsecholesky")

    # build the Poisson projector with operator Algebra:
    proj = IdentityMatrix() - gradmat @ invh1 @ gradmattrans @ m.mat

    projpre = proj @ pre.mat

    evals, evecs = solvers.PINVIT(a.mat, m.mat, pre=projpre, num=12, maxit=20)
0 : [6.229093256122031, 22.636447446296273, 38.7591267936905, 56.95688369056704, 64.68904679977769, 71.61510640397475, 76.89311283126929, 86.36950974686674, 90.92730269194278, 99.90890225134714, 108.07709800547904, 123.53078333440769]
1 : [3.2310126753945707, 6.0862342631369, 6.406899223373303, 12.05453347571023, 12.672421026970577, 13.138599690179829, 14.490032236539173, 17.723681707090943, 18.662584404812655, 19.346120606375035, 23.999160965228988, 25.451852232751268]
2 : [3.220379348186087, 5.886623822598941, 5.905548429252594, 10.853747390802571, 10.901287970116444, 11.033338300944209, 12.490608609491442, 13.713193970846593, 14.184813087459464, 15.34867454326883, 16.52982807593051, 17.964540349537767]
3 : [3.220253450726712, 5.880768708677337, 5.881908488025484, 10.709133420824614, 10.726052065995969, 10.77865621927424, 12.345960396922727, 12.76067604393403, 13.760281355529658, 14.018326042319698, 14.607718514240982, 16.59221415288701]
4 : [3.2202514669005766, 5.880494279981942, 5.880556917690577, 10.689894953487274, 10.6989832672784, 10.718281105615402, 12.323621310865866, 12.515134575397116, 13.530915635891665, 13.646352490891633, 14.013638402798792, 15.844042105652557]
5 : [3.2202514327806124, 5.880477114537593, 5.880480023263883, 10.686851036555726, 10.694700891024784, 10.700890407082506, 12.319109793668138, 12.416240501456537, 13.40947788984508, 13.552567887390609, 13.749216310509187, 15.246452470678323]
6 : [3.220251432184967, 5.880473890511238, 5.880477843318812, 10.686161008730531, 10.694032876757865, 10.695820538599452, 12.318002400654665, 12.365108987177056, 13.37572215502281, 13.48849701751555, 13.613981824483783, 14.813746367232458]
7 : [3.2202514321746043, 5.880473676484461, 5.880477751399351, 10.68596928719631, 10.69391507291701, 10.694415397847157, 12.317696219798295, 12.338610207978652, 13.365112608763148, 13.45294954028792, 13.531662728805847, 14.548118347278935]
8 : [3.2202514321744293, 5.880473664772725, 5.880477746015236, 10.685917731763311, 10.693892108137423, 10.694043457651341, 12.317604665085373, 12.326098068814051, 13.360878384949636, 13.435960447046519, 13.480566199327978, 14.398036526158597]
9 : [3.220251432174422, 5.880473664135083, 5.880477745705901, 10.685904872913573, 10.693887275313077, 10.69394943386272, 12.317575537840346, 12.320797130098217, 13.358877986656147, 13.428258105124867, 13.451525407232161, 14.315735078658477]
10 : [3.2202514321744236, 5.8804736641002835, 5.880477745688451, 10.685901792193407, 10.693886175009887, 10.693926453071294, 12.317565160998383, 12.318715754079122, 13.357892966706684, 13.424793975316563, 13.436298695985274, 14.270543553717042]
11 : [3.220251432174425, 5.880473664098375, 5.880477745687483, 10.685901066924707, 10.693885916583458, 10.69392095275861, 12.317558831676166, 12.317939833792149, 13.357414569434026, 13.423228034349995, 13.428747505688122, 14.245626488280083]
12 : [3.220251432174427, 5.8804736640982735, 5.880477745687431, 10.685900897346173, 10.693885856844721, 10.693919648675422, 12.317545562885842, 12.317668127249519, 13.357188433431682, 13.422515876270777, 13.425120098452336, 14.231830199109963]
13 : [3.220251432174426, 5.880473664098219, 5.880477745687405, 10.685900857787143, 10.693885843152524, 10.693919341032812, 12.317512860800802, 12.317598524786996, 13.357083766650833, 13.422189465863747, 13.42341088283096, 14.224178224319383]
14 : [3.220251432174424, 5.880473664098289, 5.880477745687432, 10.685900848563563, 10.69388584001407, 10.693919268631058, 12.317488501881714, 12.317586424424299, 13.35703596203284, 13.42203673999016, 13.422616362282698, 14.219930399008469]
15 : [3.2202514321744236, 5.880473664098247, 5.880477745687506, 10.68590084641126, 10.693885839292188, 10.69391925160876, 12.317478503332628, 12.317583475805254, 13.357014274729615, 13.42195982345622, 13.422254272303695, 14.217570587990727]
16 : [3.220251432174425, 5.880473664098482, 5.880477745687452, 10.685900845908282, 10.693885839124457, 10.693919247598428, 12.317474813960166, 12.317582555333718, 13.357004468329588, 13.421913812170336, 13.422096775780641, 14.216254588222508]
17 : [3.220251432174424, 5.880473664098259, 5.880477745687346, 10.685900845789426, 10.693885839086288, 10.693919246649214, 12.317473442575793, 12.317582231743886, 13.356999980730741, 13.421881800635726, 13.422028287150251, 14.215470491896982]
18 : [3.220251432174426, 5.880473664098206, 5.880477745687381, 10.685900845763017, 10.693885839077609, 10.693919246439613, 12.317473003968738, 12.317582131141247, 13.356998000686934, 13.421863966838444, 13.422004141197526, 14.215067552510423]
19 : [3.220251432174424, 5.880473664098116, 5.880477745687431, 10.685900845757438, 10.693885839075747, 10.693919246392312, 12.31747286067853, 12.317582098921042, 13.356997114891332, 13.421855343423463, 13.421994819536888, 14.214855246970657]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.220251432174424
5.880473664098116
5.880477745687431
10.685900845757438
10.693885839075747
10.693919246392312
12.31747286067853
12.317582098921042
13.356997114891332
13.421855343423463
13.421994819536888
14.214855246970657
[7]:
gfu = GridFunction(fes, multidim=len(evecs))
for i in range(len(evecs)):
    gfu.vecs[i].data = evecs[i]
Draw (Norm(gfu), mesh, order=4, min=0, max=2);
[ ]:

[ ]: