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.22909326069923, 22.636447489760755, 38.75912680418406, 56.9568837192993, 64.68904674614271, 71.61510643284898, 76.89311293920251, 86.36950976061969, 90.92730267795874, 99.90890224817761, 108.07709800987092, 123.53078333859703]
1 : [3.2310126754105166, 6.086234263776423, 6.406899223892952, 12.054533474342726, 12.672421028972943, 13.138599690187588, 14.490032246047836, 17.7236817064458, 18.66258439414756, 19.346120606298516, 23.999160958652034, 25.45185223726281]
2 : [3.2203793481862704, 5.886623822610666, 5.9055484292865685, 10.853747390876404, 10.901287970063754, 11.033338300835181, 12.490608609824058, 13.71319396611787, 14.184813087230358, 15.34867454794979, 16.529828075345684, 17.964540349340776]
3 : [3.2202534507267297, 5.880768708677681, 5.881908488027652, 10.709133420834183, 10.726052066008636, 10.778656219163302, 12.345960396950604, 12.760676042609463, 13.760281355583043, 14.01832604368615, 14.60771851523424, 16.592214151767035]
4 : [3.2202514669005935, 5.880494279982, 5.880556917690743, 10.689894953485744, 10.698983267287039, 10.71828110556583, 12.323621310863793, 12.51513457489269, 13.53091563627879, 13.646352490549113, 14.013638403849452, 15.844042104538127]
5 : [3.220251432780627, 5.880477114537636, 5.8804800232639085, 10.686851036556778, 10.694700891026228, 10.70089040706313, 12.319109793665271, 12.416240501214379, 13.40947788993817, 13.552567887193053, 13.749216311167395, 15.246452469739102]
6 : [3.2202514321849844, 5.880473890511298, 5.880477843318855, 10.686161008731188, 10.694032876758126, 10.695820538592976, 12.318002400653313, 12.365108987060049, 13.375722155070747, 13.488497017415721, 13.613981824820254, 14.813746366585546]
7 : [3.2202514321746207, 5.880473676484458, 5.8804777513994075, 10.685969287196585, 10.693915072917095, 10.694415397845312, 12.317696219797831, 12.338610207926182, 13.365112608796604, 13.45294954023842, 13.531662728959747, 14.548118346881905]
8 : [3.2202514321744427, 5.88047366477277, 5.880477746015271, 10.685917731763436, 10.693892108137478, 10.694043457650883, 12.317604665085295, 12.326098068793137, 13.360878384971787, 13.435960447004875, 13.480566199369585, 14.3980365259702]
9 : [3.2202514321744395, 5.880473664135095, 5.880477745705943, 10.685904872914513, 10.69388727531332, 10.693949433864379, 12.317575537837705, 12.320797130249415, 13.3588779866172, 13.428258103435214, 13.451525406591296, 14.315735089585818]
10 : [3.2202514321744435, 5.880473664100305, 5.880477745688494, 10.68590179219377, 10.693886175010084, 10.693926453072349, 12.317565160998493, 12.31871575370582, 13.357892966584131, 13.424793974842835, 13.436298689701035, 14.27054354827931]
11 : [3.220251432174441, 5.880473664098422, 5.880477745687525, 10.685901066925126, 10.693885916583747, 10.693920952759203, 12.317558831680367, 12.317939833505886, 13.357414569455118, 13.423228034261632, 13.42874750092132, 14.245626484913744]
12 : [3.2202514321744404, 5.880473664098327, 5.880477745687477, 10.685900897346448, 10.693885856844608, 10.693919648675367, 12.317545562893851, 12.317668127222957, 13.357188433407625, 13.422515875279663, 13.425120101001527, 14.23183021684512]
13 : [3.220251432174442, 5.880473664098294, 5.8804777456874655, 10.685900857786084, 10.69388584315275, 10.69391934102006, 12.31751285588362, 12.317598521217926, 13.357083762414339, 13.422189465042688, 13.42341074189187, 14.224177480084236]
14 : [3.2202514321744404, 5.880473664098298, 5.880477745687468, 10.685900848563183, 10.693885840014566, 10.693919268626138, 12.31748849920167, 12.317586423697684, 13.357035961149599, 13.422036752531572, 13.422616457630047, 14.219929997587187]
15 : [3.220251432174441, 5.8804736640983375, 5.8804777456875446, 10.685900846411133, 10.693885839292149, 10.693919251607253, 12.31747850330187, 12.31758347601259, 13.357014274021022, 13.421959813103138, 13.422254341177085, 14.217570329063356]
16 : [3.2202514321744404, 5.880473664098469, 5.880477745687468, 10.685900845908325, 10.693885839125464, 10.6939192476052, 12.317474827399222, 12.317582559526683, 13.35700445722982, 13.421913874947526, 13.422096984373098, 14.216256971969925]
17 : [3.220251432174442, 5.880473664098292, 5.880477745687537, 10.685900845791048, 10.693885839086862, 10.693919246666, 12.31747351234815, 12.317582249766646, 13.357000027383195, 13.421883713692369, 13.42203332657464, 14.215527482870657]
18 : [3.2202514321744378, 5.880473664098306, 5.880477745687475, 10.68590084576372, 10.69388583907794, 10.69391924644574, 12.317473045654573, 12.31758214196429, 13.35699803012541, 13.421865972353192, 13.42200771776815, 14.215122244245029]
19 : [3.2202514321744404, 5.8804736640985125, 5.880477745687537, 10.685900845757349, 10.693885839076145, 10.693919246394312, 12.31747288053068, 12.317582104084265, 13.356997130204903, 13.421856750197568, 13.42199692271845, 14.214896815541668]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.2202514321744404
5.8804736640985125
5.880477745687537
10.685900845757349
10.693885839076145
10.693919246394312
12.31747288053068
12.317582104084265
13.356997130204903
13.421856750197568
13.42199692271845
14.214896815541668
[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);
[ ]:
[ ]: