This page was generated from unit-2.7-hybrid/hybrid.ipynb.
2.7 Facet spaces and hybrid methods¶
Mixed methods for second order problems lead to saddle point problems, and indefinite matrices. By hybridization one obtains a positive definite system again. Its structure is similar to the non-conforming \(P^1\) method, but hybridization works for any order. See the textbook by Brezzi and Fortin.
One gives up the normal continuity of the \(H(div)\) variable, and enforces it again by a Lagrange multiplier. This leads to the following discrete system:
Find \((\sigma, u, \widehat u) \in \Sigma_h \times V_h \times F_h\) such that
where \(\Sigma_h\) is a discontinuous \(H(div)\) finite element space, \(V_h\) a sub-space of \(L_2\), and \(F_h\) consists of polynomials on every edge. The Lagrange multiplier \(\widehat u\) is an approximation to \(u\) on the edges. Thus, the Dirichlet condition \(\widehat u = u_D\) on \(\Gamma_D\) is an essential boundary condition for the facet space.
[1]:
from ngsolve import *
from ngsolve.webgui import Draw
mesh = Mesh(unit_square.GenerateMesh(maxh=0.2))
The same example as in unit 2.5:
[2]:
source = sin(pi*x)
ud = CF(5)
g = mesh.BoundaryCF( {"left" : y*(1-y)}, default=0)
lam = 10
Define the spaces:
The
Discontinuouswrapper generates an element-wise discontinuous version of a spaceFacetFESpacelives only on facets (i.e. faces in 3D, edges in 2D, points in 1D)
[3]:
order = 3
V = Discontinuous (HDiv(mesh, order=order))
Q = L2(mesh, order=order-1)
F = FacetFESpace(mesh, order=order)
X = V*Q*F
print ("sigmadofs:", X.Range(0))
print ("udofs: ", X.Range(1))
print ("uhatdofs: ", X.Range(2))
sigmadofs: [0,1080)
udofs: [1080,1404)
uhatdofs: [1404,1768)
Define the variational equation. The jump term is rewritten as
Integrals over the element boundaries are obtained by dx(element_boundary=True):
[4]:
(sigma,u,uhat), (tau,v,vhat) = X.TnT()
n = specialcf.normal(mesh.dim)
lhs = (1/lam * sigma*tau + div(sigma)*v + div(tau)*u) * dx \
+ (-sigma*n*vhat-tau*n*uhat) * dx(element_boundary=True)
rhs = -source*v * dx - g*vhat * ds
Now all unknowns of \(\sigma\) and \(u\) are element-local, and Solve eliminates them by static condensation. The remaining system for the facet variable \(\widehat u\) is symmetric and positive definite. We solve it by a conjugate gradient iteration with a BDDC preconditioner. The boundary condition is now posed for the facet variable:
[5]:
gf = Solve(lhs==rhs, uhat[BND("bottom")] == ud,
preconditioners.BDDC(),
solvers.CGSolver.Creator(printrates=True))
CG iteration 1, residual = 129.43061987682816
CG iteration 2, residual = 64.33508094068392
CG iteration 3, residual = 25.699479548412526
CG iteration 4, residual = 14.108687089744738
CG iteration 5, residual = 5.735425255064723
CG iteration 6, residual = 1.937146725063388
CG iteration 7, residual = 0.46503997489036264
CG iteration 8, residual = 0.21037305648082194
CG iteration 9, residual = 0.09749638050441092
CG iteration 10, residual = 0.03048565841136994
CG iteration 11, residual = 0.012763467410161997
CG iteration 12, residual = 0.004900695252366234
CG iteration 13, residual = 0.0021442306161693504
CG iteration 14, residual = 0.0007925549913537721
CG iteration 15, residual = 0.0003418740510937613
CG iteration 16, residual = 0.00011731891666203071
CG iteration 17, residual = 5.6266480452285005e-05
CG iteration 18, residual = 1.9115928384217266e-05
CG iteration 19, residual = 8.679431518440203e-06
CG iteration 20, residual = 3.0354553028718005e-06
CG iteration 21, residual = 1.3341755587449936e-06
CG iteration 22, residual = 3.9730802163889183e-07
CG iteration 23, residual = 1.6678738462447717e-07
CG iteration 24, residual = 5.40543797706573e-08
CG iteration 25, residual = 2.6813834332618146e-08
CG iteration 26, residual = 7.879337558771003e-09
CG iteration 27, residual = 2.7082600138528486e-09
CG iteration 28, residual = 8.863398159465854e-10
CG iteration 29, residual = 3.285523767589178e-10
CG iteration 30, residual = 1.32247295613908e-10
CG iteration 31, residual = 4.6974497879819684e-11
[6]:
Draw (gf[sigma], mesh, "sigma")
Draw (gf[u], mesh, "u");
With condense=False the local unknowns are kept, and the sparse direct solver has to deal with the big saddle point system:
[7]:
gf2 = Solve(lhs==rhs, uhat[BND("bottom")] == ud, condense=False)
print ("difference:", sqrt(Integrate((gf[u]-gf2[u])**2, mesh)))
difference: 2.4701231655073097e-13
Behind the scenes¶
Solve has set up a BilinearForm with the flag condense, and has performed the following steps, see also unit 1.4. Now the Dirichlet boundary is a property of the facet space:
[8]:
F = FacetFESpace(mesh, order=order, dirichlet="bottom")
X = V*Q*F
(sigma,u,uhat), (tau,v,vhat) = X.TnT()
a = BilinearForm(X, condense=True)
a += (1/lam * sigma*tau + div(sigma)*v + div(tau)*u) * dx
a += (-sigma*n*vhat-tau*n*uhat) * dx(element_boundary=True)
c = preconditioners.BDDC(a)
f = LinearForm(-source*v * dx - g*vhat * ds)
a.Assemble()
f.Assemble()
print ("A non-zero", a.mat.nze)
A non-zero 6640
The matrix a.mat is the Schur complement with respect to the facet variable. We modify the right hand side accordingly, solve for the facet variable, and finally recover the local unknowns:
[9]:
gfu = GridFunction(X)
gfu.components[2].Set(ud, BND)
fmod = (f.vec + a.harmonic_extension_trans * f.vec).Evaluate()
solvers.CG(mat=a.mat, pre=c, rhs=fmod, sol=gfu.vec, initialize=False)
gfu.vec.data += a.harmonic_extension * gfu.vec
gfu.vec.data += a.inner_solve * f.vec
print ("difference:", sqrt(Integrate((gfu.components[1]-gf.components[1])**2, mesh)))
CG iteration 1, residual = 129.43061989267372
CG iteration 2, residual = 64.33508093893889
CG iteration 3, residual = 25.69947954472949
CG iteration 4, residual = 14.10868708753025
CG iteration 5, residual = 5.735425255729804
CG iteration 6, residual = 1.9371467256782986
CG iteration 7, residual = 0.46503997596841046
CG iteration 8, residual = 0.2103730584301432
CG iteration 9, residual = 0.09749638073638034
CG iteration 10, residual = 0.030485658400161122
CG iteration 11, residual = 0.0127634674022606
CG iteration 12, residual = 0.004900695250344826
CG iteration 13, residual = 0.002144230615754034
CG iteration 14, residual = 0.0007925549912262123
CG iteration 15, residual = 0.0003418740510999423
CG iteration 16, residual = 0.00011731891667846837
CG iteration 17, residual = 5.626648046964995e-05
CG iteration 18, residual = 1.9115928390719403e-05
CG iteration 19, residual = 8.679431520077259e-06
CG iteration 20, residual = 3.0354553028959976e-06
CG iteration 21, residual = 1.3341755586523997e-06
CG iteration 22, residual = 3.9730802148020307e-07
CG iteration 23, residual = 1.6678738453506353e-07
CG iteration 24, residual = 5.405437974685681e-08
CG iteration 25, residual = 2.6813834329046424e-08
CG iteration 26, residual = 7.879337558965501e-09
CG iteration 27, residual = 2.708260013658761e-09
CG iteration 28, residual = 8.863398156987623e-10
CG iteration 29, residual = 3.28552376420089e-10
CG iteration 30, residual = 1.3224729540258183e-10
CG iteration 31, residual = 4.6974497372552485e-11
difference: 1.4177366982750599e-09