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.229093261120058, 22.63644750506259, 38.759126814344974, 56.956883711124036, 64.68904673652528, 71.61510644211104, 76.89311294554497, 86.36950975705243, 90.92730267803441, 99.90890224629871, 108.07709801553487, 123.53078333399891]
1 : [3.2310126754178277, 6.08623426380841, 6.406899224509675, 12.054533472605984, 12.672421029129946, 13.138599687662134, 14.490032247901926, 17.723681706617693, 18.662584395482305, 19.34612060520142, 23.999160955610147, 25.45185223721639]
2 : [3.2203793481863325, 5.886623822609794, 5.905548429312057, 10.853747390648754, 10.901287970037076, 11.033338300551502, 12.490608609910245, 13.713193966745905, 14.18481308730828, 15.348674545018733, 16.52982807531252, 17.96454034777323]
3 : [3.2202534507267133, 5.880768708677703, 5.8819084880285875, 10.709133420838068, 10.726052065938212, 10.778656219123757, 12.345960396955265, 12.760676042704056, 13.760281355551646, 14.018326042454373, 14.607718515780856, 16.59221414966433]
4 : [3.2202514669005757, 5.880494279981959, 5.880556917690767, 10.689894953486522, 10.698983267272622, 10.718281105559598, 12.323621310860608, 12.51513457489242, 13.530915635878415, 13.646352490730568, 14.013638403824084, 15.844042101835782]
5 : [3.220251432780613, 5.8804771145375945, 5.880480023263876, 10.686851036557021, 10.69470089102351, 10.700890407061072, 12.319109793662747, 12.416240501183765, 13.409477889798806, 13.552567887331586, 13.749216310955497, 15.2464524671979]
6 : [3.2202514321849676, 5.880473890511228, 5.8804778433188005, 10.686161008731283, 10.694032876757483, 10.69582053859191, 12.31800240065205, 12.36510898702207, 13.37572215500211, 13.48849701751162, 13.613981824556236, 14.813746364758671]
7 : [3.2202514321746047, 5.8804736764844385, 5.880477751399375, 10.685969287196544, 10.693915072916885, 10.694415397844839, 12.317696219797297, 12.338610207898197, 13.365112608758228, 13.452949540294368, 13.531662728727262, 14.54811834576807]
8 : [3.2202514321744284, 5.880473664772711, 5.8804777460152415, 10.68591773176339, 10.693892108137375, 10.694043457650709, 12.317604665085078, 12.326098068775632, 13.360878384950352, 13.435960447050329, 13.480566199198085, 14.398036525243485]
9 : [3.2202514321744213, 5.880473664135118, 5.8804777457058846, 10.685904872914023, 10.69388727531448, 10.693949433862114, 12.317575537839605, 12.320797130043557, 13.358877986661438, 13.428258105795777, 13.451525412429307, 14.315735080814557]
10 : [3.2202514321744253, 5.880473664100298, 5.880477745688462, 10.68590179219347, 10.693886175010796, 10.693926453070967, 12.317565160998424, 12.318715753155455, 13.357892966488949, 13.42479397762081, 13.436298693945114, 14.270543531656887]
11 : [3.220251432174425, 5.88047366409838, 5.880477745687472, 10.685901066924796, 10.69388591658392, 10.693920952758543, 12.317558831673034, 12.317939833133245, 13.357414569389688, 13.423228036367167, 13.428747502736357, 14.24562646549981]
12 : [3.220251432174424, 5.88047366409827, 5.880477745687424, 10.685900897346322, 10.693885856844522, 10.693919648675035, 12.317545562865053, 12.31766812707003, 13.357188433350023, 13.42251587637238, 13.42512010216511, 14.231830203302312]
13 : [3.22025143217442, 5.880473664098294, 5.8804777456874335, 10.68590085778916, 10.693885843152684, 10.693919341039999, 12.317512863628151, 12.3175985266536, 13.357083769633949, 13.42218946882323, 13.423411021848962, 14.224178981540303]
14 : [3.220251432174423, 5.8804736640982505, 5.880477745687408, 10.685900848563614, 10.693885840013909, 10.693919268631456, 12.317488501431122, 12.317586424376932, 13.357035963987387, 13.422036757748092, 13.4226163406452, 14.219930175295595]
15 : [3.2202514321744267, 5.880473664098253, 5.880477745687443, 10.685900846411142, 10.693885839291802, 10.693919251608856, 12.317478504306763, 12.317583476336598, 13.357014275198125, 13.421959827593609, 13.422254275336892, 14.217570281789808]
16 : [3.2202514321744267, 5.880473664098372, 5.880477745687367, 10.685900845908492, 10.693885839124677, 10.693919247603239, 12.317474822919946, 12.317582557885311, 13.35700446902935, 13.421913893664255, 13.422096962671306, 14.216257048531391]
17 : [3.220251432174424, 5.880473664098139, 5.88047774568759, 10.685900845790488, 10.693885839086859, 10.693919246663619, 12.317473505200157, 12.31758224811331, 13.357000012579572, 13.42188341433493, 13.422032990238478, 14.21551986922497]
18 : [3.2202514321744276, 5.880473664098258, 5.880477745687381, 10.685900845763419, 10.693885839077971, 10.69391924644511, 12.317473042010311, 12.317582141169684, 13.356998016841004, 13.42186570390247, 13.422007532885113, 14.21511538448108]
19 : [3.2202514321744253, 5.880473664098484, 5.8804777456876565, 10.685900845757173, 10.693885839075685, 10.693919246393909, 12.31747287819458, 12.317582103419122, 13.356997121332073, 13.421856611342712, 13.421996840765875, 14.21489275913948]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.2202514321744253
5.880473664098484
5.8804777456876565
10.685900845757173
10.693885839075685
10.693919246393909
12.31747287819458
12.317582103419122
13.356997121332073
13.421856611342712
13.421996840765875
14.21489275913948
[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);
[ ]:
[ ]: