This page was generated from unit-2.1.4-bddc/bddc.ipynb.
2.1.4 Element-wise BDDC Preconditioner¶
The element-wise BDDC (Balancing Domain Decomposition preconditioner with Constraints) preconditioner in NGSolve is a good general purpose preconditioner that works well both in the shared memory parallel mode as well as in distributed memory mode. In this tutorial, we discuss this preconditioner, related built-in options, and customization from python.
Let us start with a simple description of the element-wise BDDC in the context of Lagrange finite element space \(V\). Here the BDDC preconditioner is constructed on an auxiliary space \(\widetilde{V}\) obtained by connecting only element vertices (leaving edge and face shape functions discontinuous). Although larger, the auxiliary space allows local elimination of edge and face variables. Hence an analogue of the original matrix \(A\) on this space, named \(\widetilde A\), is less expensive to invert. This inverse is used to construct a preconditioner for \(A\) as follows:
Here, \(R\) is the averaging operator for the discontinuous edge and face variables.
To construct a general purpose BDDC preconditioner, NGSolve generalizes this idea to all its finite element spaces by a classification of degrees of freedom. Dofs are classified into (condensable) LOCAL_DOFs that we saw in 1.4 and a remainder that includes these types:
WIREBASKET_DOFINTERFACE_DOFThe original finite element space \(V\) is obtained by requiring conformity of both the above types of dofs, while the auxiliary space \(\widetilde{V}\) is obtained by requiring conformity of WIREBASKET_DOFs only.
Here is a figure of a typical function in the default \(\widetilde{V}\) (and the code to generate this is at the end of this tutorial) when \(V\) is the Lagrange space:
[1]:
from ngsolve import *
from ngsolve.webgui import Draw
from ngsolve.la import EigenValues_Preconditioner
SetHeapSize(100*1000*1000)
[2]:
mesh = Mesh(unit_cube.GenerateMesh(maxh=0.5))
# mesh = Mesh(unit_square.GenerateMesh(maxh=0.5))
Built-in options¶
Let us define a simple function to study how the spectrum of the preconditioned matrix changes with various options.
Effect of condensation¶
[3]:
def TestPreconditioner (p, condense=False, **args):
fes = H1(mesh, order=p, **args)
u,v = fes.TnT()
a = BilinearForm(fes, eliminate_internal=condense)
a += grad(u)*grad(v)*dx + u*v*dx
c = Preconditioner(a, "bddc")
a.Assemble()
return EigenValues_Preconditioner(a.mat, c.mat)
[4]:
lams = TestPreconditioner(5)
print (lams[0:3], "...\n", lams[-3:])
1.00049
1.03541
1.09976
...
4.52912
4.60188
4.79194
Here is the effect of static condensation on the BDDC preconditioner.
[5]:
lams = TestPreconditioner(5, condense=True)
print (lams[0:3], "...\n", lams[-3:])
1.00023
1.02753
1.08363
...
4.06546
4.12581
4.22957
Tuning the auxiliary space¶
Next, let us study the effect of a few built-in flags for finite element spaces that are useful for tweaking the behavior of the BDDC preconditioner. The effect of these flags varies in two (2D) and three dimensions (3D), e.g.,
wb_fulledges=True: This option keeps all edge-dofs conforming (i.e. they are markedWIREBASKET_DOFs). This option is only meaningful in 3D. If used in 2D, the preconditioner becomes a direct solver.wb_withedges=True: This option keeps only the first edge-dof conforming (i.e., the first edge-dof is markedWIREBASKET_DOFand the remaining edge-dofs are markedINTERFACE_DOFs).
The complete situation is a bit more complex due to the fact these options can take the three values True, False, or Undefined, the two options can be combined, and the space dimension can be 2 or 3. The default value of these flags in NGSolve is Undefined. Here is a table with the summary of the effect of these options:
wb_fulledges |
wb_withedges |
2D |
3D |
|---|---|---|---|
True |
any value |
all |
all |
False/Undefined |
Undefined |
none |
first |
False/Undefined |
False |
none |
none |
False/Undefined |
True |
first |
first |
An entry \(X \in\) {all, none, first} of the last two columns is to be read as follows: \(X\) of the edge-dofs is(are) WIREBASKET_DOF(s).
Here is an example of the effect of one of these flag values.
[6]:
lams = TestPreconditioner(5, condense=True,
wb_withedges=False)
print (lams[0:3], "...\n", lams[-3:])
1.00106
1.07034
1.22031
...
25.4058
25.406
26.9095
Clearly, when moving from the default case (where the first of the edge dofs are wire basket dofs) to the case (where none of the edge dofs are wire basket dofs), the conditioning became less favorable.
Customize¶
From within python, we can change the types of degrees of freedom of finite element spaces, thus affecting the behavior of the BDDC preconditioner.
To depart from the default and commit the first two edge dofs to wire basket, we perform the next steps:
[7]:
fes = H1(mesh, order=10)
u,v = fes.TnT()
for ed in mesh.edges:
dofs = fes.GetDofNrs(ed)
for d in dofs:
fes.SetCouplingType(d, COUPLING_TYPE.INTERFACE_DOF)
# Set the first two edge dofs to be conforming
fes.SetCouplingType(dofs[0], COUPLING_TYPE.WIREBASKET_DOF)
fes.SetCouplingType(dofs[1], COUPLING_TYPE.WIREBASKET_DOF)
a = BilinearForm(fes, eliminate_internal=True)
a += grad(u)*grad(v)*dx + u*v*dx
c = Preconditioner(a, "bddc")
a.Assemble()
lams=EigenValues_Preconditioner(a.mat, c.mat)
max(lams)/min(lams)
[7]:
9.989385160511771
This is a slight improvement from the default.
[8]:
lams = TestPreconditioner (10, condense=True)
max(lams)/min(lams)
[8]:
13.974958344243465
Combine BDDC with AMG for large problems¶
coarsetype=h1amg flag, we can ask BDDC to replace \({\,\widetilde{A}\,}^{-1}\) by an Algebraic MultiGrid (AMG) preconditioner. Since NGSolve’s h1amg is well-suitedwb_withedges=False to ensure that \(\widetilde{A}\) is made solely with vertex unknowns.[9]:
p = 5
mesh = Mesh(unit_cube.GenerateMesh(maxh=0.05))
fes = H1(mesh, order=p, dirichlet="left|bottom|back",
wb_withedges=False)
print("NDOF = ", fes.ndof)
u,v = fes.TnT()
a = BilinearForm(fes)
a += grad(u)*grad(v)*dx
f = LinearForm(fes)
f += v*dx
with TaskManager():
pre = Preconditioner(a, "bddc", coarsetype="h1amg")
a.Assemble()
f.Assemble()
gfu = GridFunction(fes)
solvers.CG(mat=a.mat, rhs=f.vec, sol=gfu.vec,
pre=pre, maxsteps=500)
Draw(gfu)
NDOF = 746336
CG iteration 1, residual = 0.7291770014214837
CG iteration 2, residual = 0.3085825766635307
CG iteration 3, residual = 0.2751732227805951
CG iteration 4, residual = 0.3147145873898307
CG iteration 5, residual = 0.32591310046298794
CG iteration 6, residual = 0.23576504582618538
CG iteration 7, residual = 0.19398509258740415
CG iteration 8, residual = 0.1717230096131236
CG iteration 9, residual = 0.12859873356540685
CG iteration 10, residual = 0.09373157198121916
CG iteration 11, residual = 0.06655712957879709
CG iteration 12, residual = 0.05174938893736765
CG iteration 13, residual = 0.041724157511091625
CG iteration 14, residual = 0.032023490025174406
CG iteration 15, residual = 0.02426903728316706
CG iteration 16, residual = 0.018659350366408735
CG iteration 17, residual = 0.01492520278517522
CG iteration 18, residual = 0.011465515055235038
CG iteration 19, residual = 0.008563421986448065
CG iteration 20, residual = 0.00651071780733211
CG iteration 21, residual = 0.0049904387622430905
CG iteration 22, residual = 0.003885537772120183
CG iteration 23, residual = 0.002883633564281429
CG iteration 24, residual = 0.002195900457874435
CG iteration 25, residual = 0.0016985067526945996
CG iteration 26, residual = 0.0013046513241800034
CG iteration 27, residual = 0.0010193922821632258
CG iteration 28, residual = 0.0007914753132771894
CG iteration 29, residual = 0.0006101146125643506
CG iteration 30, residual = 0.00046837784144273056
CG iteration 31, residual = 0.0003600181111327305
CG iteration 32, residual = 0.00027050436360882585
CG iteration 33, residual = 0.00020845002552513208
CG iteration 34, residual = 0.00016362882206070694
CG iteration 35, residual = 0.00013051706904820923
CG iteration 36, residual = 0.00012213702138131084
CG iteration 37, residual = 9.098464093890813e-05
CG iteration 38, residual = 6.630761705143061e-05
CG iteration 39, residual = 5.0896799587065425e-05
CG iteration 40, residual = 3.8514392245814175e-05
CG iteration 41, residual = 2.9258567725196725e-05
CG iteration 42, residual = 2.2679795984042047e-05
CG iteration 43, residual = 1.781557889084954e-05
CG iteration 44, residual = 1.5805047637213956e-05
CG iteration 45, residual = 1.2775699287474432e-05
CG iteration 46, residual = 8.997618273072435e-06
CG iteration 47, residual = 6.7467288467436305e-06
CG iteration 48, residual = 5.2835677235457065e-06
CG iteration 49, residual = 4.083458289915947e-06
CG iteration 50, residual = 3.1394503351718843e-06
CG iteration 51, residual = 2.428470362790334e-06
CG iteration 52, residual = 1.872196307023379e-06
CG iteration 53, residual = 1.4390437175799632e-06
CG iteration 54, residual = 1.0843558896409948e-06
CG iteration 55, residual = 8.218784873748478e-07
CG iteration 56, residual = 6.348404560778514e-07
CG iteration 57, residual = 4.888231988553826e-07
CG iteration 58, residual = 3.746044440606221e-07
CG iteration 59, residual = 2.914328296476296e-07
CG iteration 60, residual = 2.2724318081562071e-07
CG iteration 61, residual = 1.7148245586131917e-07
CG iteration 62, residual = 1.3154782724723392e-07
CG iteration 63, residual = 1.0586488652536403e-07
CG iteration 64, residual = 1.0054010745532162e-07
CG iteration 65, residual = 7.617980848259125e-08
CG iteration 66, residual = 5.494271018914366e-08
CG iteration 67, residual = 4.227225820182271e-08
CG iteration 68, residual = 3.219763806851422e-08
CG iteration 69, residual = 2.4618093774996745e-08
CG iteration 70, residual = 1.8757473727649062e-08
CG iteration 71, residual = 1.447643860682407e-08
CG iteration 72, residual = 1.1214541699365544e-08
CG iteration 73, residual = 8.530321100556101e-09
CG iteration 74, residual = 6.567902303353336e-09
CG iteration 75, residual = 4.990683240247259e-09
CG iteration 76, residual = 3.861953341327288e-09
CG iteration 77, residual = 3.123068467095906e-09
CG iteration 78, residual = 2.6204003376339094e-09
CG iteration 79, residual = 2.1470901041364766e-09
CG iteration 80, residual = 1.715465414024858e-09
CG iteration 81, residual = 1.3377639937777669e-09
CG iteration 82, residual = 1.0096417350559871e-09
CG iteration 83, residual = 7.720635898898706e-10
CG iteration 84, residual = 5.898285835185975e-10
CG iteration 85, residual = 4.5832665517629297e-10
CG iteration 86, residual = 3.5513081201645244e-10
CG iteration 87, residual = 2.678322149513722e-10
CG iteration 88, residual = 2.0437926227454538e-10
CG iteration 89, residual = 1.5804241421139222e-10
CG iteration 90, residual = 1.2144174167600618e-10
CG iteration 91, residual = 9.34686570474984e-11
CG iteration 92, residual = 7.952877124997442e-11
CG iteration 93, residual = 7.455890048075098e-11
CG iteration 94, residual = 5.042176606462696e-11
CG iteration 95, residual = 3.7410851034266173e-11
CG iteration 96, residual = 2.874480557131593e-11
CG iteration 97, residual = 2.2250393754663573e-11
CG iteration 98, residual = 1.749360827794464e-11
CG iteration 99, residual = 1.3959440809988358e-11
CG iteration 100, residual = 1.1021153206831983e-11
CG iteration 101, residual = 8.255815684488761e-12
CG iteration 102, residual = 6.274450065774157e-12
CG iteration 103, residual = 4.829935767030705e-12
CG iteration 104, residual = 3.703880488413409e-12
CG iteration 105, residual = 2.824824338479877e-12
CG iteration 106, residual = 2.1334565434923505e-12
CG iteration 107, residual = 1.6143114203967084e-12
CG iteration 108, residual = 1.2253717265990682e-12
CG iteration 109, residual = 9.370026901374162e-13
CG iteration 110, residual = 7.113470631968736e-13
[9]:
WebGLScene
Postscript¶
By popular demand, here is the code to draw the figure found at the beginning of this tutorial:
[10]:
from netgen.geom2d import unit_square
mesh = Mesh(unit_square.GenerateMesh(maxh=0.1))
fes_ho = Discontinuous(H1(mesh, order=10))
fes_lo = H1(mesh, order=1, dirichlet=".*")
fes_lam = Discontinuous(H1(mesh, order=1))
fes = fes_ho*fes_lo*fes_lam
uho, ulo, lam = fes.TrialFunction()
a = BilinearForm(fes)
a += Variation(0.5 * grad(uho)*grad(uho)*dx
- 1*uho*dx
+ (uho-ulo)*lam*dx(element_vb=BBND))
gfu = GridFunction(fes)
solvers.Newton(a=a, u=gfu)
Draw(gfu.components[0],deformation=True, settings={"camera": {"transformations": [{"type": "rotateX", "angle": -45}]}})
Newton iteration 0
err = 0.39346141669995033
Newton iteration 1
err = 2.4388275071858333e-15
[10]:
WebGLScene