# Iterate over the faces of an UnstructuredGrid

**URL:** https://discourse.vtk.org/t/iterate-over-the-faces-of-an-unstructuredgrid/2184
**Category:** Support
**Created:** [November 29, 2019, 7:16pm UTC](https://discourse.vtk.org/t/iterate-over-the-faces-of-an-unstructuredgrid/2184 "2019-11-29T19:16:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![balborian](https://discourse.vtk.org/user_avatar/discourse.vtk.org/balborian/32/1152_2.png) [@balborian](https://discourse.vtk.org/u/balborian)
#### Post date: [November 29, 2019, 7:16pm UTC](https://discourse.vtk.org/t/iterate-over-the-faces-of-an-unstructuredgrid/2184/1 "2019-11-29T19:16:35Z")

</div>

What’s the most efficient way to iterate over all the faces of an UnstructuredGrid? I know I can iterate over the cells first and then get its faces for each cell, but this will lead me to visit the same face two times (one per each cell that shares the face). Is there a way to just iterate over all the faces? Thanks.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [December 2, 2019, 2:40pm UTC](https://discourse.vtk.org/t/iterate-over-the-faces-of-an-unstructuredgrid/2184/2 "2019-12-02T14:40:16Z")

</div>

If you are interested in visiting only the cells on the outside surface of the mesh then you can apply [vtkGeometryFilter](https://vtk.org/doc/nightly/html/classvtkGeometryFilter.html).

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [August 17, 2021, 4:02pm UTC](https://discourse.vtk.org/t/iterate-over-the-faces-of-an-unstructuredgrid/2184/3 "2021-08-17T16:02:00Z")

</div>

One trick to use is the following:

- Iterate over all cells
- For each cell C
- For each face F of C, get the list of cell neighbors.
- If the cell id of C \< the cell id of any other cell using F, then visit F. (Or if there are no neighbors to face F, visit it).
