From b580dbd671bc0b642da63bd1e7b23eb459eed414 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Jan 2024 09:16:47 -0600 Subject: [PATCH] Making IDs on sets mutable --- dagmc/dagnav.py | 8 +++++++- test/test_basic.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dagmc/dagnav.py b/dagmc/dagnav.py index 71ba8b7..592a30d 100644 --- a/dagmc/dagnav.py +++ b/dagmc/dagnav.py @@ -91,6 +91,12 @@ def id(self): """ return self.model.mb.tag_get_data(self.model.id_tag, self.handle, flat=True)[0] + @id.setter + def id(self, i): + """Set the DAGMC set's ID. + """ + self.model.mb.tag_set_data(self.model.id_tag, self.handle, i) + @property def geom_dimension(self): """Return the DAGMC set's geometry dimension. @@ -334,4 +340,4 @@ def create(cls, model, name): mb.tag_set_data(model.name_tag, group_handle, name) mb.tag_set_data(model.category_tag, group_handle, 'Group') mb.tag_set_data(model.geom_dimension_tag, group_handle, 4) - return cls(model, group_handle) \ No newline at end of file + return cls(model, group_handle) diff --git a/test/test_basic.py b/test/test_basic.py index def0992..8bf1c74 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -82,6 +82,13 @@ def test_group_merge(request): new_group = dagmc.Group.create(model, 'mat:fuel') assert orig_group != new_group + + # check that we can update a set ID + assert new_group.id == -1 + new_group.id = 100 + assert new_group.id == 100 + + # merge the new group into the existing group orig_group.merge(new_group) assert orig_group == new_group @@ -102,7 +109,6 @@ def test_group_merge(request): # volume set w/ ID 3 now fuel_group = groups['mat:fuel'] assert 3 in fuel_group.get_volumes() - assert len(fuel_group.get_volumes()) == orig_group_size + 1 def test_compressed_coords(request, capfd):