Skip to content

Commit

Permalink
split sets_to_int_data -> [cell,point]_set_to_data
Browse files Browse the repository at this point in the history
  • Loading branch information
nschloe committed Jan 20, 2022
1 parent 96b1aa5 commit 1986272
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/meshio/_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def read(cls, path_or_buf, file_format=None):
warn("meshio.Mesh.read is deprecated, use meshio.read instead")
return read(path_or_buf, file_format)

def sets_to_int_data(self):
def cell_sets_to_data(self):
# If possible, convert cell sets to integer cell data. This is possible if all
# cells appear exactly in one group.
default_value = -1
Expand Down Expand Up @@ -341,8 +341,10 @@ def sets_to_int_data(self):
self.cell_data[data_name] = intfun
self.cell_sets = {}

def point_sets_to_data(self):
# now for the point sets
# Go for -1 as the default value. (NaN is not int.)
default_value = -1
if len(self.point_sets) > 0:
intfun = np.full(len(self.points), default_value, dtype=int)
for i, cc in enumerate(self.point_sets.values()):
Expand Down
9 changes: 5 additions & 4 deletions tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def test_sets_to_int_data():
mesh = helpers.add_point_sets(mesh)
mesh = helpers.add_cell_sets(mesh)

mesh.sets_to_int_data()
mesh.point_sets_to_data()
mesh.cell_sets_to_data()

assert mesh.cell_sets == {}
assert_equal(mesh.cell_data, {"grain0-grain1": [[0, 0, 1, 1, 1]]})
Expand All @@ -57,7 +58,7 @@ def test_sets_to_int_data_warning():
cell_sets={"tag": [[0]]},
)
with pytest.warns(UserWarning):
mesh.sets_to_int_data()
mesh.cell_sets_to_data()
assert np.all(mesh.cell_data["tag"] == np.array([[0, -1]]))

mesh = meshio.Mesh(
Expand All @@ -66,7 +67,7 @@ def test_sets_to_int_data_warning():
point_sets={"tag": [[0, 1, 3]]},
)
with pytest.warns(UserWarning):
mesh.sets_to_int_data()
mesh.point_sets_to_data()

assert np.all(mesh.point_data["tag"] == np.array([[0, 0, -1, 0]]))

Expand All @@ -93,7 +94,7 @@ def test_gh_1165():
},
)

mesh.sets_to_int_data()
mesh.cell_sets_to_data()
mesh.cell_data_to_sets("test-sets")

assert_equal(mesh.cell_sets, {"test": [[], [1]], "sets": [[0, 1], [0, 2, 3]]})
Expand Down

0 comments on commit 1986272

Please sign in to comment.