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.2290932602333315, 22.636447512123226, 38.759126807710636, 56.956883728289036, 64.68904672588612, 71.61510644811534, 76.89311290232068, 86.3695097532837, 90.92730267330046, 99.90890224332236, 108.07709801821547, 123.53078333764707]
1 : [3.2310126754092283, 6.08623426388468, 6.406899223813614, 12.054533471283843, 12.672421028954094, 13.138599687267927, 14.490032244221805, 17.72368170600348, 18.662584394015806, 19.346120605764256, 23.99916096366218, 25.451852237701047]
2 : [3.220379348186258, 5.8866238226067225, 5.905548429291282, 10.853747390664076, 10.901287969709728, 11.033338300522251, 12.490608609706062, 13.71319396729708, 14.18481308737406, 15.34867454741089, 16.529828080908704, 17.964540348776826]
3 : [3.2202534507267315, 5.8807687086775395, 5.881908488028291, 10.709133420823484, 10.726052065941582, 10.778656219104427, 12.345960396935185, 12.760676043217359, 13.760281355703079, 14.018326044592106, 14.60771851579109, 16.592214150400267]
4 : [3.2202514669005917, 5.880494279982021, 5.880556917690795, 10.68989495348025, 10.698983267280818, 10.718281105548025, 12.323621310858606, 12.515134575189137, 13.53091563658338, 13.646352490494836, 14.013638403935355, 15.844042102996188]
5 : [3.220251432780626, 5.880477114537661, 5.880480023263946, 10.686851036555497, 10.694700891025342, 10.70089040705741, 12.319109793663106, 12.416240501351165, 13.40947789001302, 13.552567887089696, 13.749216311269976, 15.246452468320602]
6 : [3.220251432184984, 5.880473890511274, 5.880477843318877, 10.68616100873089, 10.694032876757918, 10.695820538591203, 12.318002400652546, 12.365108987115784, 13.375722155093289, 13.48849701733413, 13.613981824879511, 14.81374636553199]
7 : [3.220251432174622, 5.880473676484479, 5.880477751399416, 10.685969287196517, 10.693915072917056, 10.694415397844773, 12.31769621979757, 12.338610207945882, 13.365112608807053, 13.452949540191693, 13.53166272896364, 14.54811834621309]
8 : [3.2202514321744418, 5.88047366477276, 5.880477746015271, 10.68591773176344, 10.69389210813748, 10.694043457650741, 12.31760466508522, 12.32609806880165, 13.360878384976562, 13.435960446999136, 13.48056619944162, 14.398036525623263]
9 : [3.2202514321744378, 5.880473664135112, 5.880477745705938, 10.685904872914767, 10.693887275314527, 10.693949433864296, 12.317575537839517, 12.32079713116795, 13.358877986659726, 13.428258105391231, 13.451525427909278, 14.315735113156707]
10 : [3.220251432174437, 5.880473664100343, 5.880477745688505, 10.685901792193842, 10.693886175010542, 10.693926453072347, 12.31756516099852, 12.318715754587778, 13.357892966543233, 13.424793977224839, 13.436298713499664, 14.27054357678877]
11 : [3.2202514321744404, 5.8804736640984, 5.880477745687526, 10.685901066925206, 10.69388591658392, 10.693920952759301, 12.317558831681616, 12.317939833999995, 13.357414569477543, 13.423228035975795, 13.428747518722913, 14.245626510767412]
12 : [3.22025143217444, 5.880473664098327, 5.880477745687467, 10.685900897346604, 10.693885856844751, 10.693919648675209, 12.317545562925456, 12.317668127468949, 13.35718843319737, 13.42251587487904, 13.425120114686063, 14.231830250967965]
13 : [3.2202514321744404, 5.880473664098323, 5.880477745687495, 10.68590085778921, 10.693885843152513, 10.693919341038777, 12.317512864221905, 12.317598527044971, 13.357083763365166, 13.422189438428084, 13.423411019753791, 14.224179109878907]
14 : [3.2202514321744373, 5.880473664098291, 5.880477745687466, 10.685900848564227, 10.693885840014037, 10.693919268634195, 12.31748850419704, 12.317586425145898, 13.357035963567812, 13.422036745315614, 13.422616464734123, 14.219931071823897]
15 : [3.220251432174441, 5.8804736640982975, 5.880477745687463, 10.685900846410993, 10.69388583929186, 10.693919251608538, 12.317478504604377, 12.317583476370107, 13.357014260555424, 13.421959810048149, 13.422254252921322, 14.2175703294707]
16 : [3.220251432174443, 5.880473664098392, 5.880477745687464, 10.685900845908003, 10.6938858391253, 10.693919247604853, 12.317474827002776, 12.317582559487056, 13.357004449865242, 13.421913848646799, 13.422096889207175, 14.216256278818141]
17 : [3.220251432174443, 5.880473664098198, 5.880477745687497, 10.685900845791014, 10.69388583908621, 10.693919246657519, 12.31747347673242, 12.31758223894132, 13.3570000309339, 13.421883222427017, 13.422031836091888, 14.215511372850838]
18 : [3.2202514321744404, 5.880473664098296, 5.880477745687437, 10.685900845763548, 10.69388583907774, 10.693919246441526, 12.317473023852786, 12.317582135766285, 13.356998015105805, 13.421865329305724, 13.422006746483751, 14.215104178130739]
19 : [3.2202514321744418, 5.880473664098072, 5.880477745687294, 10.685900845757299, 10.693885839075847, 10.69391924639262, 12.317472870022552, 12.317582101190279, 13.356997118172083, 13.421856290055223, 13.42199640862547, 14.214882702252257]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.2202514321744418
5.880473664098072
5.880477745687294
10.685900845757299
10.693885839075847
10.69391924639262
12.317472870022552
12.317582101190279
13.356997118172083
13.421856290055223
13.42199640862547
14.214882702252257
[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);
[ ]:
[ ]: