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 : [7.150296948204009, 22.3265035008857, 31.60106792108181, 58.24000270003562, 67.6350033400194, 72.34711474287607, 80.89451919250253, 83.59530218812247, 91.60198856171587, 95.68068302126306, 99.7573283216324, 126.06808241539228]
1 : [3.2294321230226104, 6.02109523824747, 6.2458929491709805, 12.354767319382434, 12.76330239204964, 13.188129273909139, 14.934865620583956, 15.944276092038548, 18.95698048334093, 20.50027990606101, 24.455475748512832, 28.195839850071202]
2 : [3.2203395167520013, 5.885669974135578, 5.897182338204891, 10.838469253913434, 10.9377932021711, 11.238717411501346, 12.530767897966232, 13.5314063137629, 14.006795458506186, 16.06911227384477, 17.288396920595158, 20.033610627837554]
3 : [3.2202526747069817, 5.8808114448353574, 5.881454784990588, 10.713377328923613, 10.736960229421697, 10.84795039161136, 12.360316401230746, 12.945300054858578, 13.50524154681408, 14.569997881595844, 15.708606257320206, 18.075340642656396]
4 : [3.220251451907903, 5.880500462907363, 5.880529333494944, 10.694236557601178, 10.700286732943606, 10.74918149884931, 12.327750515791715, 12.681833928309802, 13.436580989194804, 13.814633985147639, 15.04842723415472, 16.29126446665115]
5 : [3.2202514325045866, 5.880476771790247, 5.88047933857338, 10.688014342020972, 10.695120107752285, 10.714547964755939, 12.320176815003908, 12.526639693561318, 13.415636920620177, 13.539564686983182, 14.604849498590394, 15.007999274722065]
6 : [3.220251432179889, 5.880473849605591, 5.88047783169811, 10.686445825892267, 10.694194150529183, 10.700522944764472, 12.318282819917831, 12.421255845054443, 13.4052480236904, 13.454478614292626, 14.052944970106998, 14.529458153253717]
7 : [3.2202514321744884, 5.880473674544917, 5.8804777504057855, 10.6860470351339, 10.693983562499506, 10.695716667117399, 12.317772546024623, 12.36193527210446, 13.397778616036325, 13.430806578398435, 13.693098988733539, 14.379048404020862]
8 : [3.2202514321743965, 5.8804736646671465, 5.880477745941508, 10.685937259558896, 10.693933856911293, 10.694343563341878, 12.317623641831366, 12.334532965752082, 13.390355718276775, 13.42446663142754, 13.529209201150673, 14.302707932912512]
9 : [3.2202514321743907, 5.880473664128867, 5.880477745701051, 10.685909399493548, 10.693922016911877, 10.693995912172436, 12.317577080939955, 12.323670882252644, 13.380806924917318, 13.422710979037001, 13.46163361710706, 14.2621504097008]
10 : [3.2202514321743934, 5.880473664099905, 5.880477745688126, 10.685902804309173, 10.693910120937733, 10.693921407809247, 12.317561315624, 12.31967648277845, 13.37079397714444, 13.422196664040717, 13.436883779629012, 14.240314688531743]
11 : [3.220251432174396, 5.880473664098343, 5.880477745687448, 10.685901290715101, 10.693891690174091, 10.693919552184386, 12.317554138747935, 12.318262368661953, 13.36393795384134, 13.422036050430473, 13.428026464294938, 14.22853757431523]
12 : [3.2202514321743934, 5.880473664098238, 5.8804777456873945, 10.68590094654944, 10.693887201441736, 10.69391931463768, 12.31754530675057, 12.317774300923581, 13.36027969728515, 13.421981702072644, 13.424558350552816, 14.222164595727433]
13 : [3.220251432174396, 5.880473664098261, 5.880477745687395, 10.685900868585021, 10.693886155729658, 10.693919262275557, 12.317522537583159, 12.31762431245206, 13.358511409364278, 13.421960655666595, 13.423088505852634, 14.218713674530385]
14 : [3.2202514321743956, 5.880473664098248, 5.8804777456873465, 10.685900850926982, 10.693885912712345, 10.693919250114517, 12.317494665069527, 12.31759217767268, 13.357688414950246, 13.421948888625042, 13.422440246239745, 14.216841757733956]
15 : [3.2202514321743934, 5.88047366409827, 5.880477745687444, 10.685900846927932, 10.693885856221021, 10.693919247258842, 12.317480865404491, 12.317585131719671, 13.35731121765254, 13.421934999213207, 13.422155328324722, 14.21582589384091]
16 : [3.220251432174396, 5.880473664098247, 5.880477745687356, 10.685900846019283, 10.693885843072374, 10.693919246584212, 12.31747564893871, 12.317583095846729, 13.357139344790502, 13.421910581202352, 13.422042713398483, 14.215267883984003]
17 : [3.220251432174396, 5.880473664098512, 5.880477745687908, 10.685900845814945, 10.69388584000724, 10.693919246426747, 12.317473791888897, 12.317582431311607, 13.357061248945474, 13.421883295663285, 13.422007071272194, 14.214969135111998]
18 : [3.2202514321743965, 5.880473664098177, 5.880477745687302, 10.685900845767913, 10.69388583927474, 10.693919246389708, 12.317473115255613, 12.317582196865034, 13.357024593339544, 13.42186515035893, 13.421995541132702, 14.21480323201992]
19 : [3.220251432174395, 5.880473664098392, 5.8804777456874, 10.685900845758114, 10.693885839119604, 10.693919246380982, 12.317472899388905, 12.31758212173291, 13.357008874399577, 13.42185616876624, 13.421991346240372, 14.214716675234367]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.220251432174395
5.880473664098392
5.8804777456874
10.685900845758114
10.693885839119604
10.693919246380982
12.317472899388905
12.31758212173291
13.357008874399577
13.42185616876624
13.421991346240372
14.214716675234367
[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);
[ ]:
[ ]: