This page was generated from wta/fembem.ipynb.
FEM-BEM Coupling¶
The ngbem boundary element addon project initiated by Lucy Weggler (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 representation 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 = 53.25532390083439
GMRES iteration 2, residual = 11.2040204480726
GMRES iteration 3, residual = 2.624791062664937
GMRES iteration 4, residual = 1.9538056658117877
GMRES iteration 5, residual = 0.42240261497863846
GMRES iteration 6, residual = 0.39752546195918165
GMRES iteration 7, residual = 0.18178805750932725
GMRES iteration 8, residual = 0.14276785948635629
GMRES iteration 9, residual = 0.0937913443709492
GMRES iteration 10, residual = 0.049119386767396085
GMRES iteration 11, residual = 0.04817369557264094
GMRES iteration 12, residual = 0.04626231007647245
GMRES iteration 13, residual = 0.022592067754033572
GMRES iteration 14, residual = 0.013683109246967261
GMRES iteration 15, residual = 0.013135234255366057
GMRES iteration 16, residual = 0.007865740878871107
GMRES iteration 17, residual = 0.007845096076303341
GMRES iteration 18, residual = 0.00651089135158481
GMRES iteration 19, residual = 0.006010697822952032
GMRES iteration 20, residual = 0.0039987796493259255
GMRES iteration 21, residual = 0.003942711715359908
GMRES iteration 22, residual = 0.003295957953428529
GMRES iteration 23, residual = 0.0032676766805470564
GMRES iteration 24, residual = 0.0022444261380229224
GMRES iteration 25, residual = 0.0021980521468972936
GMRES iteration 26, residual = 0.0017818626498373594
GMRES iteration 27, residual = 0.0016201441947980683
GMRES iteration 28, residual = 0.0014081996850076701
GMRES iteration 29, residual = 0.0012630115064504615
GMRES iteration 30, residual = 0.0011495136484311603
GMRES iteration 31, residual = 0.0008726236597544789
GMRES iteration 32, residual = 0.0008724250361451755
GMRES iteration 33, residual = 0.0007075491858118994
GMRES iteration 34, residual = 0.0007065256863391315
GMRES iteration 35, residual = 0.0005653262821289839
GMRES iteration 36, residual = 0.0005492501947689849
GMRES iteration 37, residual = 0.0004279646222697831
GMRES iteration 38, residual = 0.00042713837032181404
GMRES iteration 39, residual = 0.00035733527554955216
GMRES iteration 40, residual = 0.00035390109626594275
GMRES iteration 41, residual = 0.0002495237553336717
GMRES iteration 42, residual = 0.00024410429736716914
GMRES iteration 43, residual = 0.00021991313007674115
GMRES iteration 44, residual = 0.0002000934813150768
GMRES iteration 45, residual = 0.00018200105660540636
GMRES iteration 46, residual = 0.00015495417483971265
GMRES iteration 47, residual = 0.0001542437226099992
GMRES iteration 48, residual = 0.00012348603892590028
GMRES iteration 49, residual = 0.00012315030606799545
GMRES iteration 50, residual = 9.585976159296845e-05
GMRES iteration 51, residual = 9.550861833070232e-05
GMRES iteration 52, residual = 8.056739654562017e-05
GMRES iteration 53, residual = 8.003748554715034e-05
GMRES iteration 54, residual = 6.259698896293743e-05
GMRES iteration 55, residual = 5.303426414165452e-05
GMRES iteration 56, residual = 5.179762429389781e-05
GMRES iteration 57, residual = 4.21516737945128e-05
GMRES iteration 58, residual = 4.206264504642249e-05
GMRES iteration 59, residual = 3.113641406451295e-05
GMRES iteration 60, residual = 3.0632027861170416e-05
GMRES iteration 61, residual = 2.6975332675865132e-05
GMRES iteration 62, residual = 2.689126482748609e-05
GMRES iteration 63, residual = 2.2511919799988028e-05
GMRES iteration 64, residual = 2.18562869028524e-05
GMRES iteration 65, residual = 1.7843268607644223e-05
GMRES iteration 66, residual = 1.5987667151398848e-05
GMRES iteration 67, residual = 1.569849637156188e-05
GMRES iteration 68, residual = 1.1403074672788014e-05
GMRES iteration 69, residual = 1.129215347997951e-05
GMRES iteration 70, residual = 9.159661550293455e-06
GMRES iteration 71, residual = 8.67352584058982e-06
GMRES iteration 72, residual = 7.847270993349445e-06
GMRES iteration 73, residual = 6.450385819630367e-06
GMRES iteration 74, residual = 6.112145874509574e-06
GMRES iteration 75, residual = 4.6125899808999125e-06
GMRES iteration 76, residual = 4.567463468081935e-06
GMRES iteration 77, residual = 3.9461772713410034e-06
GMRES iteration 78, residual = 3.6166919014674607e-06
GMRES iteration 79, residual = 3.257703514991642e-06
GMRES iteration 80, residual = 2.7764491314899508e-06
GMRES iteration 81, residual = 2.68545682068154e-06
GMRES iteration 82, residual = 2.324963188461048e-06
GMRES iteration 83, residual = 2.265725789804039e-06
GMRES iteration 84, residual = 1.7588462876626033e-06
GMRES iteration 85, residual = 1.7201161873607395e-06
GMRES iteration 86, residual = 1.4691020278714767e-06
GMRES iteration 87, residual = 1.3378423697587331e-06
GMRES iteration 88, residual = 1.2844911843075858e-06
GMRES iteration 89, residual = 9.865182588579183e-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:
Costabel: Principles of boundary element methods, Computer Physics Reports 6 (1987), 243-274