Hi everybody,
Currently, I translate my ‘classical’ dolfincode to dolfinx. Among others, I face the problem of evaluating all cell sizes by doing:
elemsize = [c.h() for c in cells(mesh)]
But that doesn’t work under dolfinx. As far as I noticed, the ‘hmin’ attribute (see dolfinx.cpp.mesh — DOLFINX documentation) should give me the option the get the smallest cell size (and via ‘hmax’ the maximal cell size). But unfortunately, it doesn’t work.
I should mention that I read xdmf-meshes into dolfinx that are created by converting msh files into xdmf. My python function doing this reads
import sys
# converts msh to xdmf
# essential for dolfinx
# see
# https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/147
model_name = sys.argv[1]
dim = sys.argv[2] # 2d or 3d
import meshio # python3 -m pip install meshio
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
if prune_z:
out_mesh.prune_z_0()
return out_mesh
# Read in mesh
msh = meshio.read(f"{model_name}.msh")
# Create and save one file for the mesh, and one file for the facets
if dim == '2d':
triangle_mesh = create_mesh(msh, "triangle", prune_z=True)
line_mesh = create_mesh(msh, "line", prune_z=True)
meshio.write(f"{model_name}_mesh.xdmf", triangle_mesh)
meshio.write(f"{model_name}_mt.xdmf", line_mesh)
elif dim == '3d':
tetra_mesh = create_mesh(msh, "tetra")
triangle_mesh = create_mesh(msh, "triangle")
meshio.write(f"{model_name}_mesh.xdmf", tetra_mesh)
meshio.write(f"{model_name}_mt.xdmf", triangle_mesh)
Has anybody an idea how I can get the whole array of cell sizes for doing some ‘statistics’?
Thanks for the help!