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

How to find the global index of a cell which belongs to a submesh?

0 votes
asked Jan 23, 2014 by fotini.karakatsani FEniCS Novice (500 points)

1 Answer

+1 vote

Edit: Sorry, realized that's not what you were asking for.

How about this quite crude approach:

local_cell = Cell(submesh, local_index)
bb = mesh.bounding_box_tree()
global_index = bb.compute_first_entity_collision(local_cell.midpoint())

As far as I know, the mapping between a submesh and parent mesh isn't stored...(?)

answered Jan 23, 2014 by Øyvind Evju FEniCS Expert (17,700 points)
edited Jan 23, 2014 by Øyvind Evju

Thank you for your answer but I still have a problem. Here is my code

patch = SubMesh(mesh, subdomains, 1)
for cell in cells(patch):
cell_index = cell.index()
print 'cell index=%d' % cell.index()
cell1 = Cell(mesh, cell_index)
print 'global index', cell1.global_index()

And here are the results:

facet: 500
cell index=0
global index 0
cell index=1
global index 1
facet: 501
cell index=0
global index 0
cell index=1
global index 1
facet: 502
cell index=0
global index 0
cell index=1
global index 1

etc ... the global index is equal to the local index in submesh

Best,
Fotini

Sorry, realized that I misunderstood your question. Update the reply now.

Thanks for your help.
There is the following error:

bbt = mesh.bounding_box_tree()
AttributeError: 'Mesh' object has no attribute 'bounding_box_tree'

Which version of dolfin are you using?

For 1.2 you can try this

local_cell = Cell(submesh, local_index)
global_index = mesh.intersected_cell(cell.midpoint())

However, using the BoundingBoxTree in 1.3 is much more efficient.

I use the binary for mac os X 10.8.
Thanks so much for your help. Now everything is fine!

...