neighboring cells

Asked by yk1000

I would like to define a function that takes as its input the index of a particular cell within my mesh(2D or 3D), and returns as output the indices of all neighboring cells (where I define neighbors to mean those that share ANY VERTICES with the input cell). What might be the best way to do this using the built in MeshConnectivity or MeshTopology classes? It appears MeshConnectivity yields all cells associated with each vertex and vice versa (the transpose), but I'm not sure how to obtain the neighbors of one particular cell. There doesn't seem to be a reference operator of any sort. Thank you in advance for any help!

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Andre Massing
Solved:
Last query:
Last reply:
Revision history for this message
Best Andre Massing (massing) said :
#1

On 06/15/2011 06:11 AM, yk1000 wrote:
> New question #161480 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/161480
>
> I would like to define a function that takes as its input the index of a particular cell within my mesh(2D or 3D), and returns as output the indices of all neighboring cells (where I define neighbors to mean those that share ANY VERTICES with the input cell). What might be the best way to do this using the built in MeshConnectivity or MeshTopology classes? It appears MeshConnectivity yields all cells associated with each vertex and vice versa (the transpose), but I'm not sure how to obtain the neighbors of one particular cell. There doesn't seem to be a reference operator of any sort. Thank you in advance for any help!
>

You can use the Cell class with the constructor

/// Create cell on given mesh with given index
Cell(const Mesh& mesh, uint index)

and than use the following member function

  /// Return array of indices for incident mesh entitites of given
topological dimension
const uint* entities(uint dim) const

If you want to iterate of your mesh you can employ the CellIterator,
which also has a random access operator, taking a cell index. It will
than point to corresponding Cell entity.

HTH,
Andre

Revision history for this message
yk1000 (ykimura) said :
#2

Thanks Andre Massing, that solved my question.