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/ngbem/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.94329927058722
GMRes iteration 2, residual = 10.539369746932412
GMRes iteration 3, residual = 2.611587156531043
GMRes iteration 4, residual = 1.9195757191366862
GMRes iteration 5, residual = 0.4166916580569569
GMRes iteration 6, residual = 0.39297352574755945
GMRes iteration 7, residual = 0.17795761889223363
GMRes iteration 8, residual = 0.13816526015255906
GMRes iteration 9, residual = 0.08671805759892859
GMRes iteration 10, residual = 0.047060025937755136
GMRes iteration 11, residual = 0.04534479530159345
GMRes iteration 12, residual = 0.044421919137264954
GMRes iteration 13, residual = 0.016701502543282554
GMRes iteration 14, residual = 0.012683670900522562
GMRes iteration 15, residual = 0.011115768703934971
GMRes iteration 16, residual = 0.007051225983238416
GMRes iteration 17, residual = 0.006714580260454154
GMRes iteration 18, residual = 0.005947766472094048
GMRes iteration 19, residual = 0.004793409918441886
GMRes iteration 20, residual = 0.0035486000829411594
GMRes iteration 21, residual = 0.003176412477059868
GMRes iteration 22, residual = 0.002826216820732495
GMRes iteration 23, residual = 0.002465704148832201
GMRes iteration 24, residual = 0.0018632042929533194
GMRes iteration 25, residual = 0.001847176530930495
GMRes iteration 26, residual = 0.0013478969077569344
GMRes iteration 27, residual = 0.0013444294386051325
GMRes iteration 28, residual = 0.0010720995981459247
GMRes iteration 29, residual = 0.0010545592009659677
GMRes iteration 30, residual = 0.0007620541684927238
GMRes iteration 31, residual = 0.0006873897895081102
GMRes iteration 32, residual = 0.0006388026388088008
GMRes iteration 33, residual = 0.000552268268736385
GMRes iteration 34, residual = 0.00048353717643769917
GMRes iteration 35, residual = 0.0004479298779359073
GMRes iteration 36, residual = 0.00036474070572050635
GMRes iteration 37, residual = 0.00034678840790482044
GMRes iteration 38, residual = 0.0003021956192011616
GMRes iteration 39, residual = 0.0002885819304191116
GMRes iteration 40, residual = 0.00023060160387735056
GMRes iteration 41, residual = 0.00019995191091016728
GMRes iteration 42, residual = 0.0001913877852517723
GMRes iteration 43, residual = 0.00015891304707707022
GMRes iteration 44, residual = 0.00015494149101115984
GMRes iteration 45, residual = 0.0001238328478764619
GMRes iteration 46, residual = 0.00012381191727581489
GMRes iteration 47, residual = 9.622952868397373e-05
GMRes iteration 48, residual = 9.349714068590122e-05
GMRes iteration 49, residual = 7.689469008047396e-05
GMRes iteration 50, residual = 7.458496716269779e-05
GMRes iteration 51, residual = 6.38233573591704e-05
GMRes iteration 52, residual = 6.236932128139821e-05
GMRes iteration 53, residual = 4.956280506786976e-05
GMRes iteration 54, residual = 4.124180005570895e-05
GMRes iteration 55, residual = 4.01834222090339e-05
GMRes iteration 56, residual = 3.204919970388245e-05
GMRes iteration 57, residual = 3.1847116979493416e-05
GMRes iteration 58, residual = 2.4094077019572218e-05
GMRes iteration 59, residual = 2.4009466412291937e-05
GMRes iteration 60, residual = 2.1199089884730496e-05
GMRes iteration 61, residual = 2.1157663439428206e-05
GMRes iteration 62, residual = 1.7273837460548715e-05
GMRes iteration 63, residual = 1.7055522474978357e-05
GMRes iteration 64, residual = 1.376453486105454e-05
GMRes iteration 65, residual = 1.2844384119091235e-05
GMRes iteration 66, residual = 1.1069323023451232e-05
GMRes iteration 67, residual = 8.71689928346959e-06
GMRes iteration 68, residual = 8.571925858913926e-06
GMRes iteration 69, residual = 6.935376757756931e-06
GMRes iteration 70, residual = 6.934584351983885e-06
GMRes iteration 71, residual = 5.211288210715863e-06
GMRes iteration 72, residual = 5.074432180938133e-06
GMRes iteration 73, residual = 4.230376563557623e-06
GMRes iteration 74, residual = 3.6632106274705874e-06
GMRes iteration 75, residual = 3.5897665275178723e-06
GMRes iteration 76, residual = 2.8153940174936834e-06
GMRes iteration 77, residual = 2.815387753647172e-06
GMRes iteration 78, residual = 2.2671760541582285e-06
GMRes iteration 79, residual = 2.2425121674392784e-06
GMRes iteration 80, residual = 1.971451542122009e-06
GMRes iteration 81, residual = 1.9168033183581094e-06
GMRes iteration 82, residual = 1.7676672288830176e-06
GMRes iteration 83, residual = 1.3685428019818876e-06
GMRes iteration 84, residual = 1.3588960356441056e-06
GMRes iteration 85, residual = 1.076962120601372e-06
GMRes iteration 86, residual = 1.0765812591929904e-06
GMRes iteration 87, residual = 8.757127763472146e-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
[ ]: