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.160219346835305, 22.264531981297537, 31.567335214266215, 58.289877143677785, 67.47227874773407, 72.39523705352914, 80.93569051252369, 83.50249765475537, 91.51581274988284, 95.6102134074308, 99.67918593889998, 126.01520005527479]
1 : [3.2294240059704236, 6.020505138659677, 6.242969591516261, 12.344066796042007, 12.776727828436021, 13.18948820770492, 14.922959875434438, 15.93154452612112, 18.97359321167749, 20.50699765115335, 24.473952189676577, 28.20271756214668]
2 : [3.2203406545730573, 5.885637286315296, 5.89704327119396, 10.837933770122472, 10.9404765244274, 11.238454915321704, 12.527420999689488, 13.534806277538594, 14.009881882696051, 16.080118686731307, 17.293552258066782, 20.0591821335636]
3 : [3.2202545546810746, 5.880808974725193, 5.881448150833814, 10.713394208014455, 10.73761935735923, 10.848114949284165, 12.359641741647971, 12.947326703014067, 13.50481673196974, 14.581340841261726, 15.708094614048305, 18.11246046446069]
4 : [3.22025334934816, 5.880500534430544, 5.880529059355814, 10.694288288876542, 10.700379598750256, 10.749389209010173, 12.327566311313786, 12.68281393672931, 13.43626544250477, 13.819929006664415, 15.047529952261183, 16.33990085137728]
5 : [3.2202533303188186, 5.880476899500665, 5.880479539617036, 10.688012948559159, 10.695132040832151, 10.714752133629448, 12.320117952844008, 12.527954704311593, 13.415417592891838, 13.541431966704904, 14.610649435133775, 15.040427017065232]
6 : [3.2202533300015963, 5.880473995303139, 5.880478041161115, 10.686437346692982, 10.694196526167888, 10.700641548803546, 12.318262394523963, 12.42260046041812, 13.405131058259835, 13.455045360354854, 14.070282887530729, 14.532957040922705]
7 : [3.2202533299963294, 5.88047382109936, 5.880477959925733, 10.686043605936609, 10.693983611589623, 10.695760094158002, 12.317765503849087, 12.362788187577623, 13.397790909109572, 13.430966894654857, 13.701963145420995, 14.37989507727172]
8 : [3.2202533299962406, 5.880473811248231, 5.880477955458625, 10.685936301748837, 10.693933335503756, 10.694355287847127, 12.317621457247085, 12.334921494817735, 13.390538181378181, 13.424509983475867, 13.53303741387356, 14.303040859677706]
9 : [3.2202533299962384, 5.880473810710855, 5.880477955218023, 10.685909123033658, 10.693921375288797, 10.69399833634055, 12.317576652033383, 12.323821815012355, 13.381142242824215, 13.4227224913255, 13.463084423163926, 14.26230019779721]
10 : [3.2202533299962384, 5.880473810681918, 5.880477955205112, 10.685902693078608, 10.693910121851788, 10.693920804122984, 12.317561520725782, 12.319731204798243, 13.371093995709922, 13.422199915456762, 13.43737955281412, 14.240382972794901]
11 : [3.220253329996244, 5.880473810680384, 5.880477955204431, 10.685901218433354, 10.693891230245525, 10.69391884189085, 12.31755459926241, 12.318282101973008, 13.36411334572859, 13.42203731314446, 13.428207032431025, 14.228568612875442]
12 : [3.2202533299962437, 5.880473810680306, 5.880477955204369, 10.68590088337814, 10.69388661188476, 10.693918601941222, 12.317545999005972, 12.317781713121395, 13.36036669814444, 13.421982570110835, 13.424630976588725, 14.222178668037344]
13 : [3.220253329996241, 5.880473810680289, 5.880477955204379, 10.685900807534896, 10.69388553612593, 10.693918549173047, 12.317523731079483, 12.317627097008053, 13.358552112663173, 13.421961532231258, 13.423119444142358, 14.218720266174861]
14 : [3.2202533299962393, 5.88047381068031, 5.880477955204372, 10.68590079037115, 10.693885286192813, 10.693918536923688, 12.317495870658052, 12.317593552409845, 13.357707055901258, 13.421949937664435, 13.42245351654013, 14.21684505400261]
15 : [3.2202533299962384, 5.880473810680321, 5.880477955204246, 10.685900786487169, 10.693885228107145, 10.69391853404842, 12.317481895229024, 12.31758620937247, 13.357319717111718, 13.421936405178181, 13.422160568785463, 14.215828232254788]
16 : [3.220253329996236, 5.880473810680268, 5.880477955204463, 10.685900785606314, 10.693885214587397, 10.693918533368938, 12.317476599077729, 12.317584095521559, 13.357143124120821, 13.421912194678413, 13.422044201531415, 14.215271446859392]
17 : [3.2202533299962375, 5.8804738106807175, 5.880477955204318, 10.685900785407815, 10.693885211439776, 10.693918533210853, 12.31747471261608, 12.317583406254279, 13.3570629702061, 13.42188446413017, 13.42200748726337, 14.214975761104071]
18 : [3.2202533299962375, 5.880473810680267, 5.880477955204395, 10.685900785362035, 10.69388521070374, 10.693918533173159, 12.317474048455708, 12.31758317077964, 13.357026578270023, 13.421866355535935, 13.421995843945089, 14.214806749761223]
19 : [3.2202533299962393, 5.880473810680447, 5.880477955204366, 10.685900785352102, 10.693885210530699, 10.693918533164974, 12.317473814093688, 12.317583088699974, 13.357009896144724, 13.421856829288135, 13.421991516213996, 14.21471946964979]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.2202533299962393
5.880473810680447
5.880477955204366
10.685900785352102
10.693885210530699
10.693918533164974
12.317473814093688
12.317583088699974
13.357009896144724
13.421856829288135
13.421991516213996
14.21471946964979
[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);
[ ]:

[ ]: