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.2290932574529885, 22.636447445144434, 38.75912679443551, 56.95688368132279, 64.6890467964173, 71.61510640129654, 76.8931128548401, 86.3695097527238, 90.92730268948857, 99.90890224915033, 108.07709801218556, 123.53078333426468]
1 : [3.2310126754024795, 6.086234263006221, 6.406899223720901, 12.054533475527085, 12.67242102733432, 13.138599691155731, 14.490032234965692, 17.723681706565124, 18.6625844062199, 19.346120606491265, 23.999160963958733, 25.451852233134883]
2 : [3.220379348186232, 5.8866238225948235, 5.9055484292733045, 10.853747390901331, 10.901287970054439, 11.033338300768902, 12.490608609302393, 13.713193971080303, 14.184813087527374, 15.34867454361136, 16.529828075851995, 17.96454035019547]
3 : [3.2202534507267138, 5.880768708677154, 5.881908488026609, 10.709133420829094, 10.726052066001056, 10.778656219183206, 12.345960396898684, 12.76067604376089, 13.760281355614044, 14.018326042627324, 14.607718514740405, 16.59221415220209]
4 : [3.220251466900577, 5.880494279981944, 5.880556917690666, 10.689894953483961, 10.698983267283035, 10.718281105578138, 12.323621310862045, 12.515134575264176, 13.530915635929043, 13.646352491065187, 14.013638403076323, 15.844042104561565]
5 : [3.220251432780614, 5.880477114537605, 5.880480023263888, 10.686851036554133, 10.69470089102577, 10.700890407068798, 12.319109793667646, 12.416240501371378, 13.409477889847668, 13.552567887489232, 13.749216310638875, 15.246452469587704]
6 : [3.2202514321849636, 5.880473890511233, 5.880477843318812, 10.686161008729776, 10.694032876758072, 10.695820538595095, 12.31800240065471, 12.365108987126744, 13.375722155013834, 13.488497017568587, 13.613981824529208, 14.813746366415529]
7 : [3.220251432174601, 5.880473676484442, 5.8804777513993844, 10.68596928719607, 10.693915072917033, 10.694415397845942, 12.317696219798353, 12.338610207952385, 13.365112608754579, 13.45294954031556, 13.531662728805717, 14.548118346751206]
8 : [3.2202514321744276, 5.880473664772745, 5.880477746015231, 10.68591773176325, 10.6938921081374, 10.694043457651047, 12.317604665085398, 12.326098068799329, 13.360878384943618, 13.435960447063866, 13.480566199272296, 14.398036525767791]
9 : [3.2202514321744227, 5.880473664135059, 5.88047774570591, 10.685904872914605, 10.69388727531386, 10.693949433864656, 12.3175755378393, 12.320797130851282, 13.3588779866402, 13.428258104423099, 13.451525418964344, 14.315735103747114]
10 : [3.220251432174424, 5.880473664100276, 5.8804777456884745, 10.685901792193746, 10.693886175010237, 10.693926453072438, 12.317565160998393, 12.318715753986648, 13.35789296665992, 13.42479397476288, 13.436298697638803, 14.270543561412198]
11 : [3.2202514321744267, 5.880473664098379, 5.880477745687474, 10.685901066925265, 10.693885916583591, 10.693920952760164, 12.31755883168448, 12.317939833880287, 13.357414569638367, 13.423228034040948, 13.428747508954354, 14.245626509089213]
12 : [3.2202514321744244, 5.880473664098234, 5.880477745687425, 10.685900897346501, 10.693885856844727, 10.693919648675818, 12.317545562920621, 12.317668127368572, 13.357188433474432, 13.422515874408324, 13.425120102860074, 14.23183023592003]
13 : [3.2202514321744244, 5.880473664098265, 5.8804777456874255, 10.685900857788402, 10.69388584315242, 10.693919341039607, 12.317512863037855, 12.317598526322447, 13.357083768703339, 13.422189470438237, 13.423410969713988, 14.22417875933763]
14 : [3.2202514321744236, 5.880473664098251, 5.880477745687436, 10.685900848563891, 10.693885840013936, 10.693919268634382, 12.31748850265314, 12.317586424614719, 13.357035966278932, 13.422036758845483, 13.422616332743472, 14.219930528653661]
15 : [3.220251432174424, 5.880473664098019, 5.88047774568729, 10.685900846411489, 10.693885839291632, 10.693919251610362, 12.317478504556352, 12.31758347620763, 13.357014278116718, 13.421959839508917, 13.422254206646649, 14.217570638970981]
16 : [3.2202514321744258, 5.880473664098554, 5.880477745687409, 10.685900845908513, 10.69388583911866, 10.693919247558025, 12.317474693593105, 12.317582515229475, 13.35700441113762, 13.421913502974213, 13.422093167878193, 14.216231023589419]
17 : [3.2202514321744244, 5.880473664098199, 5.880477745687492, 10.685900845788392, 10.693885839083267, 10.693919246645518, 12.317473429575484, 12.317582225734215, 13.356999802696862, 13.421881860600385, 13.42202936715934, 14.215475157909548]
18 : [3.220251432174426, 5.880473664097929, 5.880477745687623, 10.685900845762681, 10.693885839076735, 10.693919246438686, 12.317473004549036, 12.317582130780707, 13.356997904108377, 13.421864162913366, 13.422005256158048, 14.21507439844942]
19 : [3.2202514321744253, 5.880473664098097, 5.880477745687248, 10.685900845757002, 10.693885839075497, 10.693919246391957, 12.317472862472664, 12.31758209927024, 13.3569970719769, 13.421855593921123, 13.421995616929188, 14.214863333229106]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.2202514321744253
5.880473664098097
5.880477745687248
10.685900845757002
10.693885839075497
10.693919246391957
12.317472862472664
12.31758209927024
13.3569970719769
13.421855593921123
13.421995616929188
14.214863333229106
[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);
[ ]:

[ ]: