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.229093262112666, 22.636447500317416, 38.75912680520485, 56.95688372011057, 64.68904675672971, 71.61510645335656, 76.8931129333179, 86.36950975584612, 90.92730267537299, 99.90890224759515, 108.07709801120156, 123.53078334281284]
1 : [3.231012675428406, 6.086234263800532, 6.406899224200422, 12.054533474811405, 12.672421028605592, 13.138599687074086, 14.490032247704134, 17.72368170628437, 18.66258440079789, 19.346120603950364, 23.99916095992401, 25.451852239035606]
2 : [3.2203793481864684, 5.886623822610802, 5.905548429303577, 10.853747390871382, 10.901287970107356, 11.033338300475197, 12.490608609951474, 13.713193967978413, 14.184813087518613, 15.34867454609767, 16.529828076228434, 17.9645403490703]
3 : [3.2202534507267306, 5.880768708677752, 5.881908488028353, 10.709133420842589, 10.72605206597879, 10.7786562191536, 12.345960396970934, 12.760676043139696, 13.760281355705239, 14.018326043118917, 14.607718515535655, 16.592214150831083]
4 : [3.22025146690059, 5.8804942799820035, 5.880556917690781, 10.68989495348523, 10.698983267280992, 10.7182811055764, 12.323621310866091, 12.515134575113992, 13.530915636120254, 13.646352490747528, 14.013638403876286, 15.844042103153148]
5 : [3.220251432780628, 5.880477114537629, 5.880480023263939, 10.686851036556616, 10.694700891025185, 10.700890407067924, 12.319109793664907, 12.416240501317084, 13.409477889888997, 13.552567887294199, 13.749216311184243, 15.246452468325765]
6 : [3.220251432184983, 5.880473890511263, 5.880477843318856, 10.686161008731268, 10.694032876757907, 10.695820538594344, 12.318002400652931, 12.36510898710071, 13.375722155043391, 13.488497017464313, 13.613981824814893, 14.813746365507122]
7 : [3.220251432174621, 5.880473676484503, 5.880477751399414, 10.685969287196611, 10.693915072917058, 10.694415397845654, 12.317696219797647, 12.338610207939439, 13.365112608778471, 13.452949540264486, 13.531662728929733, 14.54811834619262]
8 : [3.2202514321744435, 5.88047366477277, 5.880477746015266, 10.685917731763464, 10.693892108137454, 10.694043457650965, 12.317604665085243, 12.326098068803695, 13.360878384960278, 13.435960447048359, 13.480566199527217, 14.398036525725638]
9 : [3.2202514321744404, 5.880473664135113, 5.880477745705932, 10.68590487291373, 10.693887275314294, 10.69394943386268, 12.317575537840934, 12.320797130575526, 13.358877986656719, 13.428258106355138, 13.451525421667025, 14.315735094792062]
10 : [3.220251432174443, 5.8804736641003315, 5.880477745688527, 10.685901792193377, 10.693886175010558, 10.69392645307133, 12.317565160998454, 12.318715753377427, 13.357892966668253, 13.424793976512916, 13.436298692693127, 14.270543537972623]
11 : [3.220251432174443, 5.880473664098435, 5.880477745687514, 10.68590106692484, 10.693885916583868, 10.693920952758882, 12.317558831673969, 12.31793983327054, 13.357414569539594, 13.423228035241932, 13.428747500407326, 14.245626471663062]
12 : [3.220251432174444, 5.880473664098306, 5.88047774568748, 10.685900897346315, 10.69388585684501, 10.693919648675578, 12.31754556285548, 12.317668126982683, 13.357188433434633, 13.422515876094783, 13.425120092591824, 14.231830188474667]
13 : [3.2202514321744418, 5.880473664098288, 5.880477745687481, 10.685900857786931, 10.69388584315197, 10.693919341036926, 12.317512862156315, 12.317598525896377, 13.357083763000876, 13.422189468369979, 13.4234109035885, 14.224178391648872]
14 : [3.2202514321744387, 5.880473664098315, 5.880477745687486, 10.685900848563472, 10.693885840012635, 10.69391926863258, 12.317488503458106, 12.317586425084794, 13.357035963130436, 13.422036754617027, 13.422616394950332, 14.21993055198016]
15 : [3.220251432174441, 5.880473664098316, 5.880477745687453, 10.685900846411323, 10.693885839291392, 10.693919251610174, 12.317478505463493, 12.317583476529226, 13.357014274005378, 13.421959834480084, 13.422254234008543, 14.217570686486146]
16 : [3.2202514321744418, 5.8804736640978295, 5.880477745687548, 10.6859008459088, 10.693885839125098, 10.693919247605992, 12.317474826356401, 12.317582558836357, 13.357004471011775, 13.421913934145, 13.422096891757766, 14.21625787037089]
17 : [3.2202514321744413, 5.880473664098442, 5.880477745687541, 10.685900845791178, 10.69388583908685, 10.693919246665233, 12.317473499740892, 12.317582246125129, 13.35700003660531, 13.42188344017796, 13.422031977715411, 14.215517996769114]
18 : [3.2202514321744453, 5.880473664098341, 5.880477745687439, 10.685900845763499, 10.693885839077778, 10.693919246445468, 12.317473039143078, 12.317582140102699, 13.356998039500063, 13.421865679851445, 13.422006917892267, 14.215114227719923]
19 : [3.2202514321744427, 5.88047366409839, 5.880477745687511, 10.685900845757372, 10.69388583907597, 10.693919246394266, 12.317472877630726, 12.3175821032565, 13.356997138102432, 13.421856541307946, 13.42199642715685, 14.214890987636206]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.2202514321744427
5.88047366409839
5.880477745687511
10.685900845757372
10.69388583907597
10.693919246394266
12.317472877630726
12.3175821032565
13.356997138102432
13.421856541307946
13.42199642715685
14.214890987636206
[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);
[ ]:

[ ]: