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.1602193583107425, 22.264531976891654, 31.567335217321208, 58.28987719019087, 67.47227879592783, 72.39523706659628, 80.93569052203152, 83.50249763847957, 91.51581273971257, 95.61021337186047, 99.67918595989117, 126.01520004343692]
1 : [3.2294240060312003, 6.0205051384124255, 6.242969591648828, 12.344066794515914, 12.776727832077622, 13.189488207092431, 14.922959875098705, 15.931544525945908, 18.973593208980027, 20.50699765073092, 24.473952191602372, 28.20271755165191]
2 : [3.220340654573683, 5.885637286306853, 5.897043271183784, 10.837933769754573, 10.940476524903143, 11.238454914646061, 12.527420999570378, 13.534806278143474, 14.00988188285712, 16.080118687418675, 17.293552259050937, 20.059182133070053]
3 : [3.220254554681078, 5.8808089747251, 5.881448150832054, 10.713394207952069, 10.73761935743679, 10.848114949015207, 12.35964174159143, 12.947326704342148, 13.504816732069955, 14.581340841435427, 15.708094616208099, 18.112460469124724]
4 : [3.220253349348158, 5.880500534430588, 5.880529059355609, 10.694288288869963, 10.700379598752235, 10.749389208926784, 12.327566311289129, 12.682813938143406, 13.436265442570292, 13.819929006632147, 15.047529953439055, 16.339900863311062]
5 : [3.220253330318821, 5.880476899500646, 5.880479539617064, 10.688012948554064, 10.695132040830934, 10.714752133634523, 12.320117952834636, 12.527954705669034, 13.415417592937882, 13.541431966555445, 14.610649435476072, 15.04042702832551]
6 : [3.220253330001597, 5.880473995303125, 5.88047804116112, 10.686437346689539, 10.694196526167643, 10.700641548822938, 12.318262394520714, 12.422600461417318, 13.405131058272632, 13.455045360206952, 14.07028289115709, 14.532957044030399]
7 : [3.2202533299963325, 5.880473821099379, 5.880477959925746, 10.686043605935323, 10.693983611589578, 10.695760094167387, 12.31776550384798, 12.362788188122536, 13.397790909098669, 13.43096689456959, 13.701963147561479, 14.379895078507124]
8 : [3.2202533299962415, 5.8804738112482395, 5.880477955458607, 10.685936301748509, 10.693933335503777, 10.694355287849838, 12.317621457246684, 12.33492149505228, 13.390538181384958, 13.424509983430493, 13.533037414843559, 14.303040860299003]
9 : [3.2202533299962415, 5.880473810710863, 5.880477955218047, 10.68590912303283, 10.693921375288559, 10.69399833633767, 12.31757665203193, 12.323821814868413, 13.38114224273796, 13.42272249130558, 13.463084423799534, 14.262300196030225]
10 : [3.220253329996238, 5.880473810681902, 5.8804779552050945, 10.685902693078432, 10.693910121852943, 10.693920804123549, 12.317561520725226, 12.31973120483764, 13.371093996340084, 13.422199915456245, 13.437379554053868, 14.240382970963386]
11 : [3.2202533299962384, 5.880473810680397, 5.880477955204421, 10.685901218435687, 10.69389123029374, 10.693918841891957, 12.317554599275796, 12.318282107422071, 13.364113384035058, 13.422037312779008, 13.428207063379856, 14.22856861061467]
12 : [3.2202533299962415, 5.880473810680312, 5.8804779552043716, 10.685900883378425, 10.693886611899622, 10.693918601941547, 12.317545999087288, 12.317781715312794, 13.360366723377771, 13.421982569824559, 13.424630995062625, 14.222178656089648]
13 : [3.220253329996239, 5.8804738106803125, 5.88047795520438, 10.68590080753683, 10.693885536133985, 10.693918549173084, 12.3175237322039, 12.31762710013321, 13.358552147330343, 13.421961532918802, 13.423119452192328, 14.21872028566173]
14 : [3.220253329996237, 5.880473810680291, 5.880477955204351, 10.685900790372378, 10.693885286195325, 10.693918536924087, 12.317495872158432, 12.317593553537172, 13.357707086488064, 13.421949938600807, 13.422453535534993, 14.216845305022307]
15 : [3.22025332999624, 5.880473810680332, 5.8804779552044435, 10.685900786487302, 10.693885228100754, 10.693918534048468, 12.317481893260917, 12.317586208721012, 13.357319670343331, 13.42193640316484, 13.422160545063537, 14.215828298476676]
16 : [3.22025332999624, 5.880473810680397, 5.880477955204453, 10.685900785607224, 10.69388521458674, 10.693918533371244, 12.3174765975429, 12.317584095011084, 13.357143241967847, 13.421912281248288, 13.422044431122366, 14.215275664916318]
17 : [3.2202533299962433, 5.880473810680119, 5.880477955204389, 10.68590078540654, 10.693885211405432, 10.693918533210908, 12.317474679384917, 12.317583394938438, 13.357061530011554, 13.421883990661192, 13.422007187492397, 14.21497582554949]
18 : [3.2202533299962424, 5.880473810680297, 5.880477955204353, 10.685900785362087, 10.693885210691887, 10.69391853317353, 12.31747402949544, 12.317583164526066, 13.357025564408579, 13.421865938742426, 13.421995752133677, 14.214812805081046]
19 : [3.2202533299962415, 5.880473810680371, 5.880477955204351, 10.68590078535201, 10.693885210529265, 10.693918533164974, 12.317473806985598, 12.31758308617622, 13.357009487640058, 13.421856708934623, 13.421991512782178, 14.214724050508458]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.2202533299962415
5.880473810680371
5.880477955204351
10.68590078535201
10.693885210529265
10.693918533164974
12.317473806985598
12.31758308617622
13.357009487640058
13.421856708934623
13.421991512782178
14.214724050508458
[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);
[ ]:

[ ]: