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

Which dofs belong to which vector components

+7 votes

Say V is a dolfin.VectorFunctionSpace(...).

For visualization purposes I have set up a table that tabulates the dofs of V vs. their coordinates in $\mathbb R^2$.

Now I still have to extract the information which dof of V is associated to the x[0] component of a function in V and which is with the x[1] component.

Is their a more direct way than interpolating dolfin.Constant(('1', '0')) in V and checking for the zero components.

asked Jan 30, 2014 by Jan FEniCS User (8,290 points)

2 Answers

+5 votes
 
Best answer
from dolfin import *
mesh = UnitSquareMesh(3, 3)
V = VectorFunctionSpace(mesh, 'CG', 2)
print V.sub(0).dofmap().dofs()

Out:

[ 0  2  4  6  8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96]
answered Jan 31, 2014 by Jan Blechta FEniCS Expert (51,420 points)
selected Jan 31, 2014 by Jan
+1 vote

If it is a CG1 functionspace, you can use

mesh.coordinates() 

in combindation with

dof2vtx = vertex_to_dof_map(FunctionSpace(mesh, "CG" ,1))

for DOLFIN 1.2.0 or

dof2vtx = FunctionSpace(mesh,'CG',1).dofmap().vertex_to_dof_map(mesh).argsort()

for the development version.

answered Jan 30, 2014 by KristianE FEniCS Expert (12,900 points)

Thanks a lot for this insight. I should have added that I am in a CG2 space. For which vertex_do_dof_map doesn't work...

Sure it does not. There are no mesh vertices at a half of DOFs.

There are other helper function in DofMap class, like cell_dofs or something like that.

I don't understand this answer. How does dof2vtx determine which dof's correspond to x[0], and which to x[1]?

...