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

Find dof and coordinate from a subspace

+1 vote

Hello,

What is the better way to extract DOF and its coordinate from a subspace ?

  • Actually, i'm using a cell iterator on a subspace in python, and for a big mesh loop is not convenient in python.

  • vertex_to_dof_map and dof_map_to_vertex function cannot be used in a subspace of a MixedFunctionSpace.

  • I want to use dofs function, but the order of DOFs given by this method is not good.

Minimal code :

from dolfin import *    

mesh = UnitIntervalMesh(3)
V = FunctionSpace(mesh, 'CG', 1)
W = MixedFunctionSpace([V,V])
W1,W2 = W.split()

#Method that I use
list_dof = []
list_coor = []

for cell in cells(W1.mesh()) :
    i = cell.index()
    list_dof.append(W1.dofmap().cell_dofs(i))
    list_coor.append(W1.dofmap().tabulate_coordinates(cell))

Then I have to arrange both list to have the list DOFs and the list of coordinates with corresponding index.

I want to use methods like tabulate_all_coordinates() and dofs() in W1.dofmap(), but the DOFs indice doesn't correspond to the coordinate indice with the methods dofs().

Is there an other way than cell iterator to do what I want ?

Thanks for you help !
Mehdi Tha.

asked Mar 18, 2015 by mehdi.tha FEniCS Novice (170 points)

1 Answer

+1 vote
 
Best answer

Hi, consider

from dolfin import *    

mesh = UnitSquareMesh(3, 3)
V = FunctionSpace(mesh, 'CG', 1)
W = MixedFunctionSpace([V, V])

# Coordinates of all dofs in the mixed space
Wdofs_x = W.dofmap().tabulate_all_coordinates(mesh).reshape((-1, 2))
# Dofs of first subspace of the mixed space
V0_dofs = W.sub(0).dofmap().dofs()
# Coordinates of dofs of first subspace of the mixed space
V0_dofs_x = Wdofs_x[V0_dofs, :] 
answered Mar 18, 2015 by MiroK FEniCS Expert (80,920 points)
selected Oct 27, 2015 by mehdi.tha
...