This page was generated from unit-2.4-Maxwell/Maxwellevp.ipynb.
2.4.1 Maxwell eigenvalue problem¶
We solve the Maxwell eigenvalue problem
for \(u, v \; \bot \; \nabla H^1\) using the PINVIT solver from the ngsolve.solvers module.
The orthogonality to gradient fields is important to eliminate the huge number of zero eigenvalues. The projection onto the orthogonal sub-space is implemented by a Poisson projection:
The algorithm and the example are taken from the PhD thesis of Sabine Zaglmayr, pp 145-150.
[1]:
from netgen.occ import *
from ngsolve import *
from ngsolve.webgui import Draw
The domain is the Fichera cube. The eigenfunctions are singular at the re-entrant edges and at the re-entrant corner, where we want to apply geometric mesh refinement:
[2]:
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 = fichera.GenerateMesh(maxh=0.4)
mesh.RefineHP(levels=2, factor=0.2)
Draw (mesh);
We need the stiffness matrix and the mass matrix. The preconditioner is a sparse direct solver for the shifted problem:
[4]:
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 = preconditioners.Direct(apre, inverse="sparsecholesky")
ndof = 34224
The discrete gradient is a sparse matrix mapping the coefficients of an \(H^1\) function to the coefficients of its gradient in \(H(curl)\). With it we assemble the Laplace matrix for the projection, and combine the projected preconditioner:
[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.198343689651654, 23.64381886914339, 37.677223942852756, 47.302981656926086, 50.45402361211148, 58.31364632056474, 63.10692001014712, 75.47990638403165, 83.58942658490074, 89.6597005593316, 102.28276798360051, 106.61233630597211]
1 : [3.236988801953164, 6.031064600555818, 6.230525953207135, 11.905510217240213, 12.742935649807123, 14.719906191293582, 15.317887285049082, 15.745556255332016, 17.409946597117763, 18.53514553051685, 20.568469665830836, 24.8613025417769]
2 : [3.220853534475838, 5.885170944829342, 5.890562277073722, 10.804832765278796, 10.936019393400924, 11.48591698234278, 12.917511393149137, 13.6355932901491, 13.679306610286828, 14.357128236258916, 15.492957402156902, 18.60859704217582]
3 : [3.2207135653307617, 5.880850431505839, 5.881200867151008, 10.704891109555959, 10.752772045508328, 10.84150916604736, 12.42669262598983, 13.280972458042706, 13.427172833200467, 13.729420475293516, 14.76723399572777, 16.016495899378945]
4 : [3.2207114855513344, 5.880639410972358, 5.880652998766366, 10.691550277198436, 10.709054543695467, 10.734575548947014, 12.339959980506777, 13.001755856118804, 13.384801405140553, 13.548157893948584, 14.213536199299282, 14.584576207431416]
5 : [3.2207114497565237, 5.88060750562191, 5.880636974822891, 10.689230799386905, 10.69779978479977, 10.706582823798561, 12.32297077539877, 12.665956456802919, 13.37349528097685, 13.478406373330303, 13.668498255210576, 14.386076681139857]
6 : [3.2207114491300253, 5.880605298568294, 5.880636323429761, 10.688138674026037, 10.69550438152772, 10.698061349896323, 12.319436965351624, 12.453220178944651, 13.368123891482684, 13.447878944852281, 13.510702101466817, 14.305329722160053]
7 : [3.220711449119284, 5.880605175661436, 5.880636287257657, 10.687565256731208, 10.695043493384794, 10.6959881555198, 12.318654994418516, 12.366788092098814, 13.364016153139422, 13.434044075425597, 13.458128211529761, 14.264146998744126]
8 : [3.2207114491190985, 5.880605168984415, 5.880636285246249, 10.687384281028987, 10.694946658559717, 10.69551289959084, 12.318470175138359, 12.335331932732398, 13.361099585224363, 13.42776155107842, 13.437757254141797, 14.242228675584748]
9 : [3.2207114491190967, 5.88060516862215, 5.880636285134891, 10.687338695825943, 10.694925439041656, 10.69540300203975, 12.318423052716426, 12.32425302266495, 13.35939813191632, 13.424895914200404, 13.429240010862765, 14.23034333447257]
10 : [3.220711449119098, 5.880605168602351, 5.880636285128739, 10.687327886052689, 10.694920711938094, 10.695377390828645, 12.318409671500794, 12.320379311154475, 13.358527136209041, 13.423584471395131, 13.425512200211005, 14.22383626444231]
11 : [3.220711449119096, 5.880605168601261, 5.880636285128379, 10.687325356239088, 10.694919650414448, 10.695371400949417, 12.318404100182963, 12.319028893833874, 13.358109821878516, 13.422981352590986, 13.423838904333838, 14.22025391393299]
12 : [3.220711449119095, 5.880605168601201, 5.8806362851283485, 10.687324764725611, 10.694919410082216, 10.695369996168665, 12.318395200425869, 12.318564112714729, 13.357916060133325, 13.422701664617934, 13.423079655329078, 14.218276000054065]
13 : [3.2207114491190976, 5.880605168601197, 5.880636285128348, 10.687324626207605, 10.694919355328375, 10.695369666006172, 12.318355444933479, 12.318438209338181, 13.357827321840578, 13.42256691481014, 13.422737626063736, 14.217181711715655]
14 : [3.2207114491191002, 5.880605168601201, 5.880636285128369, 10.687324593708732, 10.694919342793538, 10.695369588260178, 12.318312786647098, 12.318422842923537, 13.357786931648404, 13.422492699877509, 13.422592438777416, 14.216575645329565]
15 : [3.2207114491190976, 5.880605168601201, 5.880636285128268, 10.687324586071423, 10.694919339910848, 10.695369569924118, 12.31829531692919, 12.318419963920492, 13.357768587808565, 13.422446971975834, 13.422537021353628, 14.216239646976591]
16 : [3.220711449119096, 5.880605168601478, 5.8806362851283485, 10.687324584274325, 10.694919339246095, 10.695369565593506, 12.318289005137704, 12.318419132006122, 13.357760264366185, 13.422421899438337, 13.422515413023588, 14.216053237293336]
17 : [3.220711449119098, 5.880605168600084, 5.8806362851284595, 10.687324583850218, 10.694919339092374, 10.695369564569484, 12.318286769948879, 12.318418857676267, 13.357756482866739, 13.422409508855477, 13.422506233294337, 14.215949616915372]
18 : [3.2207114491190953, 5.880605168601233, 5.880636285128471, 10.687324583750504, 10.694919339056977, 10.695369564326887, 12.31828597717831, 12.318418762654169, 13.35775475969623, 13.422403603392965, 13.422502129031095, 14.21589223779901]
19 : [3.220711449119095, 5.8806051686018765, 5.880636285128813, 10.68732458372701, 10.694919339047772, 10.695369564268878, 12.318285699304154, 12.318418729575358, 13.35775396184159, 13.422400755371962, 13.422500214049311, 14.21585957267932]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.220711449119095
5.8806051686018765
5.880636285128813
10.68732458372701
10.694919339047772
10.695369564268878
12.318285699304154
12.318418729575358
13.35775396184159
13.422400755371962
13.422500214049311
14.21585957267932
We copy the eigenvectors into a multi-dimensional GridFunction for visualization:
[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);