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

How to get the patch of the cells from the vertex index

0 votes

Is there a way to know the patch of a given vertex? I mean, if I have the id of a vertex, can I know the ids of the cells that share it?

I tried with closest_cell() and I ran the demo lines

mesh=dolfin.UnitSquareMesh(2,2)
point = dolfin.Point(0.0, 2.0)
mesh.closest_cell(point)

but it gives me the error:
'UnitSquareMesh' object has no attribute 'closest_cell'

Differently from the example, I have a 3D mesh.
Thanks in advance!
Cristina

asked Mar 18, 2015 by MCri FEniCS User (1,120 points)

Dear All

Further to the above question

Why is closest_cell gone in dolfin 1.5.0

What has replaced it.

For my project it is absolutely vital to have a function like this!

regards

Moritz Braun

Does not work what chris_richardson answered? I used his suggestion.

1 Answer

+3 votes
 
Best answer

How about:

mesh = UnitSquareMesh(2, 2)
for v in vertices(mesh):
    for c in cells(v)
        print v.index(), c.index()
answered Mar 18, 2015 by chris_richardson FEniCS Expert (31,740 points)
selected Mar 19, 2015 by MCri

Maybe I was not clear..

I get the array of dofmap

dm = V.dofmap().dofs()

and I need to get, for each dofmap, an array containing the id of the cell that have that dofmap, and then get the dofmap on each cell.

for i in range(0, len(dm))
     get the ids of the cells with dof of index i (How can I do this?) -> create an array
     for each cell 
          dofs_of_cell = V.dofmap.cell_dofs(id_cell) 
          .... then it continues 

If you are just using P1 elements, then you can use:

Q = FunctionSpace(mesh, "CG", 1)
print dof_to_vertex_map(Q)
print vertex_to_dof_map(Q)

to map between dofs and vertices.

So you can use:

for v in vertices(mesh):
    for c in cells(v):
        print vertex_to_dof_map(Q)[v.index()], 
        print Q.dofmap().cell_dofs(c.index())

or similar

But can I use this method for MixedSpace too?

...