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.229093264388884, 22.63644750267151, 38.7591268119006, 56.95688372927046, 64.68904674257344, 71.61510643152916, 76.89311296405751, 86.36950975664791, 90.92730267437773, 99.90890224447234, 108.07709801674056, 123.53078334129707]
1 : [3.231012675431436, 6.086234263736157, 6.406899224641825, 12.054533472156447, 12.672421029692961, 13.138599689238864, 14.490032248320173, 17.72368170677237, 18.66258439836167, 19.346120603357505, 23.999160957369508, 25.451852240343648]
2 : [3.2203793481864946, 5.8866238226084375, 5.905548429319975, 10.853747390563575, 10.901287970022738, 11.033338300597086, 12.490608609904116, 13.713193967677052, 14.184813087520526, 15.348674545186727, 16.529828073048456, 17.964540349782933]
3 : [3.2202534507267213, 5.880768708677535, 5.881908488028926, 10.709133420836485, 10.726052065912215, 10.778656219068624, 12.345960396954803, 12.760676042929205, 13.76028135565352, 14.018326042187873, 14.607718515737307, 16.59221415107253]
4 : [3.220251466900577, 5.880494279981964, 5.880556917690787, 10.68989495348474, 10.698983267267298, 10.718281105535443, 12.32362131086067, 12.515134574997738, 13.530915635901703, 13.646352490715854, 14.013638404050802, 15.844042103483673]
5 : [3.2202514327806155, 5.880477114537583, 5.880480023263849, 10.68685103655564, 10.694700891022515, 10.700890407053992, 12.319109793662628, 12.416240501260686, 13.40947788983108, 13.552567887305218, 13.74921631125804, 15.246452468686579]
6 : [3.2202514321849645, 5.880473890511215, 5.880477843318827, 10.686161008730666, 10.69403287675729, 10.695820538590322, 12.318002400651933, 12.365108987077313, 13.375722155023574, 13.488497017483835, 13.613981824850613, 14.8137463657946]
7 : [3.220251432174608, 5.880473676484435, 5.880477751399358, 10.685969287196379, 10.693915072916857, 10.69441539784453, 12.317696219797195, 12.338610207930783, 13.365112608769245, 13.452949540276899, 13.531662728957247, 14.548118346392457]
8 : [3.220251432174431, 5.880473664772743, 5.880477746015218, 10.685917731763322, 10.69389210813737, 10.69404345765056, 12.317604665084954, 12.326098068798018, 13.360878384956301, 13.435960447027911, 13.480566199450934, 14.398036525810562]
9 : [3.2202514321744213, 5.8804736641350654, 5.880477745705893, 10.685904872915406, 10.693887275313891, 10.69394943386609, 12.317575537837413, 12.320797131342415, 13.358877986615704, 13.428258103323314, 13.451525425407187, 14.315735122959852]
10 : [3.2202514321744236, 5.88047366410027, 5.880477745688456, 10.685901792194155, 10.6938861750103, 10.693926453073383, 12.317565160998399, 12.318715754749654, 13.3578929665392, 13.424793976109449, 13.436298716404652, 14.270543591196349]
11 : [3.220251432174424, 5.880473664098367, 5.880477745687492, 10.685901066924997, 10.693885916583554, 10.693920952759644, 12.3175588316817, 12.317939834263115, 13.357414569313512, 13.423228035423314, 13.428747523446015, 14.245626522138604]
12 : [3.220251432174425, 5.880473664098258, 5.880477745687432, 10.685900897346292, 10.693885856844636, 10.693919648675694, 12.317545562925371, 12.317668127485796, 13.357188433261236, 13.422515875738732, 13.425120107677028, 14.231830229620986]
13 : [3.2202514321744244, 5.880473664098303, 5.8804777456874255, 10.685900857788956, 10.693885843152529, 10.693919341041292, 12.317512863419047, 12.317598526511864, 13.357083769491554, 13.422189473191423, 13.423410986798253, 14.224178877569686]
14 : [3.220251432174422, 5.88047366409828, 5.8804777456874415, 10.685900848563044, 10.693885840013586, 10.693919268627214, 12.317488498280245, 12.317586423262506, 13.35703596332454, 13.422036748648889, 13.422616168050494, 14.219929420409095]
15 : [3.220251432174423, 5.880473664098264, 5.880477745687417, 10.685900846410892, 10.693885839291598, 10.6939192516077, 12.317478502557593, 12.317583475885831, 13.357014273598448, 13.42195982386077, 13.422254140882043, 14.217569587035435]
16 : [3.220251432174425, 5.880473664098217, 5.880477745687402, 10.685900845908554, 10.69388583912516, 10.693919247607226, 12.317474827152104, 12.317582559116753, 13.35700446574852, 13.421913933351904, 13.422096776103999, 14.216257487942041]
17 : [3.2202514321744253, 5.8804736640983775, 5.880477745687442, 10.685900845790995, 10.69388583908674, 10.693919246666573, 12.317473507853538, 12.317582248354837, 13.357000035572929, 13.421883635276965, 13.422032555228846, 14.215523912394133]
18 : [3.220251432174425, 5.880473664098195, 5.880477745687485, 10.685900845763586, 10.693885839078128, 10.69391924644623, 12.317473043813994, 12.317582141354656, 13.356998037762986, 13.421865881743566, 13.42200724260841, 14.215119557914814]
19 : [3.2202514321744227, 5.880473664098525, 5.880477745687196, 10.68590084575702, 10.693885839075778, 10.693919246393044, 12.317472870867965, 12.317582101915594, 13.356997100040477, 13.421855836315498, 13.42199590196811, 14.214870638105479]
[6]:
print ("Eigenvalues")
for lam in evals:
    print (lam)
Eigenvalues
3.2202514321744227
5.880473664098525
5.880477745687196
10.68590084575702
10.693885839075778
10.693919246393044
12.317472870867965
12.317582101915594
13.356997100040477
13.421855836315498
13.42199590196811
14.214870638105479
[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);
[ ]:

[ ]: