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.229093261611238, 22.636447496121434, 38.75912681538943, 56.956883728347044, 64.68904674381324, 71.61510644720279, 76.89311295008659, 86.36950976666394, 90.92730267714961, 99.90890224372218, 108.07709802321993, 123.53078334025317]
1 : [3.231012675417083, 6.086234263787284, 6.406899224410408, 12.054533474328005, 12.67242102953422, 13.138599690102343, 14.49003224720416, 17.723681706745722, 18.66258439390677, 19.346120603698047, 23.999160962155738, 25.451852236784347]
2 : [3.2203793481863516, 5.886623822608661, 5.90554842931095, 10.853747390853778, 10.901287970220187, 11.033338300647891, 12.490608609878294, 13.713193965755611, 14.184813087521645, 15.348674545433141, 16.52982807518986, 17.964540348865786]
3 : [3.220253450726715, 5.88076870867751, 5.881908488028645, 10.709133420844383, 10.72605206601623, 10.778656219060572, 12.345960396948074, 12.760676042526043, 13.760281355682089, 14.018326042481672, 14.607718515628456, 16.592214151042477]
4 : [3.220251466900576, 5.8804942799819715, 5.8805569176907655, 10.689894953489736, 10.698983267284763, 10.71828110552897, 12.323621310859295, 12.515134574868, 13.530915635950794, 13.646352490652754, 14.013638403974527, 15.844042103777968]
5 : [3.2202514327806138, 5.880477114537596, 5.880480023263861, 10.686851036557375, 10.694700891025205, 10.70089040705158, 12.319109793662657, 12.416240501206778, 13.409477889826315, 13.55256788724016, 13.74921631129047, 15.246452469063271]
6 : [3.220251432184964, 5.880473890511234, 5.880477843318818, 10.686161008731052, 10.694032876757786, 10.695820538589642, 12.318002400652109, 12.365108987056365, 13.37572215502216, 13.488497017431733, 13.61398182492365, 14.813746366078343]
7 : [3.2202514321746083, 5.880473676484457, 5.880477751399362, 10.685969287196436, 10.693915072916983, 10.694415397844367, 12.317696219797332, 12.338610207923738, 13.365112608771653, 13.4529495402467, 13.53166272902294, 14.54811834655691]
8 : [3.2202514321744284, 5.88047366477275, 5.88047774601524, 10.68591773176336, 10.69389210813741, 10.694043457650608, 12.31760466508506, 12.326098068794495, 13.360878384957685, 13.435960447037207, 13.48056619951116, 14.398036525816172]
9 : [3.220251432174421, 5.880473664135073, 5.880477745705905, 10.685904872914168, 10.693887275313799, 10.693949433863438, 12.317575537839542, 12.320797130581862, 13.358877986630684, 13.42825810492559, 13.451525416528073, 14.315735097654619]
10 : [3.2202514321744276, 5.880473664100265, 5.8804777456884585, 10.685901792193771, 10.693886175010416, 10.693926453071805, 12.317565160998301, 12.318715754844115, 13.357892966743213, 13.424793975687535, 13.436298717329645, 14.270543593448878]
11 : [3.2202514321744244, 5.880473664098388, 5.880477745687499, 10.685901066924806, 10.693885916583836, 10.693920952758258, 12.317558831679428, 12.317939834125124, 13.357414569502067, 13.423228034737804, 13.428747523438446, 14.245626521103384]
12 : [3.220251432174426, 5.880473664098262, 5.880477745687447, 10.685900897346373, 10.693885856844602, 10.693919648674838, 12.317545562920353, 12.317668127465188, 13.357188433253613, 13.422515874032028, 13.425120111342315, 14.231830243655958]
13 : [3.2202514321744258, 5.880473664098265, 5.880477745687423, 10.68590085778804, 10.693885843152348, 10.693919341038324, 12.31751286300982, 12.317598526398651, 13.35708376511034, 13.422189466980427, 13.423410978247496, 14.224178695471467]
14 : [3.2202514321744222, 5.880473664098272, 5.8804777456874335, 10.685900848563541, 10.69388584001427, 10.693919268633248, 12.317488502090622, 12.317586424576966, 13.357035964030345, 13.422036764684064, 13.422616394706996, 14.219930331092135]
15 : [3.220251432174428, 5.880473664098275, 5.8804777456872594, 10.685900846411178, 10.69388583929202, 10.69391925161012, 12.31747850448519, 12.317583476331704, 13.357014273171275, 13.421959834929291, 13.422254261155551, 14.217570280322672]
16 : [3.220251432174426, 5.880473664098162, 5.880477745687533, 10.685900845908511, 10.693885839123107, 10.693919247591827, 12.31747479128061, 12.317582547818194, 13.357004461238002, 13.421913785292546, 13.422096152576579, 14.21625046791623]
17 : [3.2202514321744244, 5.880473664098357, 5.880477745687559, 10.685900845790817, 10.693885839085809, 10.693919246661352, 12.31747349405566, 12.317582243623168, 13.356999988099567, 13.421883561051162, 13.422032808455933, 14.215522654245527]
18 : [3.2202514321744244, 5.88047366409803, 5.880477745687369, 10.685900845763717, 10.693885839077335, 10.693919246443448, 12.31747303288855, 12.317582137929772, 13.356998016882862, 13.421865733061702, 13.422007184426702, 14.215115242924718]
19 : [3.2202514321744244, 5.880473664098166, 5.880477745687382, 10.68590084575723, 10.693885839075897, 10.693919246392753, 12.317472873154571, 12.317582101962941, 13.356997112558503, 13.421856515806684, 13.42199656640223, 14.214889496145787]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.2202514321744244
5.880473664098166
5.880477745687382
10.68590084575723
10.693885839075897
10.693919246392753
12.317472873154571
12.317582101962941
13.356997112558503
13.421856515806684
13.42199656640223
14.214889496145787
[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);
[ ]:

[ ]: