This page was generated from unit-2.1.3-bddc/bddc.ipynb.
2.1.3 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 preconditoner 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 discontinous 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_DOF
s 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_DOF
s 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]:
import netgen.gui
from ngsolve import *
from ngsolve.la import EigenValues_Preconditioner
from netgen.csg import unit_cube
from netgen.geom2d import unit_square
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.00408
1.11176
1.34787
...
33.7436
34.7966
38.0012
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.00139
1.04212
1.12173
...
6.95459
7.03965
7.3257
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_DOF
s). 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_DOF
and the remaining edge-dofs are markedINTERFACE_DOF
s).
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.00468
1.09359
1.32949
...
31.1877
33.3524
34.3632
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]:
18.310200831382364
This is a slight improvement from the default.
[8]:
lams = TestPreconditioner (10, condense=True)
max(lams)/min(lams)
[8]:
27.550548160831866
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 = 1165206
iteration 0 error = 0.7073081556201699
iteration 1 error = 0.29234932975605554
iteration 2 error = 0.2850418149821573
iteration 3 error = 0.2909981017147027
iteration 4 error = 0.31960438903466765
iteration 5 error = 0.2548888240960561
iteration 6 error = 0.19211648077547436
iteration 7 error = 0.15448200225941894
iteration 8 error = 0.12629308957277452
iteration 9 error = 0.10147809995154579
iteration 10 error = 0.07424629202717485
iteration 11 error = 0.056624467725207656
iteration 12 error = 0.04501676034374408
iteration 13 error = 0.0382220381809261
iteration 14 error = 0.03168346197791913
iteration 15 error = 0.02517331328272456
iteration 16 error = 0.01931169756848505
iteration 17 error = 0.015539926079374468
iteration 18 error = 0.012427093009904315
iteration 19 error = 0.009988766258813522
iteration 20 error = 0.0077720886344875536
iteration 21 error = 0.006098861813647612
iteration 22 error = 0.004845046892975528
iteration 23 error = 0.003893773676822123
iteration 24 error = 0.003121133386776407
iteration 25 error = 0.002514640233156311
iteration 26 error = 0.0020184764921664673
iteration 27 error = 0.001617864447126155
iteration 28 error = 0.0012924084232665927
iteration 29 error = 0.0010424122415456996
iteration 30 error = 0.0008356476881818595
iteration 31 error = 0.0006714771386029344
iteration 32 error = 0.0005352583557295326
iteration 33 error = 0.00042153614004972163
iteration 34 error = 0.00033332986692651847
iteration 35 error = 0.000267377482156842
iteration 36 error = 0.00021292707026142384
iteration 37 error = 0.00016781065820928843
iteration 38 error = 0.00013449011495942793
iteration 39 error = 0.00010874377691006918
iteration 40 error = 8.770990809322496e-05
iteration 41 error = 7.040160830268227e-05
iteration 42 error = 5.698664113959084e-05
iteration 43 error = 4.5501503462654023e-05
iteration 44 error = 3.6589594863170344e-05
iteration 45 error = 2.915218649295205e-05
iteration 46 error = 2.3079948214278587e-05
iteration 47 error = 1.8701645006036686e-05
iteration 48 error = 1.5031022112734328e-05
iteration 49 error = 1.2051566531026929e-05
iteration 50 error = 9.777942195673649e-06
iteration 51 error = 7.826471192074674e-06
iteration 52 error = 6.201950973193662e-06
iteration 53 error = 4.939891740893184e-06
iteration 54 error = 3.914638625056899e-06
iteration 55 error = 3.1360658058688553e-06
iteration 56 error = 2.527227821299947e-06
iteration 57 error = 2.0411730380085634e-06
iteration 58 error = 1.6311444686606998e-06
iteration 59 error = 1.2845529202221262e-06
iteration 60 error = 1.0401707229757139e-06
iteration 61 error = 8.352753108567447e-07
iteration 62 error = 6.684582333668527e-07
iteration 63 error = 5.32651068150703e-07
iteration 64 error = 4.261221547761287e-07
iteration 65 error = 3.4050491248038255e-07
iteration 66 error = 2.7074975790309777e-07
iteration 67 error = 2.1749032285629753e-07
iteration 68 error = 1.7486675337678366e-07
iteration 69 error = 1.405784172177547e-07
iteration 70 error = 1.1189051550484346e-07
iteration 71 error = 8.937565135456247e-08
iteration 72 error = 7.124610408362074e-08
iteration 73 error = 5.644689560098361e-08
iteration 74 error = 4.558955080437436e-08
iteration 75 error = 3.6239672499135155e-08
iteration 76 error = 2.9298785040787337e-08
iteration 77 error = 2.3411322754464886e-08
iteration 78 error = 1.8457984841352454e-08
iteration 79 error = 1.4900417523186493e-08
iteration 80 error = 1.2022570114981657e-08
iteration 81 error = 9.627502103620846e-09
iteration 82 error = 7.794274843297983e-09
iteration 83 error = 6.328645356797293e-09
iteration 84 error = 5.089852935363618e-09
iteration 85 error = 4.136067464155599e-09
iteration 86 error = 3.3565571007330278e-09
iteration 87 error = 2.7664760444172366e-09
iteration 88 error = 2.193118940041056e-09
iteration 89 error = 1.7442175826574267e-09
iteration 90 error = 1.391269420964351e-09
iteration 91 error = 1.1172863539780384e-09
iteration 92 error = 8.948310609021816e-10
iteration 93 error = 7.210459310590989e-10
iteration 94 error = 5.787294903914218e-10
iteration 95 error = 4.5703357457109395e-10
iteration 96 error = 3.663899946648758e-10
iteration 97 error = 2.9450117552208257e-10
iteration 98 error = 2.3398402297726184e-10
iteration 99 error = 1.8853743781186316e-10
iteration 100 error = 1.505157675946302e-10
iteration 101 error = 1.1963785334299208e-10
iteration 102 error = 9.597287931630692e-11
iteration 103 error = 7.711173513561008e-11
iteration 104 error = 6.133485230239876e-11
iteration 105 error = 4.917145944743518e-11
iteration 106 error = 3.975221274301793e-11
iteration 107 error = 3.264311502526618e-11
iteration 108 error = 2.6286723828163157e-11
iteration 109 error = 2.122605910347873e-11
iteration 110 error = 1.719340323218332e-11
iteration 111 error = 1.3766468877319304e-11
iteration 112 error = 1.1187725147280619e-11
iteration 113 error = 8.925333169670713e-12
iteration 114 error = 7.049987623038661e-12
iteration 115 error = 5.655310868212989e-12
iteration 116 error = 4.501256939356903e-12
iteration 117 error = 3.576765573636405e-12
iteration 118 error = 2.8851299059515853e-12
iteration 119 error = 2.3040513151116907e-12
iteration 120 error = 1.819315644132251e-12
iteration 121 error = 1.452724482698981e-12
iteration 122 error = 1.1748751733349953e-12
iteration 123 error = 9.430890221142276e-13
iteration 124 error = 7.560869944544073e-13
iteration 125 error = 6.057705175269238e-13
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 = FESpace([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])
Newton iteration 0
err = 0.3937351156371161
Newton iteration 1
err = 3.874027236775335e-15