How to average a function over a cell

Hi all,

I am trying to compute the average of a function per cell in a tetrahedral mesh. Following this old topic How to calculate effective stress/strain in a homogenization model - #11 by AIJAZ_NAZIR , I get the following error
ValueError: Unknown element family: D with cell type tetrahedron

I am using DOLFINx v0.7.3 - is that some version error or do I have to use some newer than 0.7.3.?

Thankful for any help :slight_smile:

For the sake of transparency and reproducibility, could you add the code you are trying to run?

Sure, for a tetrahedral mesh I try the following:

x = ufl.SpatialCoordinate(mesh)
f = x[0]**2
V = FunctionSpace(mesh, “DG”, 0)
v = TestFunction(V)
int_f = dolfinx.fem.assemble_vector(dolfinx.fem.form(1/ufl.CellVolume(mesh)fv*ufl.dx))

I found the solution, moving away from the deprecated API and adding a set of brackets solved the issue…

x = ufl.SpatialCoordinate(mesh)
f = x[0]**2
V = functionspace(mesh, (“DG”, 0))
v = TestFunction(V)
int_f = dolfinx.fem.assemble_vector(dolfinx.fem.form(1/ufl.CellVolume(mesh)fv*ufl.dx))
print(int_f.array)

Thank you for your help anyways!