Distribute_entity_data TypeError

Dear all,
I tried to read a 3D gmsh mesh file and transform it to xdmf file. I followed this post at Using the GMSH Python API to generate complex meshes | Jørgen S. Dokken. However an error occurred:

Traceback (most recent call last):
  File "/mnt/d/Workspace/RFQ/mesh_transform.py", line 43, in <module>
    local_entities, local_values = distribute_entity_data(mesh, mesh.topology.dim, cells, cell_values)
TypeError: distribute_entity_data(): incompatible function arguments. The following argument types are supported:
    1. (mesh: dolfinx.cpp.mesh.Mesh, entity_dim: int, entities: numpy.ndarray[numpy.int64], values: numpy.ndarray[numpy.int32]) -> Tuple[numpy.ndarray[numpy.int32], numpy.ndarray[numpy.int32]]

Invoked with: <dolfinx.mesh.Mesh object at 0x7f24bf7d7f70>, 2, array([[ 1114,     4, 57163],
       [    4,  5563, 57163],
       [    5,  1131, 57834],
       ...,
       [17235, 16870, 17879],
       [17326, 16892, 17439],
       [17257, 17220, 17645]]), array([23, 23, 23, ..., 25, 25, 25], dtype=int32)

Thank you very much if anyone can help me.

Please provide a minimal reproducible example, as one cannot do much with just the error msssage.

Dear dokken,
In order to provide a minimal example, I created a box using gmsh and grenerated the mesh. Now another error occurred, and the msh file and my code are also listed below.

Info    : Reading 'untitled.msh'...
Info    : 27 entities
Info    : 13 nodes
Info    : 20 elements
Info    : Done reading 'untitled.msh'
malloc(): unaligned tcache chunk detected
[WIN-LBEUVJDAK3Q:00431] *** Process received signal ***
malloc(): unaligned tcache chunk detected
$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
8 12 6 1
1 -0.1 0.1 0.001 0 
2 -0.1 0.1 0 0 
3 -0.1 0.101 0.001 0 
4 -0.1 0.101 0 0 
5 -0.099 0.1 0.001 0 
6 -0.099 0.1 0 0 
7 -0.099 0.101 0.001 0 
8 -0.099 0.101 0 0 
1 -0.1000001 0.0999999 -9.999999999994822e-08 -0.0999999 0.1000001 0.0010001 0 2 2 -1 
2 -0.1000001 0.0999999 0.0009999 -0.0999999 0.1010001 0.0010001 0 2 1 -3 
3 -0.1000001 0.1009999 -9.999999999994822e-08 -0.0999999 0.1010001 0.0010001 0 2 4 -3 
4 -0.1000001 0.0999999 -1e-07 -0.0999999 0.1010001 1e-07 0 2 2 -4 
5 -0.09900010000000001 0.0999999 -9.999999999994822e-08 -0.0989999 0.1000001 0.0010001 0 2 6 -5 
6 -0.09900010000000001 0.0999999 0.0009999 -0.0989999 0.1010001 0.0010001 0 2 5 -7 
7 -0.09900010000000001 0.1009999 -9.999999999994822e-08 -0.0989999 0.1010001 0.0010001 0 2 8 -7 
8 -0.09900010000000001 0.0999999 -1e-07 -0.0989999 0.1010001 1e-07 0 2 6 -8 
9 -0.1000001 0.0999999 -1e-07 -0.0989999 0.1000001 1e-07 0 2 2 -6 
10 -0.1000001 0.0999999 0.0009999 -0.0989999 0.1000001 0.0010001 0 2 1 -5 
11 -0.1000001 0.1009999 -1e-07 -0.0989999 0.1010001 1e-07 0 2 4 -8 
12 -0.1000001 0.1009999 0.0009999 -0.0989999 0.1010001 0.0010001 0 2 3 -7 
1 -0.1000001 0.0999999 -9.999999999994822e-08 -0.0999999 0.1010001 0.0010001 2 13 14 4 -1 4 3 -2 
2 -0.09900010000000001 0.0999999 -9.999999999994822e-08 -0.0989999 0.1010001 0.0010001 2 13 14 4 -5 8 7 -6 
3 -0.1000001 0.0999999 -9.999999999994822e-08 -0.0989999 0.1000001 0.0010001 1 13 4 -9 1 10 -5 
4 -0.1000001 0.1009999 -9.999999999994822e-08 -0.0989999 0.1010001 0.0010001 0 4 -11 3 12 -7 
5 -0.1000001 0.0999999 -1e-07 -0.0989999 0.1010001 1e-07 1 14 4 -4 9 8 -11 
6 -0.1000001 0.0999999 0.0009999 -0.0989999 0.1010001 0.0010001 2 13 14 4 -2 10 6 -12 
1 -0.1000001 0.0999999 -9.999999999994822e-08 -0.0989999 0.1010001 0.0010001 0 6 -1 2 -3 4 -5 6 
$EndEntities
$Nodes
13 13 1 13
0 1 0 1
1
-0.1 0.1 0.001
0 2 0 1
2
-0.1 0.1 0
0 3 0 1
3
-0.1 0.101 0.001
0 4 0 1
4
-0.1 0.101 0
0 5 0 1
5
-0.099 0.1 0.001
0 6 0 1
6
-0.099 0.1 0
0 7 0 1
7
-0.099 0.101 0.001
0 8 0 1
8
-0.099 0.101 0
2 1 0 1
9
-0.1 0.1005 0.0005
2 2 0 1
10
-0.099 0.1005 0.0005
2 3 0 1
11
-0.09950000000000001 0.1 0.0005
2 5 0 1
12
-0.09950000000000001 0.1005 0
2 6 0 1
13
-0.09950000000000001 0.1005 0.001
$EndNodes
$Elements
5 20 1 20
2 1 2 4
1 2 1 9 
2 1 3 9 
3 4 2 9 
4 3 4 9 
2 2 2 4
5 6 10 5 
6 5 10 7 
7 8 10 6 
8 7 10 8 
2 3 2 4
9 1 2 11 
10 5 1 11 
11 2 6 11 
12 6 5 11 
2 5 2 4
13 2 4 12 
14 6 2 12 
15 4 8 12 
16 8 6 12 
2 6 2 4
17 1 13 3 
18 5 13 1 
19 3 13 7 
20 7 13 5 
$EndElements
from dolfinx.io import gmshio, XDMFFile

from dolfinx.mesh import create_mesh

from mpi4py import MPI

from dolfinx.cpp.io import perm_gmsh

from dolfinx.cpp.mesh import to_type

from dolfinx.cpp.graph import AdjacencyList_int32

from dolfinx.io import distribute_entity_data

from dolfinx.cpp.mesh import cell_entity_type

from dolfinx.mesh import meshtags_from_entities

import numpy as np

import gmsh

mesh_comm = MPI.COMM_WORLD

gdim = 3

gmsh_model_rank = 0

gmsh.initialize()

gmsh.open('untitled.msh')

#gmsh.open('pole-FEMMeshGmsh.msh')

x = gmshio.extract_geometry(gmsh.model)

topologies = gmshio.extract_topology_and_markers(gmsh.model)

num_cell_types = len(topologies.keys())

cell_information = {}

cell_dimensions = np.zeros(num_cell_types, dtype=np.int32)

for i, element in enumerate(topologies.keys()):

properties = gmsh.model.mesh.getElementProperties(element)

name, dim, order, num_nodes, local_coords, _ = properties

cell_information[i] = {"id": element, "dim": dim,

"num_nodes": num_nodes}

cell_dimensions[i] = dim

gmsh.finalize()

perm_sort = np.argsort(cell_dimensions)

cell_id = cell_information[perm_sort[-1]]["id"]

cells = np.asarray(topologies[cell_id]["topology"], dtype=np.int64)

ufl_domain = gmshio.ufl_mesh(cell_id, 3)

#

num_nodes = cell_information[perm_sort[-1]]["num_nodes"]

gmsh_cell_perm = perm_gmsh(to_type(str(ufl_domain.ufl_cell())), num_nodes)

