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.2290932539690225, 22.636447457505973, 38.759126795374456, 56.95688366483574, 64.6890467683866, 71.61510642359713, 76.89311281951635, 86.3695097466862, 90.92730268803301, 99.90890224549739, 108.07709801363241, 123.53078332812176]
1 : [3.231012675384601, 6.086234263026512, 6.406899223410982, 12.0545334729039, 12.672421026989607, 13.138599688935702, 14.490032234540545, 17.723681704259583, 18.662584402089188, 19.34612060907546, 23.999160968931776, 25.45185223215351]
2 : [3.220379348186014, 5.886623822589721, 5.905548429263989, 10.85374739076248, 10.901287969891627, 11.033338300557684, 12.490608609196492, 13.713193970719944, 14.18481308752122, 15.348674544133393, 16.529828079980764, 17.96454035097108]
3 : [3.220253450726709, 5.88076870867703, 5.881908488026542, 10.709133420830522, 10.72605206596339, 10.77865621917236, 12.345960396876537, 12.760676043897174, 13.760281355680997, 14.01832604347155, 14.607718515175279, 16.592214153188657]
4 : [3.2202514669005753, 5.880494279981931, 5.8805569176906864, 10.689894953480666, 10.69898326727906, 10.718281105583115, 12.323621310853364, 12.515134575351315, 13.530915636163128, 13.646352491068962, 14.013638403151154, 15.844042105770638]
5 : [3.2202514327806164, 5.880477114537607, 5.880480023263883, 10.686851036552373, 10.694700891025198, 10.700890407072876, 12.31910979366403, 12.416240501426078, 13.409477889895417, 13.552567887503274, 13.749216310687153, 15.246452470722193]
6 : [3.220251432184967, 5.8804738905112455, 5.880477843318825, 10.686161008729181, 10.69403287675792, 10.695820538596895, 12.318002400653352, 12.365108987162047, 13.375722155025068, 13.488497017577663, 13.613981824592093, 14.813746367224187]
7 : [3.220251432174602, 5.880473676484463, 5.880477751399364, 10.685969287195887, 10.693915072917024, 10.694415397846502, 12.317696219797863, 12.338610207972378, 13.365112608760167, 13.452949540317292, 13.531662728859022, 14.548118347240072]
8 : [3.220251432174427, 5.880473664772715, 5.8804777460152255, 10.68591773176322, 10.693892108137423, 10.694043457651123, 12.317604665085247, 12.326098068814025, 13.36087838494881, 13.435960447040557, 13.480566199392952, 14.398036526256176]
9 : [3.2202514321744267, 5.880473664135054, 5.880477745705898, 10.68590487291445, 10.69388727531439, 10.693949433863764, 12.317575537839888, 12.320797130642482, 13.358877986652384, 13.428258104858202, 13.451525419090247, 14.315735099964133]
10 : [3.2202514321744222, 5.880473664100299, 5.880477745688445, 10.685901792193427, 10.693886175010556, 10.69392645307182, 12.317565160998354, 12.318715753197722, 13.357892966123412, 13.424793979454352, 13.436298694252569, 14.270543525347897]
11 : [3.220251432174428, 5.880473664098382, 5.880477745687496, 10.685901066924663, 10.693885916583607, 10.693920952758658, 12.317558831667965, 12.317939832810769, 13.357414569158916, 13.423228038023094, 13.428747491595004, 14.245626435811202]
12 : [3.2202514321744244, 5.880473664098274, 5.880477745687424, 10.685900897346176, 10.693885856844455, 10.693919648675152, 12.317545562816807, 12.317668126798907, 13.357188433298186, 13.422515877857235, 13.425120086900478, 14.231830159829252]
13 : [3.220251432174422, 5.880473664098285, 5.880477745687439, 10.685900857788011, 10.693885843152676, 10.693919341033403, 12.317512860027499, 12.317598523970435, 13.357083768911373, 13.42218947295747, 13.423410885086248, 14.224178348038812]
14 : [3.2202514321744244, 5.880473664098267, 5.880477745687416, 10.685900848563552, 10.693885840013708, 10.693919268627717, 12.317488500531063, 12.317586424085608, 13.35703596497051, 13.422036751142105, 13.422616435635724, 14.219930276829068]
15 : [3.2202514321744236, 5.8804736640980275, 5.880477745687416, 10.68590084641128, 10.693885839291754, 10.693919251607175, 12.317478503327935, 12.31758347603818, 13.357014276893615, 13.421959823650477, 13.422254430931527, 14.21757050965323]
16 : [3.2202514321744258, 5.880473664098325, 5.880477745687407, 10.685900845908561, 10.69388583912515, 10.693919247606225, 12.317474829052243, 12.31758255986709, 13.357004467905156, 13.421913912564316, 13.422097193945001, 14.216258302570683]
17 : [3.2202514321744236, 5.880473664098118, 5.88047774568749, 10.685900845790469, 10.693885839086732, 10.693919246665548, 12.317473511807686, 12.317582248166614, 13.356999876478241, 13.421883744769769, 13.422032125592576, 14.2155293010091]
18 : [3.2202514321744244, 5.880473664098271, 5.880477745687346, 10.68590084576354, 10.693885839077854, 10.69391924644595, 12.317473045348475, 12.317582141100534, 13.356997940118795, 13.421866032272698, 13.422006785115942, 14.215123745909883]
19 : [3.220251432174425, 5.880473664098414, 5.8804777456873945, 10.685900845757299, 10.693885839075763, 10.693919246394067, 12.317472879993606, 12.317582103525957, 13.35699708403359, 13.421856792160591, 13.421996264835041, 14.214897967074176]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.220251432174425
5.880473664098414
5.8804777456873945
10.685900845757299
10.693885839075763
10.693919246394067
12.317472879993606
12.317582103525957
13.35699708403359
13.421856792160591
13.421996264835041
14.214897967074176
[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);
[ ]:
[ ]: