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.229093261124893, 22.636447510336502, 38.75912681883203, 56.956883723608975, 64.68904673925014, 71.6151064480173, 76.89311292956687, 86.36950975873258, 90.92730267581186, 99.90890224396443, 108.07709801667636, 123.53078334101778]
1 : [3.2310126754209523, 6.086234263821845, 6.406899224009433, 12.054533473119081, 12.672421029218627, 13.138599686199665, 14.490032249923082, 17.723681706101832, 18.662584396885407, 19.346120605276234, 23.99916096097902, 25.45185224014425]
2 : [3.220379348186355, 5.886623822608376, 5.9055484292942, 10.853747390675123, 10.901287970226807, 11.033338300564056, 12.490608610067696, 13.713193967340759, 14.184813087546734, 15.34867454607145, 16.529828079360545, 17.964540346847414]
3 : [3.2202534507267284, 5.8807687086776, 5.881908488028258, 10.709133420847643, 10.726052065985003, 10.778656219151973, 12.345960396984362, 12.760676043164917, 13.760281355782181, 14.018326043605038, 14.60771851576606, 16.592214147527923]
4 : [3.220251466900592, 5.8804942799819875, 5.880556917690769, 10.689894953489384, 10.698983267280859, 10.718281105564913, 12.323621310867512, 12.515134575121259, 13.530915636363298, 13.646352490523334, 14.013638403802885, 15.844042099148375]
5 : [3.2202514327806284, 5.8804771145376495, 5.8804800232639325, 10.68685103655768, 10.694700891024581, 10.70089040706049, 12.319109793664754, 12.416240501269446, 13.409477889956266, 13.552567887121295, 13.749216311030453, 15.246452464635556]
6 : [3.220251432184987, 5.880473890511279, 5.880477843318854, 10.686161008731316, 10.694032876757696, 10.695820538591057, 12.318002400652759, 12.3651089870403, 13.375722155078371, 13.48849701735362, 13.613981824571937, 14.813746362848407]
7 : [3.2202514321746256, 5.880473676484486, 5.88047775139942, 10.685969287196592, 10.693915072917022, 10.69441539784449, 12.31769621979759, 12.338610207895798, 13.36511260880237, 13.45294954020169, 13.53166272867435, 14.548118344552222]
8 : [3.220251432174444, 5.880473664772775, 5.880477746015269, 10.685917731763464, 10.693892108137462, 10.694043457650597, 12.31760466508522, 12.326098068777178, 13.3608783849757, 13.435960446999431, 13.480566199244945, 14.398036524701988]
9 : [3.2202514321744413, 5.880473664135085, 5.880477745705955, 10.685904872915472, 10.69388727531341, 10.693949433865974, 12.317575537836486, 12.320797130508218, 13.358877986595928, 13.428258101674936, 13.451525405468448, 14.31573510063106]
10 : [3.2202514321744395, 5.880473664100313, 5.880477745688496, 10.685901792194153, 10.693886175009903, 10.69392645307327, 12.317565160998528, 12.31871575398383, 13.35789296654265, 13.424793973353353, 13.43629868752426, 14.270543557391065]
11 : [3.2202514321744404, 5.880473664098417, 5.880477745687527, 10.685901066925013, 10.693885916583637, 10.693920952758688, 12.31755883167828, 12.317939833444427, 13.357414569382916, 13.423228033225236, 13.42874749567931, 14.24562647871796]
12 : [3.2202514321744427, 5.880473664098322, 5.880477745687489, 10.685900897346412, 10.69388585684496, 10.693919648675292, 12.317545562860564, 12.317668126968062, 13.35718843317472, 13.422515873520494, 13.425120082974328, 14.231830187509944]
13 : [3.2202514321744373, 5.880473664098275, 5.880477745687481, 10.685900857789525, 10.693885843152305, 10.693919341041697, 12.317512863841781, 12.317598526759777, 13.357083768726474, 13.422189464804868, 13.423410985776053, 14.224178995663326]
14 : [3.2202514321744427, 5.8804736640983, 5.880477745687519, 10.685900848564232, 10.69388584001337, 10.693919268635817, 12.317488504452646, 12.317586425270223, 13.357035967545434, 13.422036763990539, 13.422616404236521, 14.219930900581216]
15 : [3.220251432174442, 5.880473664098334, 5.880477745687461, 10.685900846411485, 10.693885839291523, 10.693919251611323, 12.317478505944027, 12.317583476615066, 13.357014279082266, 13.421959846817396, 13.422254221179092, 14.217570862301452]
16 : [3.22025143217444, 5.880473664098337, 5.880477745687452, 10.685900845908783, 10.693885839124617, 10.69391924760784, 12.317474827888931, 12.317582558768269, 13.357004464387918, 13.421913971166449, 13.422096967502354, 14.216259089464431]
17 : [3.220251432174442, 5.880473664098281, 5.880477745687329, 10.68590084579083, 10.693885839086432, 10.693919246661174, 12.317473489679063, 12.317582243125798, 13.357000031486901, 13.421883314666328, 13.42203208293561, 14.215514142521581]
18 : [3.2202514321744435, 5.88047366409813, 5.880477745687421, 10.685900845763546, 10.69388583907776, 10.693919246443958, 12.317473032417864, 12.317582138197803, 13.35699803116317, 13.421865521592197, 13.422006909516572, 14.215109177038045]
19 : [3.2202514321744435, 5.880473664098602, 5.880477745686978, 10.68590084575728, 10.693885839075946, 10.6939192463937, 12.31747287448947, 12.317582102250633, 13.356997106687391, 13.42185646500229, 13.421996409128658, 14.214888066415073]
[6]:
print ("Eigenvalues")
for lam in evals:
print (lam)
Eigenvalues
3.2202514321744435
5.880473664098602
5.880477745686978
10.68590084575728
10.693885839075946
10.6939192463937
12.31747287448947
12.317582102250633
13.356997106687391
13.42185646500229
13.421996409128658
14.214888066415073
[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);
[ ]:
[ ]: