# Volume_entities and inradius function from cpp.mesh

Good afternoon everyone,

I’m wondering why volume_entities and inradius functions are missing in fenicsx.cpp.mesh. For instance, I got this error message:

``````module 'dolfinx.cpp.mesh' has no attribute 'inradius'
``````

However, at least volume_entities function is used in the test files from the git of fenicsx:

Is it normal ?

Here an MWE:

``````from fenicsx import cpp as _cpp

_cpp.mesh.volume_entities()
``````

I’m working with the version 0.6 of fenicsx.

Have a good afternoon

Alot of these functions only make sense on linear (straight edged) meshes.
As DOLFINx supports higher order geometries, many of these functions are not simple or even well defined to compute.

For instance, the volume over a higher order cell is dependent on more than just the nodes defining the cell.
You can compute the volume as described in: Computing mesh element size - #2 by dokken
And we do have the definition of `h`: dolfinx.mesh — DOLFINx 0.7.2 documentation

2 Likes

By curiosity, I remember, I hope well, that the determinant of the Jacobian matrix was related to the volume of a cell. Is there a way to use this trick ?

The Jacobian of the determinant relates to the volume of the cell. For affine cells, the determinant of the jacobian is constant, and thus you can compute it at any point in a cell to get the volume. However, for non-affine cells, the determinant is not constant.
Thus for simple (affine) problems, you can do:

``````import dolfinx
from mpi4py import MPI
import ufl
import numpy as np

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 5, 5)
V = dolfinx.fem.functionspace(mesh, ("DG", 0))
u = dolfinx.fem.Function(V)
detJ = abs(ufl.JacobianDeterminant(mesh)*ufl.classes.ReferenceCellVolume(mesh))
expr = dolfinx.fem.Expression(detJ, V.element.interpolation_points())
u.interpolate(expr)
print(u.x.array)
print(sum(u.x.array))
``````
1 Like