cells = cells[:, gmsh_cell_perm]

mesh = create_mesh(MPI.COMM_SELF, cells, x, ufl_domain)

cell_values = np.asarray(topologies[cell_id]["cell_data"], dtype=np.int32)

local_entities, local_values = distribute_entity_data(mesh, mesh.topology.dim, cells, cell_values)

mesh.topology.create_connectivity(mesh.topology.dim, 0)

adj = AdjacencyList_int32(local_entities)

ct = meshtags_from_entities(mesh, mesh.topology.dim, adj, local_values)

ct.name = "Cell tags"

# Create MeshTags for facets

# Permute facets from MSH to DOLFINx ordering

# FIXME: This does not work for prism meshes

facet_type = cell_entity_type(to_type(str(ufl_domain.ufl_cell())), mesh.topology.dim - 1, 0)

gmsh_facet_id = cell_information[perm_sort[-2]]["id"]

num_facet_nodes = cell_information[perm_sort[-2]]["num_nodes"]

gmsh_facet_perm = perm_gmsh(facet_type, num_facet_nodes)

marked_facets = np.asarray(topologies[gmsh_facet_id]["topology"], dtype=np.int64)

facet_values = np.asarray(topologies[gmsh_facet_id]["cell_data"], dtype=np.int32)

marked_facets = marked_facets[:, gmsh_facet_perm]

local_entities, local_values = distribute_entity_data(mesh, mesh.topology.dim - 1, marked_facets, facet_values)

mesh.topology.create_connectivity(mesh.topology.dim - 1, mesh.topology.dim)

adj = AdjacencyList_int32(local_entities)

ft = meshtags_from_entities(mesh, mesh.topology.dim - 1, adj, local_values)

ft.name = "Facet tags"

Dear dokken,
Is there any simple method to write the mesh to xdmf file and visualize it in paraview? For example, just write “domain” in the following code to xdmf file.
domain, cell_markers, facet_markers = gmshio.read_from_msh('pole-FEMMeshGmsh.msh', mesh_comm, rank=gmsh_model_rank, gdim=gdim)

You haven’t supplied what version of dolfin you are running.
I also dont understand why you arent just using dolfinx.Io.gmshio.model_to_mesh or read_from_msh, which handles all the Gmsh Logic for you: https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/io/gmshio.py#L173

This function uses https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/io/gmshio.py#L281
Which calls https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/mesh.py#L422

Dear dokken,

I have similar error.

I installed fenicsx on the docker as suggested here How to compile c++ dolfinx code?.

In addition to this, I installed also gmsh with “pip3 install gmsh” (version installed gmsh-4.11.1).
The error I obtained is
7 cell_values = numpy.asarray(topologies[cell_id][“cell_data”], dtype=numpy.int32)
----> 8 local_entities, local_values = distribute_entity_data(mesh, mesh.topology.dim, cells, cell_values)
9 mesh.topology.create_connectivity(mesh.topology.dim, 0)
10 adj = AdjacencyList_int32(local_entities)

TypeError: distribute_entity_data(): incompatible function arguments. The following argument types are supported:
1. (mesh: dolfinx.cpp.mesh.Mesh, entity_dim: int, entities: numpy.ndarray[numpy.int64], values: numpy.ndarray[numpy.int32]) → Tuple[numpy.ndarray[numpy.int32], numpy.ndarray[numpy.int32]]

Invoked with: <dolfinx.mesh.Mesh object at 0x7f42db11b5e0>, 3, array([[ 6017, 23350, 28573, 31784],
[15722, 18140, 14897, 24563],
[10878, 14544, 25339, 34120],
…,
[27373, 12566, 12564, 22900],
[34333, 12566, 30310, 10419],
[34333, 30310, 12566, 12567]]), array([11, 11, 11, …, 11, 11, 11], dtype=int32)

Thank you very much for your help.

Please provide the mesh file or a script that can generate the mesh.

Dear dokken,

The file that creates the mesh (and runs into the problem) is this https://jsdokken.com/src/tutorial_gmsh.py.

I will send to your email the mesh file.
Thank you very much.