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:

\[C_{BDDC}^{-1} = R {\,\widetilde{A}\,}^{-1}\, R^t\]

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_DOF
INTERFACE_DOF

The 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:

title
[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.00052
 1.03338
 1.09991
 ...
  4.55515
 4.60067
 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 marked WIREBASKET_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 marked WIREBASKET_DOF and the remaining edge-dofs are marked INTERFACE_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.07035
 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.989385160527906

This is a slight improvement from the default.

[8]:
lams = TestPreconditioner (10, condense=True)
max(lams)/min(lams)
[8]:
13.974958344241607

Combine BDDC with AMG for large problems

The coarse inverse \({\,\widetilde{A}\,}^{-1}\) of BDDC is expensive on fine meshes. Using the option coarsetype=h1amg flag, we can ask BDDC to replace \({\,\widetilde{A}\,}^{-1}\) by an Algebraic MultiGrid (AMG) preconditioner. Since NGSolve’s h1amg is well-suited
for the lowest order Lagrange space, we use the option wb_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 =  747331
CG iteration 1, residual = 0.728413955096221
CG iteration 2, residual = 0.3038064633975432
CG iteration 3, residual = 0.2731573265198619
CG iteration 4, residual = 0.321644468036129
CG iteration 5, residual = 0.3362137537776381
CG iteration 6, residual = 0.23091380686774435
CG iteration 7, residual = 0.17758171344641407
CG iteration 8, residual = 0.14575584903552571
CG iteration 9, residual = 0.1094334566481546
CG iteration 10, residual = 0.07987287960772069
CG iteration 11, residual = 0.058360787105302965
CG iteration 12, residual = 0.04630036174594888
CG iteration 13, residual = 0.037001482312352056
CG iteration 14, residual = 0.028875962787519027
CG iteration 15, residual = 0.021947291835534545
CG iteration 16, residual = 0.01688036939339392
CG iteration 17, residual = 0.013424016729028333
CG iteration 18, residual = 0.010407276786618078
CG iteration 19, residual = 0.00783111929263995
CG iteration 20, residual = 0.006068982634319513
CG iteration 21, residual = 0.004699791356400399
CG iteration 22, residual = 0.0035013081298882437
CG iteration 23, residual = 0.0026881998338427475
CG iteration 24, residual = 0.0020913709940974324
CG iteration 25, residual = 0.0016265345742918866
CG iteration 26, residual = 0.0012407145818779193
CG iteration 27, residual = 0.000974217326318523
CG iteration 28, residual = 0.0007649510759745143
CG iteration 29, residual = 0.0005840071554908115
CG iteration 30, residual = 0.0004482828154467541
CG iteration 31, residual = 0.0003444113416353921
CG iteration 32, residual = 0.00026146352120846324
CG iteration 33, residual = 0.00020256820856994794
CG iteration 34, residual = 0.0001607622127776955
CG iteration 35, residual = 0.00012510668095716692
CG iteration 36, residual = 9.70926888809783e-05
CG iteration 37, residual = 9.081199546919187e-05
CG iteration 38, residual = 6.872980322025363e-05
CG iteration 39, residual = 4.98784310235204e-05
CG iteration 40, residual = 3.782553574452818e-05
CG iteration 41, residual = 2.922944571640207e-05
CG iteration 42, residual = 2.2848533104598235e-05
CG iteration 43, residual = 1.7602011036600784e-05
CG iteration 44, residual = 1.3885656020760526e-05
CG iteration 45, residual = 1.0813387178124012e-05
CG iteration 46, residual = 8.097364668506325e-06
CG iteration 47, residual = 6.141265217387209e-06
CG iteration 48, residual = 4.79327704272667e-06
CG iteration 49, residual = 3.6467780868706824e-06
CG iteration 50, residual = 2.830568735278445e-06
CG iteration 51, residual = 2.141470433460782e-06
CG iteration 52, residual = 1.6371318610893182e-06
CG iteration 53, residual = 1.268521338408648e-06
CG iteration 54, residual = 9.687252649034529e-07
CG iteration 55, residual = 7.429325199359479e-07
CG iteration 56, residual = 5.718110256346745e-07
CG iteration 57, residual = 4.438687295368013e-07
CG iteration 58, residual = 3.428074253487734e-07
CG iteration 59, residual = 2.691845408191268e-07
CG iteration 60, residual = 2.0761481858997938e-07
CG iteration 61, residual = 1.6004452468710171e-07
CG iteration 62, residual = 1.2386161504469674e-07
CG iteration 63, residual = 9.358114663416246e-08
CG iteration 64, residual = 7.218312831411888e-08
CG iteration 65, residual = 5.592557845364378e-08
CG iteration 66, residual = 4.255760895166389e-08
CG iteration 67, residual = 3.42885005937502e-08
CG iteration 68, residual = 3.2211617084469465e-08
CG iteration 69, residual = 2.4339240601746848e-08
CG iteration 70, residual = 1.7565471811876057e-08
CG iteration 71, residual = 1.3281792071619871e-08
CG iteration 72, residual = 1.0160088614743937e-08
CG iteration 73, residual = 7.803125778579358e-09
CG iteration 74, residual = 6.026546278929305e-09
CG iteration 75, residual = 4.616887449388399e-09
CG iteration 76, residual = 3.5254258787640178e-09
CG iteration 77, residual = 2.7028031166513074e-09
CG iteration 78, residual = 2.0818453154216583e-09
CG iteration 79, residual = 1.6294325631178293e-09
CG iteration 80, residual = 1.2914405455503885e-09
CG iteration 81, residual = 1.051166420502288e-09
CG iteration 82, residual = 8.199195878325732e-10
CG iteration 83, residual = 6.206520183242694e-10
CG iteration 84, residual = 4.76995821127825e-10
CG iteration 85, residual = 3.6967197907182374e-10
CG iteration 86, residual = 2.800034668966816e-10
CG iteration 87, residual = 2.2491222797848523e-10
CG iteration 88, residual = 1.8451487109356094e-10
CG iteration 89, residual = 1.4149919832925903e-10
CG iteration 90, residual = 1.082920637628715e-10
CG iteration 91, residual = 8.363328351437984e-11
CG iteration 92, residual = 6.455066247499176e-11
CG iteration 93, residual = 4.9537649504797274e-11
CG iteration 94, residual = 3.778225856410223e-11
CG iteration 95, residual = 2.8511688696499268e-11
CG iteration 96, residual = 2.225948216928099e-11
CG iteration 97, residual = 2.001701395476387e-11
CG iteration 98, residual = 1.6940443251819565e-11
CG iteration 99, residual = 1.185389304152901e-11
CG iteration 100, residual = 9.093652142408457e-12
CG iteration 101, residual = 6.93352222287234e-12
CG iteration 102, residual = 5.219822826754369e-12
CG iteration 103, residual = 3.947806942593717e-12
CG iteration 104, residual = 3.0633140176182746e-12
CG iteration 105, residual = 2.385289678378347e-12
CG iteration 106, residual = 1.852327709588382e-12
CG iteration 107, residual = 1.4772104587739407e-12
CG iteration 108, residual = 1.1471409074323923e-12
CG iteration 109, residual = 8.99878964277499e-13
CG iteration 110, residual = 6.769767453394141e-13
[9]:
BaseWebGuiScene

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.3934614166999501
Newton iteration  1
err =  5.90497752440774e-15
[10]:
BaseWebGuiScene