write cell_sets more carefully, fixes
@@ -55,14 +55,13 @@ def read_buffer(f, is_ascii, data_size):
if environ == "PhysicalNames":
_read_physical_names(f, field_data)
- cell_sets = {k: [] for k in field_data.keys()}
elif environ == "Entities":
physical_tags = _read_entities(f, is_ascii, data_size)
elif environ == "Nodes":
points, point_tags = _read_nodes(f, is_ascii, data_size)
elif environ == "Elements":
- cells, cell_tags = _read_elements(
- f, point_tags, physical_tags, is_ascii, data_size, field_data, cell_sets
+ cells, cell_tags, cell_sets = _read_elements(
+ f, point_tags, physical_tags, is_ascii, data_size, field_data
)
elif environ == "Periodic":
periodic = _read_periodic(f, is_ascii, data_size)
@@ -177,7 +176,7 @@ def _read_nodes(f, is_ascii, data_size):
def _read_elements(
- f, point_tags, physical_tags, is_ascii, data_size, field_data, cell_sets
+ f, point_tags, physical_tags, is_ascii, data_size, field_data
):
fromfile = partial(numpy.fromfile, sep=" " if is_ascii else "")
c_size_t = _size_type(data_size)
@@ -189,22 +188,20 @@ def _read_elements(
data = []
cell_data = {}
+ cell_sets = {k: [None] * num_entity_blocks for k in field_data.keys()}
for k in range(num_entity_blocks):
# entityDim(int) entityTag(int) elementType(int) numElements(size_t)
dim_entity, tag_entity, type_ele = fromfile(f, c_int, 3)
(num_ele,) = fromfile(f, c_size_t, 1)
for physical_name, cell_set in cell_sets.items():
- if physical_tags:
- for physical_tag in physical_tags[dim_entity][tag_entity]:
- cell_set.append(
- numpy.arange(
- num_ele
- if field_data[physical_name][0] == physical_tag
+ cell_set[k] = numpy.arange(
+ num_ele if (physical_tags and
+ field_data[physical_name][1] == dim_entity and
+ field_data[physical_name][0]
+ in physical_tags[dim_entity][tag_entity])
else 0,
- dtype=type(num_ele),
- )
- )
+ dtype=type(num_ele))
tpe = _gmsh_to_meshio_type[type_ele]
num_nodes_per_ele = num_nodes_per_cell[tpe]
d = fromfile(f, c_size_t, int(num_ele * (1 + num_nodes_per_ele))).reshape(
@@ -243,7 +240,7 @@ def _read_elements(
)
cells[:] = _gmsh_to_meshio_order(cells)
- return cells, cell_data
+ return cells, cell_data, cell_sets
def _read_periodic(f, is_ascii, data_size):
