This page was generated from wta/fembem.ipynb.
FEM-BEM Coupling¶
The ngbem boundary element addon project initiated by Lucy Weggeler (see https://weggler.github.io/docu-ngsbem/intro.html) is now partly integrated into core NGSolve. Find a short and sweet introduction to the boundary element method there.
In this demo we simulate a plate capacitor on an unbounded domain.
[1]:
from ngsolve import *
from netgen.occ import *
from ngsolve.solvers import GMRes
from ngsolve.webgui import Draw
from ngsolve.bem import *
[2]:
largebox = Box ((-2,-2,-2), (2,2,2) )
eltop = Box ( (-1,-1,0.5), (1,1,1) )
elbot = Box ( (-1,-1,-1), (1,1,-0.5))
largebox.faces.name = "outer" # coupling boundary
eltop.faces.name = "topface" # Dirichlet boundary
elbot.faces.name = "botface" # Dirichlet boundary
eltop.edges.hpref = 1
elbot.edges.hpref = 1
shell = largebox-eltop-elbot # FEM domain
shell.solids.name = "air"
mesh = shell.GenerateMesh(maxh=0.8)
mesh.RefineHP(2)
ea = { "euler_angles" : (-67, 0, 110) }
Draw (mesh, clipping={"x":1, "y":0, "z":0, "dist" : 1.1}, **ea);
On the exterior domain \(\Omega^c\), the solution can be expressed by the representation formula:
where \(\gamma_0 u = u\) and \(\gamma_1 u = \frac{\partial u}{\partial n}\) are Dirichlet and Neumann traces. These traces are related by the Calderon projector
.
The \(V\), \(K\) are the single layer and double layer potential operators, and \(D\) is the hypersingular operator.
On the FEM domain we have the variational formulation
We use Calderon’s represenataion formula for the Neumann trace:
To get a closed system, we use also the first equation of the Calderon equations. To see the structure of the discretized system, the dofs are split into degrees of freedom inside \(\Omega\), and those on the boundary \(\Gamma\). The FEM matrix \(A\) is split accordingly. We see, the coupled system is symmetric, but indefinite:
Generate the finite element space for \(H^1(\Omega)\) and set the given Dirichlet boundary conditions on the surfaces of the plates:
[3]:
order = 4
fesH1 = H1(mesh, order=order, dirichlet="topface|botface")
print ("H1-ndof = ", fesH1.ndof)
H1-ndof = 90703
The finite element space \(\verb-fesH1-\) provides \(H^{\frac12}(\Gamma)\) conforming element to discretize the Dirichlet trace on the coupling boundary \(\Gamma\). However we still need \(H^{-\frac12}(\Gamma)\) conforming elements to discretize the Neumann trace of \(u\) on the coupling boundary. Here it is:
[4]:
fesL2 = SurfaceL2(mesh, order=order-1, dual_mapping=True, definedon=mesh.Boundaries("outer"))
print ("L2-ndof = ", fesL2.ndof)
L2-ndof = 4035
[5]:
fes = fesH1 * fesL2
u,dudn = fes.TrialFunction()
v,dvdn = fes.TestFunction()
a = BilinearForm(grad(u)*grad(v)*dx, check_unused=False).Assemble()
gfudir = GridFunction(fes)
gfudir.components[0].Set ( mesh.BoundaryCF( { "topface" : 1, "botface" : -1 }), BND)
f = LinearForm(fes).Assemble()
res = (f.vec - a.mat * gfudir.vec).Evaluate()
Generate the the single layer potential \(V\), double layer potential \(K\) and hypersingular operator \(D\):
[6]:
n = specialcf.normal(3)
with TaskManager():
V = LaplaceSL(dudn*ds("outer"))*dvdn*ds("outer")
K = LaplaceDL(u*ds("outer"))*dvdn*ds("outer")
D = LaplaceSL(Cross(grad(u).Trace(),n)*ds("outer"))*Cross(grad(v).Trace(),n)*ds("outer")
M = BilinearForm(u*dvdn*ds("outer"), check_unused=False).Assemble()
Setup the coupled system matrix and the right hand side:
[7]:
sym = a.mat+D.mat - (0.5*M.mat+K.mat).T - (0.5*M.mat+K.mat) - V.mat
rhs = res
bfpre = BilinearForm(grad(u)*grad(v)*dx+1e-10*u*v*dx + dudn*dvdn*ds("outer") ).Assemble()
pre = bfpre.mat.Inverse(freedofs=fes.FreeDofs(), inverse="sparsecholesky")
Compute the solution of the coupled system:
[8]:
with TaskManager():
sol_sym = GMRes(A=sym, b=rhs, pre=pre, tol=1e-6, maxsteps=200, printrates=True)
GMRES iteration 1, residual = 47.94329927058578
GMRES iteration 2, residual = 10.547738042888897
GMRES iteration 3, residual = 2.6122774443199384
GMRES iteration 4, residual = 1.9193598537427214
GMRES iteration 5, residual = 0.41513121350756055
GMRES iteration 6, residual = 0.3904448743753159
GMRES iteration 7, residual = 0.1771961861337045
GMRES iteration 8, residual = 0.1379174955636662
GMRES iteration 9, residual = 0.08865763341052565
GMRES iteration 10, residual = 0.047706297584558
GMRES iteration 11, residual = 0.04662109067782161
GMRES iteration 12, residual = 0.0449709713131908
GMRES iteration 13, residual = 0.020803869025885213
GMRES iteration 14, residual = 0.013029445657642672
GMRES iteration 15, residual = 0.012428849092473705
GMRES iteration 16, residual = 0.007375363713958368
GMRES iteration 17, residual = 0.007328671491593149
GMRES iteration 18, residual = 0.006116844119459971
GMRES iteration 19, residual = 0.00557475044309861
GMRES iteration 20, residual = 0.003669977355633894
GMRES iteration 21, residual = 0.0035919757619241885
GMRES iteration 22, residual = 0.0029943239014151887
GMRES iteration 23, residual = 0.002946929400723327
GMRES iteration 24, residual = 0.0019792679271308923
GMRES iteration 25, residual = 0.0019408664885232757
GMRES iteration 26, residual = 0.0015575489595994025
GMRES iteration 27, residual = 0.001424620445039654
GMRES iteration 28, residual = 0.0012204425120912956
GMRES iteration 29, residual = 0.0010847044561551925
GMRES iteration 30, residual = 0.0009837865749407872
GMRES iteration 31, residual = 0.0007490400520406143
GMRES iteration 32, residual = 0.0007488559796222956
GMRES iteration 33, residual = 0.0006134924989428473
GMRES iteration 34, residual = 0.0006124109584723662
GMRES iteration 35, residual = 0.0004939642689718503
GMRES iteration 36, residual = 0.00047858686155967693
GMRES iteration 37, residual = 0.00037174187506187217
GMRES iteration 38, residual = 0.00037097048973069874
GMRES iteration 39, residual = 0.0003142110252350046
GMRES iteration 40, residual = 0.00031040251745091007
GMRES iteration 41, residual = 0.00021837357943973662
GMRES iteration 42, residual = 0.0002144952440445597
GMRES iteration 43, residual = 0.00019217128045619577
GMRES iteration 44, residual = 0.00017880247627735088
GMRES iteration 45, residual = 0.00016236092090611822
GMRES iteration 46, residual = 0.00013935854238768537
GMRES iteration 47, residual = 0.00013877785896765737
GMRES iteration 48, residual = 0.00011238293925497823
GMRES iteration 49, residual = 0.00011226422927014482
GMRES iteration 50, residual = 8.692521862236174e-05
GMRES iteration 51, residual = 8.664928873177539e-05
GMRES iteration 52, residual = 7.291903341726927e-05
GMRES iteration 53, residual = 7.253473753701216e-05
GMRES iteration 54, residual = 5.7047639416880586e-05
GMRES iteration 55, residual = 4.7964544399936525e-05
GMRES iteration 56, residual = 4.6725280158655536e-05
GMRES iteration 57, residual = 3.819925844778912e-05
GMRES iteration 58, residual = 3.807476462927961e-05
GMRES iteration 59, residual = 2.8152110653082045e-05
GMRES iteration 60, residual = 2.772481584576219e-05
GMRES iteration 61, residual = 2.4337832333250192e-05
GMRES iteration 62, residual = 2.4272918464545152e-05
GMRES iteration 63, residual = 2.0368369155465598e-05
GMRES iteration 64, residual = 1.9873156140617475e-05
GMRES iteration 65, residual = 1.6038071664864372e-05
GMRES iteration 66, residual = 1.4477036685886971e-05
GMRES iteration 67, residual = 1.4163716785768528e-05
GMRES iteration 68, residual = 1.040980902325435e-05
GMRES iteration 69, residual = 1.032880447734307e-05
GMRES iteration 70, residual = 8.19011268390318e-06
GMRES iteration 71, residual = 7.817834137163861e-06
GMRES iteration 72, residual = 7.018532953529613e-06
GMRES iteration 73, residual = 5.897819846444793e-06
GMRES iteration 74, residual = 5.54547117442989e-06
GMRES iteration 75, residual = 4.159607889489691e-06
GMRES iteration 76, residual = 4.128810899126316e-06
GMRES iteration 77, residual = 3.6120160130757996e-06
GMRES iteration 78, residual = 3.3515778399246267e-06
GMRES iteration 79, residual = 2.98467750268165e-06
GMRES iteration 80, residual = 2.5627033699374074e-06
GMRES iteration 81, residual = 2.452236709671407e-06
GMRES iteration 82, residual = 2.1344262351502986e-06
GMRES iteration 83, residual = 2.0774974641588442e-06
GMRES iteration 84, residual = 1.6116735383714747e-06
GMRES iteration 85, residual = 1.586859698511938e-06
GMRES iteration 86, residual = 1.3487736015755563e-06
GMRES iteration 87, residual = 1.229643989117966e-06
GMRES iteration 88, residual = 1.18470299697138e-06
GMRES iteration 89, residual = 9.075403717622584e-07
[9]:
gfu = GridFunction(fes)
gfu.vec[:] = sol_sym + gfudir.vec
Draw(gfu.components[0], clipping={"x" : 1, "y":0, "z":0, "dist":0.0, "function" : True }, **ea, order=2);
The Neumann data:
[10]:
Draw (gfu.components[1], **ea);
References:
M. Costabel: Principles of boundary element methods
[ ]: