How can I compute centroids and cell averages?

Hi,

I am using dolfinx 0.7.2.

How can I compute the centroids of the mesh elements? I am aware that this dolfinx version doesn’t support ufl.cell_avg. How can I compute the cell averages of a scalar field? How can I do the same thing for a vector field?

Thanks for any help,
Jorge

Interpolate into DG-0, whose dof is at the center of the cell.

1 Like

Thanks @dokken! Additionally, how do I get a numpy array of the coordinates of the centroid?

Tabulate the dof coordinates of the DG-0 space.

If I have a mesh with a lot of regions, how can I get the centroids of the regions separately?

Use locate entities or meshtags.find(i) to get the relevant cell indices of the region, and then use
https://docs.fenicsproject.org/dolfinx/v0.7.3/python/generated/dolfinx.mesh.html#dolfinx.mesh.compute_midpoints

Thank you. how can I store the vertices of reach regions separately?

Use dolfinx.mesh.entities_to_geometry and mesh.geometry.x of the output of entities to geometry to get the vertex coordinates of each entity