Minimum element size hmin | FEniCSx 0.7.2

Hello everyone,

I recently upgraded from FEniCSx version 0.6.0 to 0.7.2. Now I get an error message when determining the minimum element size hmin, which I can’t fix myself.

Here is my code as it worked before:

import dolfinx
from mpi4py import MPI
import numpy as np

mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 50, 50)

tdim = mesh.topology.dim

num_cells = mesh.topology.index_map(tdim).size_local

hmin = mesh.comm.allreduce(min(dolfinx.cpp.mesh.h(mesh, tdim, range(num_cells))), op=MPI.MIN)

I get the following error message:

Traceback (most recent call last):
  File "/root/shared/Thesis/Fenicsx/3Dcube-8Incls+14Pores/Dry/Monotonic/Battery/MWE_hmin.py", line 11, in <module>
    hmin = mesh.comm.allreduce(min(dolfinx.cpp.mesh.h(mesh, tdim, range(num_cells))), op=MPI.MIN)
TypeError: h(): incompatible function arguments. The following argument types are supported:
    1. (mesh: dolfinx.cpp.mesh.Mesh_float32, dim: int, entities: numpy.ndarray[numpy.int32]) -> numpy.ndarray[numpy.float32]
    2. (mesh: dolfinx.cpp.mesh.Mesh_float64, dim: int, entities: numpy.ndarray[numpy.int32]) -> numpy.ndarray[numpy.float64]

Invoked with: <dolfinx.mesh.Mesh object at 0x7fb98c292260>, 2, range(0, 5000)

FEniCSX: 0.7.2 (installed via docker-container)
Ubuntu: 22.04

Thank you in advance and have a nice weekend!

With kind regards
Dejan

Can you double check the dolfinx version with

python3 -c 'import dolfinx; print(dolfinx.__version__)'

?

My suspicion is that you pulled the nightly docker tag, rather than the stable, and thus you have the development version.

If you are indeed on 0.7.2, try with

mesh.h(tdim, range(num_cells))

If you are the nightly tag try instead

mesh.h(tdim, np.arange(num_cells))

where mesh is the actual mesh object (not dolfinx.mesh or dolfinx.cpp.mesh).

1 Like

I have checked my version as you suggested and it is version 0.7.2.

Your solution for this version works perfectly! Thank you for the quick response.