This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

DOF ordering of mixed function spaces

0 votes

In the context of a Navier-Stokes problem consider a mixed function space

mesh = UnitSquareMesh(3, 3)
V2 = VectorElement('P', mesh.ufl_cell(), 2)
P1 = FiniteElement('P', mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, V2 * P1)

and for simplicity

u, _ = TrialFunctions(W)
v, _ = TestFunctions(W)
a = dot(u, v)*dx
A = assemble(a)

I'd like to know if the DOF ordering of the velocity component sub spaces W.sub(0).sub(i) is known apriori or predicable.
Is there a relationship between the orderings of each velocity component subspace?
For example, with dofs = [W.sub(0).sub(i).dofmap().dofs() for i in range(2)] I get

dofmap[0] = [0, 1, 4, 5, 9, 10, 15, ...]
dofmap[1] = [2, 6, 7, 11, 12, 13, 16, ...]

In the system matrix $A$ I find in the rows 0, 1, 4, .. the correct entries for the first component of $u$, and of course the rows 2, 6, 7, ... belong to the second component. However, the order is different, i.e., rows 0--2, 1--6, etc, don't match. The ordering of component 1 is identical to dofmap[0], but the ordering of component 2 seems to be: [11, 2, 6, 7, ..]

If I knew the ordering of the dofs w.r.t. $A$ beforehand, I could assemble a scalar sub problem and construct the system matrix by copying the entries of the sub matrix into the correct locations in the system matrix.

Thanks!

asked Mar 31, 2017 by dajuno FEniCS User (4,140 points)

Do you want to do the assembling by yourself? What are you going to win with that?

The system matrix has 3 identical blocks, one for each component of $u$. So one could assemble a matrix for just one component and construct the system matrix by copying the "scalar" matrix into the corresponding blocks.

1 Answer

–1 vote

In general meshes are not ordered, so you can safely assume they are not in order. For this kind of scenarios you can get the dofs from each space with

W.sub(i).tabulate_dof_coordinates()

There is also a library that sounds like it could be useful, as it allows to use block matrices:

https://bitbucket.org/fenics-apps/cbc.block

Let me know your thoughts.

Best regards

answered Apr 4, 2017 by nabarnaf FEniCS User (2,940 points)

Sorry, I don't get what this has to do with my question

You asked if you can know how the dofs will be ordered, and the answer is no. If you assembled a system that should be of the form

[ A B^T ; B 0 ]

that is only one ordering of the variables, but probably not the one that fenics will use, because your form would be something like

div(sigma)*v + grad u * tau + grad v * sigma + div(tau) * u = f

But using cbc.block you can get an ordered subsystem by assembling the different partes separately

A = assemble(...); B = assemble(...); # etc
AA = block_mat([[A,B], [C,D]])

...