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.7291770014215784
CG iteration 2, residual = 0.30858257666354216
CG iteration 3, residual = 0.27517322278058215
CG iteration 4, residual = 0.3147145873900698
CG iteration 5, residual = 0.32591310046297717
CG iteration 6, residual = 0.23576504582622948
CG iteration 7, residual = 0.19398509258789606
CG iteration 8, residual = 0.17172300961307127
CG iteration 9, residual = 0.1285987335651473
CG iteration 10, residual = 0.09373157198119805
CG iteration 11, residual = 0.06655712957882566
CG iteration 12, residual = 0.051749388937386294
CG iteration 13, residual = 0.04172415751111569
CG iteration 14, residual = 0.03202349002518552
CG iteration 15, residual = 0.024269037283169297
CG iteration 16, residual = 0.01865935036642489
CG iteration 17, residual = 0.014925202785187122
CG iteration 18, residual = 0.011465515055230748
CG iteration 19, residual = 0.008563421986448478
CG iteration 20, residual = 0.006510717807340589
CG iteration 21, residual = 0.004990438762250535
CG iteration 22, residual = 0.003885537772119489
CG iteration 23, residual = 0.0028836335642811904
CG iteration 24, residual = 0.002195900457876685
CG iteration 25, residual = 0.0016985067526955147
CG iteration 26, residual = 0.0013046513241750353
CG iteration 27, residual = 0.0010193922821185107
CG iteration 28, residual = 0.0007914753128650501
CG iteration 29, residual = 0.0006101146087739969
CG iteration 30, residual = 0.0004683778035261513
CG iteration 31, residual = 0.00036001773248226296
CG iteration 32, residual = 0.00027050007451141073
CG iteration 33, residual = 0.00020839920490566628
CG iteration 34, residual = 0.00016308268505942365
CG iteration 35, residual = 0.00012541330313818098
CG iteration 36, residual = 9.743097592810589e-05
CG iteration 37, residual = 9.055051062209108e-05
CG iteration 38, residual = 7.215293727323599e-05
CG iteration 39, residual = 5.1437674338989456e-05
CG iteration 40, residual = 3.854565333573427e-05
CG iteration 41, residual = 2.9270729690577268e-05
CG iteration 42, residual = 2.2762840142811643e-05
CG iteration 43, residual = 1.8318636840022906e-05
CG iteration 44, residual = 1.663782669569956e-05
CG iteration 45, residual = 1.239326435827247e-05
CG iteration 46, residual = 8.938676971750611e-06
CG iteration 47, residual = 6.7429807255936955e-06
CG iteration 48, residual = 5.283291543866366e-06
CG iteration 49, residual = 4.0834341388009625e-06
CG iteration 50, residual = 3.139448342661445e-06
CG iteration 51, residual = 2.4284701869105606e-06
CG iteration 52, residual = 1.8721962915667525e-06
CG iteration 53, residual = 1.4390437162445548e-06
CG iteration 54, residual = 1.0843558895489702e-06
CG iteration 55, residual = 8.218784873614817e-07
CG iteration 56, residual = 6.348404559126796e-07
CG iteration 57, residual = 4.888231968743531e-07
CG iteration 58, residual = 3.7460442096199144e-07
CG iteration 59, residual = 2.914325814116727e-07
CG iteration 60, residual = 2.2724080959377045e-07
CG iteration 61, residual = 1.7145675407334641e-07
CG iteration 62, residual = 1.3121249626611821e-07
CG iteration 63, residual = 1.020804745147125e-07
CG iteration 64, residual = 8.312046269957826e-08
CG iteration 65, residual = 7.81338610457723e-08
CG iteration 66, residual = 5.824463657046881e-08
CG iteration 67, residual = 4.253475593013148e-08
CG iteration 68, residual = 3.221199589322036e-08
CG iteration 69, residual = 2.461886671160181e-08
CG iteration 70, residual = 1.8757749038201372e-08
CG iteration 71, residual = 1.4477306764126282e-08
CG iteration 72, residual = 1.1217299791878997e-08
CG iteration 73, residual = 8.539527189841692e-09
CG iteration 74, residual = 6.60236217255431e-09
CG iteration 75, residual = 5.1452017218974136e-09
CG iteration 76, residual = 4.464686272004679e-09
CG iteration 77, residual = 3.6633505016183023e-09
CG iteration 78, residual = 2.7989000383890956e-09
CG iteration 79, residual = 2.2404414698748334e-09
CG iteration 80, residual = 1.7260548036434454e-09
CG iteration 81, residual = 1.304303961985091e-09
CG iteration 82, residual = 9.948470189365207e-10
CG iteration 83, residual = 7.684662610949876e-10
CG iteration 84, residual = 5.89132560902515e-10
CG iteration 85, residual = 4.5818072888166666e-10
CG iteration 86, residual = 3.550883194853049e-10
CG iteration 87, residual = 2.678227046625749e-10
CG iteration 88, residual = 2.043774894717784e-10
CG iteration 89, residual = 1.5803801766515645e-10
CG iteration 90, residual = 1.213954438798903e-10
CG iteration 91, residual = 9.290093643925253e-11
CG iteration 92, residual = 7.394003186435462e-11
CG iteration 93, residual = 7.0943937079876e-11
CG iteration 94, residual = 5.303819413551129e-11
CG iteration 95, residual = 3.755501910886456e-11
CG iteration 96, residual = 2.8677518354231522e-11
CG iteration 97, residual = 2.2057721976782355e-11
CG iteration 98, residual = 1.709141426312067e-11
CG iteration 99, residual = 1.3439560250750672e-11
CG iteration 100, residual = 1.0861469783526931e-11
CG iteration 101, residual = 8.321601686242787e-12
CG iteration 102, residual = 6.30849093588911e-12
CG iteration 103, residual = 4.8396260793009105e-12
CG iteration 104, residual = 3.706154071116786e-12
CG iteration 105, residual = 2.8253818680058487e-12
CG iteration 106, residual = 2.133579987288858e-12
CG iteration 107, residual = 1.6145377673112591e-12
CG iteration 108, residual = 1.2275878190348223e-12
CG iteration 109, residual = 9.588483001864524e-13
CG iteration 110, residual = 8.503186671317506e-13
CG iteration 111, residual = 7.011647317417193e-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.3934614166999498
Newton iteration 1
err = 2.3069026930309314e-15
[10]:
WebGLScene