This page was generated from unit-11.2-bem-Laplace/Laplace_DtN_direct.ipynb.
11.2.2. Dirichlet Laplace Direct Method¶
keys: homogeneous Dirichlet bvp, double and single layer potential, unknown Neumann data
[1]:
from netgen.occ import *
from ngsolve import *
from ngsolve.webgui import Draw
from ngsolve.bem import *
from ngsolve.solvers import CG
Consider the Dirichlet boundary value problem
Let us choose the following ansatz for the solution \(u\in H^1(\Omega)\) (direct ansatz)
and solve for the Neumann data \(u_1 \in H^{-\frac12}(\Gamma)\) by the boundary element method, i.e.,
Define the geometry \(\Omega \subset \mathbb R^3\) and create a mesh:
[2]:
sp = Sphere( (0,0,0), 1)
mesh = Mesh( OCCGeometry(sp).GenerateMesh(maxh=0.2)).Curve(4)
Create the finite element spaces for \(H^{-\frac12}(\Gamma)\) and \(H^{\frac12}(\Gamma)\) according to the given mesh:
[3]:
fesL2 = SurfaceL2(mesh, order=3, dual_mapping=True)
u,v = fesL2.TnT()
fesH1 = H1(mesh, order=4)
uH1,vH1 = fesH1.TnT()
print ("ndofL2 = ", fesL2.ndof, "ndof H1 = ", fesH1.ndof)
ndofL2 = 7220 ndof H1 = 21241
Compute the interpolation of exact Dirichlet data \(u_0\) in finite element space:
[4]:
uexa = 1/ sqrt( (x-1)**2 + (y-1)**2 + (z-1)**2 )
u0 = GridFunction(fesH1)
u0.Interpolate (uexa)
Draw (u0, mesh, draw_vol=False, order=3);
The discretisation of the above variational formulation leads to a system of linear equations, ie
where the linear operators are as follows
\(\mathrm{V}\) is the single layer operator. \(\mathrm V\) is regular and symmetric.
\(\mathrm{M}\) is a mass matrix.
\(\mathrm{K}\) is the double layer operator.
We approximate the linear operators as hmatrices and solve for the Neumann data \(u_1\) with an iterative solver:
[5]:
u1 = GridFunction(fesL2)
pre = BilinearForm(u*v*ds, diagonal=True).Assemble().mat.Inverse()
with TaskManager():
# V = SingleLayerPotentialOperator(fesL2, intorder=12)
V = LaplaceSL(u*ds)*v*ds
M = BilinearForm( uH1 * v.Trace() * ds(bonus_intorder=3)).Assemble()
# K = DoubleLayerPotentialOperator(fesH1, fesL2, intorder=12)
K = LaplaceDL(uH1*ds)*v*ds
rhs = ( (0.5 * M.mat + K.mat)*u0.vec).Evaluate()
CG(mat = V.mat, pre=pre, rhs = rhs, sol=u1.vec, tol=1e-8, maxsteps=50, initialize=False, printrates=True)
CG iteration 1, residual = 0.268824422385237
CG iteration 2, residual = 0.06553516843504774
CG iteration 3, residual = 0.015537002782918577
CG iteration 4, residual = 0.003677573752435783
CG iteration 5, residual = 0.0009541450800464178
CG iteration 6, residual = 0.0013667099821510966
CG iteration 7, residual = 0.00019656709721021314
CG iteration 8, residual = 5.780268069991614e-05
CG iteration 9, residual = 4.6356679882298885e-05
CG iteration 10, residual = 3.4000058581407594e-05
CG iteration 11, residual = 1.7052395938329566e-05
CG iteration 12, residual = 9.985434752481992e-06
CG iteration 13, residual = 4.681261151395376e-06
CG iteration 14, residual = 7.113361208055111e-06
CG iteration 15, residual = 2.390471392171982e-06
CG iteration 16, residual = 2.086061915968112e-06
CG iteration 17, residual = 1.9082985895411976e-06
CG iteration 18, residual = 1.7798462780683814e-06
CG iteration 19, residual = 9.154756115315381e-07
CG iteration 20, residual = 6.251931615234809e-07
CG iteration 21, residual = 5.053982035136815e-07
CG iteration 22, residual = 5.253261431183349e-07
CG iteration 23, residual = 4.98195803609625e-07
CG iteration 24, residual = 3.8132848120721463e-07
CG iteration 25, residual = 2.0579513254762215e-07
CG iteration 26, residual = 1.008299517958544e-07
CG iteration 27, residual = 8.453288958000489e-08
CG iteration 28, residual = 5.611856078330582e-08
CG iteration 29, residual = 9.92561765797944e-08
CG iteration 30, residual = 8.751468006852906e-08
CG iteration 31, residual = 4.6026908472785213e-08
CG iteration 32, residual = 2.733942478943265e-08
CG iteration 33, residual = 2.017477901274625e-08
CG iteration 34, residual = 2.555118265968166e-08
CG iteration 35, residual = 1.3194208556734764e-08
CG iteration 36, residual = 7.54468441114163e-09
CG iteration 37, residual = 2.266193193229984e-08
CG iteration 38, residual = 5.114872303569123e-09
CG iteration 39, residual = 6.478150293173427e-09
CG iteration 40, residual = 4.45093472048749e-09
CG iteration 41, residual = 2.4100121389477146e-09
[6]:
Draw (u1, mesh, draw_vol=False, order=3);
Let’s have a look at the exact Neumann data and compute the error of the numerical solution:
[7]:
graduexa = CF( (uexa.Diff(x), uexa.Diff(y), uexa.Diff(z)) )
n = specialcf.normal(3)
u1exa = graduexa*n
Draw (u1exa, mesh, draw_vol=False, order=3);
print ("L2-error =", sqrt (Integrate ( (u1exa-u1)**2, mesh, BND)))
L2-error = 0.0002505947168448222
[ ]:
[ ]: