Extracting Block in Saddle Point Problem

Hi Everyone,

If I consider the system I get from assembling a saddle point problem (take stokes for example)

\begin{vmatrix} A&B^{T}\\ B&0\\ \end{vmatrix}

i.e. the system assembled from the code snippet below (ignoring boundary conditions)

mesh = UnitSquareMesh(8,8)
P2 = VectorElement(“CG”, mesh.ufl_cell(), 2)
P1= FiniteElement(“CG”, mesh.ufl_cell(), 1)
TH = P2 * P1
W = FunctionSpace(mesh, TH)
(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)
LHS = (inner(grad(u), grad(v)) - div(v)p + qdiv(u))*dx

I would like to be able to extract the B block. When I plot the sparsity pattern for the assembled system it is clear that the degrees of freedom are being ordered in a specific fashion. My questions are

  1. Can anyone point me to the documentation for how the DOF’s are being arranged, I can’t seem to find it. I can (hopefully) extract the matrices myself if I know that. Or even better is there a way to make it order the system in the block format.

  2. Is there some other easy way to do this that I’m not seeing?

Thank You

I guess the simplest way to do is, is to either assemble the matrices yourself (assuming you dont need the “complete” matrix but only its parts), i.e., for B^T you could do

L = div(v)*p*dx
B = assemble(L)

Another way for block systems might be cbc.block: https://bitbucket.org/fenics-apps/cbc.block/src/master/
Personally, I haven’t tried it, but it should do what you want to do.
You could also extract the submatrix by using the indices of the appropriate dofs, but first consider the other possibilities, and ask again if that does not work for you