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.229093257240054, 22.636447446594005, 38.75912679717534, 56.956883688668356, 64.6890467876838, 71.61510639355707, 76.8931128585286, 86.36950975663099, 90.92730269300868, 99.90890225009714, 108.07709802210738, 123.53078333454542]
1 : [3.231012675400195, 6.086234262994243, 6.406899223763362, 12.054533475543039, 12.672421027953018, 13.138599692119831, 14.490032235698802, 17.723681706204605, 18.66258440293063, 19.3461206067476, 23.99916096330178, 25.45185223277921]
2 : [3.2203793481862006, 5.8866238225940695, 5.905548429270991, 10.853747390836952, 10.901287970194483, 11.033338300889385, 12.49060860934452, 13.713193970170613, 14.184813087529289, 15.348674543304446, 16.52982807488815, 17.96454035014859]
3 : [3.220253450726709, 5.880768708677136, 5.881908488026344, 10.709133420836157, 10.726052066002088, 10.778656219186441, 12.345960396902598, 12.760676043630449, 13.760281355594788, 14.018326042275802, 14.607718514652598, 16.592214152281702]
4 : [3.2202514669005766, 5.880494279981948, 5.88055691769064, 10.689894953486766, 10.698983267280196, 10.718281105575173, 12.323621310861952, 12.515134575262529, 13.53091563586576, 13.646352490935007, 14.013638403122972, 15.84404210470648]
5 : [3.2202514327806133, 5.880477114537592, 5.880480023263871, 10.686851036554293, 10.694700891024938, 10.70089040706773, 12.31910979366726, 12.416240501389783, 13.409477889829029, 13.552567887403512, 13.749216310712232, 15.246452469737552]
6 : [3.2202514321849693, 5.880473890511233, 5.880477843318814, 10.686161008729588, 10.694032876757857, 10.6958205385948, 12.318002400654507, 12.365108987141495, 13.375722155015191, 13.488497017517235, 13.613981824586443, 14.81374636651725]
7 : [3.2202514321746043, 5.880473676484453, 5.880477751399362, 10.685969287195968, 10.693915072917, 10.694415397845862, 12.317696219798266, 12.338610207960615, 13.365112608760562, 13.452949540288799, 13.531662728838993, 14.54811834680773]
8 : [3.2202514321744258, 5.880473664772738, 5.880477746015222, 10.685917731763235, 10.693892108137398, 10.694043457650993, 12.31760466508537, 12.326098068805639, 13.360878384948878, 13.435960447040832, 13.480566199332392, 14.398036525894716]
9 : [3.220251432174424, 5.88047366413506, 5.880477745705902, 10.685904872914431, 10.693887275313662, 10.693949433864521, 12.317575537838925, 12.320797130865419, 13.358877986636315, 13.42825810467253, 13.451525420186265, 14.315735103719403]
10 : [3.220251432174422, 5.880473664100279, 5.880477745688458, 10.685901792193642, 10.693886175010231, 10.69392645307238, 12.31756516099845, 12.31871575389904, 13.357892966455914, 13.424793976723775, 13.436298700492783, 14.270543553693981]
11 : [3.2202514321744236, 5.880473664098356, 5.880477745687482, 10.68590106692462, 10.693885916583556, 10.693920952758731, 12.317558831672576, 12.317939833508754, 13.357414569273889, 13.423228035707158, 13.428747504236501, 14.245626473650413]
12 : [3.2202514321744276, 5.880473664098264, 5.880477745687424, 10.685900897346045, 10.693885856844792, 10.693919648675514, 12.317545562855361, 12.317668127070762, 13.357188433421994, 13.422515877777027, 13.425120094960919, 14.231830176502118]
13 : [3.2202514321744236, 5.880473664098304, 5.880477745687419, 10.685900857789079, 10.693885843151884, 10.693919341041802, 12.317512862219075, 12.31759852539478, 13.35708376992787, 13.422189456685162, 13.423410803323156, 14.224178615735154]
14 : [3.220251432174423, 5.880473664098273, 5.880477745687456, 10.68590084856384, 10.693885840013117, 10.69391926863342, 12.317488501879586, 12.31758642435943, 13.357035966894982, 13.422036751923445, 13.422616173531202, 14.219930164410739]
15 : [3.220251432174425, 5.880473664098298, 5.880477745687412, 10.68590084641135, 10.693885839291324, 10.693919251610586, 12.317478505652895, 12.317583476601117, 13.35701427878929, 13.4219598418137, 13.422254200077537, 14.21757066972156]
16 : [3.220251432174425, 5.880473664098242, 5.880477745687402, 10.685900845908215, 10.693885839124974, 10.693919247607651, 12.31747483095999, 12.317582560449388, 13.35700445095819, 13.421913904166605, 13.422096988361883, 14.21625758615923]
17 : [3.2202514321744284, 5.880473664098214, 5.880477745687496, 10.685900845790753, 10.693885839086615, 10.693919246664935, 12.31747351227874, 12.317582249967362, 13.357000003566196, 13.421883629100881, 13.422033353669608, 14.21552599975077]
18 : [3.2202514321744253, 5.880473664098302, 5.880477745687426, 10.685900845763449, 10.69388583907783, 10.693919246443999, 12.317473041353754, 12.317582141190162, 13.356998000765344, 13.421865669688005, 13.422007632007817, 14.215114928523475]
19 : [3.220251432174425, 5.880473664098252, 5.8804777456874895, 10.685900845757015, 10.69388583907548, 10.693919246392602, 12.31747287413226, 12.3175821026692, 13.356997106420913, 13.42185630608878, 13.421996748209356, 14.214884101272148]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.220251432174425
5.880473664098252
5.8804777456874895
10.685900845757015
10.69388583907548
10.693919246392602
12.31747287413226
12.3175821026692
13.356997106420913
13.42185630608878
13.421996748209356
14.214884101272148
[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);
[ ]:

[ ]: