# Computing cell orientation in FEniCSx

**URL:** https://fenicsproject.discourse.group/t/computing-cell-orientation-in-fenicsx/10240
**Category:** dolfinx
**Created:** [January 24, 2023, 8:25am UTC](https://fenicsproject.discourse.group/t/computing-cell-orientation-in-fenicsx/10240 "2023-01-24T08:25:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![oali](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/oali/32/4612_2.png) [@oali](https://fenicsproject.discourse.group/u/oali)
#### Post date: [January 24, 2023, 8:25am UTC](https://fenicsproject.discourse.group/t/computing-cell-orientation-in-fenicsx/10240/1 "2023-01-24T08:25:29Z")

</div>

Hi everyone,

I want to compute the normal vector field to a given 2D meshed surface (`surf`) embedded within R^3.

To that end, I use the `ufl.CellNormal(surf)` class (thk @dokken btw…).

Prior to any computation, I want to visualize this vector field. To that end, I wrote this code:

```python
import pyvista as pv
import ufl
from dolfinx import fem, plot

vDG0 = fem.VectorFunctionSpace(surf, ('DG', 0))

# Compute the normal vector field
cell_nrl = ufl.CellNormal(surf)

nrl_expr = fem.Expression(cell_nrl, vDG0.element.interpolation_points())
normals = fem.Function(vDG0)
normals.interpolate(nrl_expr)

# Reshape the array
gdim = surf.geometry.dim
nbr_cell = sphere.topology.original_cell_index.shape[0]
nrl_vcts = normals.x.array.real.reshape((nbr_cell, gdim))

# Plot
topology, cell_types, geometry = plot.create_vtk_mesh(surf)
grid = pv.UnstructuredGrid(topology, cell_types, geometry)

grid['normals'] = nrl_vcts
glyphs = grid.glyph(orient='normals', factor=.1)

pltr = pv.Plotter()
pltr.add_mesh(grid, style='wireframe', color='k')
pltr.add_mesh(glyphs)
pltr.show()

```

This code produces the expected vector field but with no coherent orientation, see caption below.

 ![Screenshot 2023-01-24 at 09.24.25](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/2/23ff15baf9ae278e8144ff71554aabb4933cfcaf.jpeg)

From my experience doing similar things with “legacy” FEniCS, I remember harmonizing cell orientation thoughout the mesh prior to the computation of normals; with the method `mesh.init_cell_orientation()` if I recall properly… I looked for such a method in FEniCSx but was not able to find any…

**My question:** How can I produce a coherent cell orientation on a meshed surface in FEniCSx ?

Thx for your help guys.  
cheers
