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.229093264751877, 22.636447481567203, 38.759126810523014, 56.956883735276854, 64.68904675455177, 71.61510643513193, 76.89311297927044, 86.36950974687753, 90.9273026781248, 99.90890224523665, 108.07709800805813, 123.53078334590656]
1 : [3.2310126754315376, 6.0862342637173406, 6.406899224609758, 12.054533475888194, 12.67242102928361, 13.138599690109267, 14.490032245207088, 17.7236817062548, 18.662584399044757, 19.346120605613365, 23.999160955213387, 25.451852238558665]
2 : [3.2203793481865643, 5.886623822609743, 5.9055484293245835, 10.853747391043036, 10.901287969954199, 11.033338300749762, 12.490608609816295, 13.7131939672093, 14.184813087212447, 15.348674548075012, 16.52982807270233, 17.9645403495856]
3 : [3.2202534507267315, 5.880768708677554, 5.8819084880295245, 10.709133420822527, 10.726052066041406, 10.778656219081359, 12.345960396953538, 12.760676042659748, 13.76028135545628, 14.018326043579377, 14.607718515215707, 16.592214150189676]
4 : [3.220251466900597, 5.880494279981994, 5.880556917690856, 10.68989495348344, 10.698983267291712, 10.71828110553047, 12.323621310865695, 12.515134574853988, 13.530915636190219, 13.646352490583006, 14.013638403954388, 15.844042102365183]
5 : [3.2202514327806324, 5.880477114537649, 5.880480023263943, 10.686851036555126, 10.694700891026702, 10.700890407050355, 12.319109793666062, 12.416240501163427, 13.409477889927606, 13.552567887169324, 13.749216311187194, 15.246452467659664]
6 : [3.2202514321849804, 5.880473890511277, 5.880477843318874, 10.686161008730211, 10.69403287675815, 10.695820538588924, 12.318002400653583, 12.365108987015867, 13.375722155064262, 13.488497017400103, 13.613981824753532, 14.813746365077824]
7 : [3.220251432174621, 5.880473676484474, 5.880477751399398, 10.685969287196198, 10.693915072917088, 10.694415397844129, 12.317696219797897, 12.338610207897842, 13.365112608788822, 13.452949540232648, 13.531662728859498, 14.548118345941202]
8 : [3.220251432174444, 5.880473664772767, 5.880477746015278, 10.68591773176335, 10.693892108137474, 10.694043457650546, 12.317604665085279, 12.326098068784788, 13.360878384964948, 13.435960447018923, 13.480566199426919, 14.398036525572886]
9 : [3.2202514321744387, 5.880473664135139, 5.8804777457059485, 10.685904872914845, 10.693887275314083, 10.693949433865203, 12.31757553784064, 12.320797131357399, 13.35887798668013, 13.428258104845968, 13.451525426623798, 14.315735113531707]
10 : [3.2202514321744387, 5.880473664100315, 5.880477745688501, 10.685901792193793, 10.693886175010233, 10.693926453072802, 12.317565160998566, 12.318715754666528, 13.357892966331882, 13.424793978252902, 13.436298711518146, 14.270543566706085]
11 : [3.220251432174444, 5.880473664098404, 5.880477745687535, 10.685901066924954, 10.693885916583634, 10.69392095275916, 12.317558831676806, 12.317939834002521, 13.357414569283595, 13.42322803693062, 13.42874751479348, 14.24562649272991]
12 : [3.220251432174443, 5.880473664098323, 5.8804777456874815, 10.685900897346425, 10.693885856844604, 10.693919648675305, 12.317545562902719, 12.317668127394445, 13.357188433200708, 13.422515875742986, 13.425120103485014, 14.23183021650908]
13 : [3.2202514321744413, 5.880473664098288, 5.880477745687467, 10.685900857788033, 10.693885843152627, 10.69391934103781, 12.317512863345026, 12.3175985266558, 13.357083764175577, 13.4221894629639, 13.423411011498391, 14.22417881446337]
14 : [3.220251432174437, 5.880473664098314, 5.880477745687463, 10.685900848563946, 10.693885840014344, 10.693919268633655, 12.317488504516868, 12.317586425411795, 13.35703596354002, 13.42203675684054, 13.422616583926406, 14.219931088277889]
15 : [3.2202514321744418, 5.8804736640983055, 5.880477745687606, 10.68590084641133, 10.693885839291342, 10.693919251600748, 12.317478493705014, 12.317583472700216, 13.357014276694095, 13.421959812088764, 13.422254115610734, 14.217568990445251]
16 : [3.2202514321744387, 5.880473664098336, 5.8804777456875215, 10.685900845908268, 10.693885839124126, 10.693919247589115, 12.31747479371393, 12.3175825493525, 13.35700447163308, 13.421913707443512, 13.42209624514411, 14.216249474948247]
17 : [3.220251432174446, 5.88047366409827, 5.880477745687414, 10.685900845791148, 10.693885839085734, 10.693919246661668, 12.317473497665494, 12.31758224526435, 13.357000043016676, 13.42188358343148, 13.422032690407752, 14.215522942343139]
18 : [3.220251432174442, 5.880473664098161, 5.8804777456875845, 10.6859008457634, 10.693885839077463, 10.693919246442851, 12.317473028033676, 12.317582137435739, 13.356998023083364, 13.421865134999088, 13.422006033881777, 14.215100289740263]
19 : [3.2202514321744395, 5.880473664098385, 5.880477745687603, 10.685900845757168, 10.693885839075788, 10.693919246393241, 12.317472871525245, 12.317582101773072, 13.356997126419198, 13.421856104657346, 13.421995847603418, 14.214878577603743]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.2202514321744395
5.880473664098385
5.880477745687603
10.685900845757168
10.693885839075788
10.693919246393241
12.317472871525245
12.317582101773072
13.356997126419198
13.421856104657346
13.421995847603418
14.214878577603743
[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);
[ ]:
[ ]: