From e2023fcbc20dabd58778252adb04714fb972ae4b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sun, 21 Apr 2024 10:49:19 -0500 Subject: [PATCH 1/3] Add create_* methods on DAGModel class --- dagmc/dagnav.py | 13 +++++++++++++ test/test_basic.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/dagmc/dagnav.py b/dagmc/dagnav.py index ca496f0..9664214 100644 --- a/dagmc/dagnav.py +++ b/dagmc/dagnav.py @@ -156,6 +156,19 @@ def add_groups(self, group_map): raise ValueError(f"DAGSet ID={dagset} could not be " "found in model volumes or surfaces.") + def create_group(self, name: Optional[str] = None, group_id: Optional[int] = None) -> Group: + """Create a new group instance with the given name, + or return an existing group if one exists.""" + return Group.create(self, name, group_id) + + def create_volume(self, global_id: Optional[int] = None) -> Volume: + """Create a new volume""" + return Volume.create(self, global_id) + + def create_surface(self, global_id: Optional[int] = None) -> Surface: + """Create a new surface""" + return Surface.create(self, global_id) + class DAGSet: """ diff --git a/test/test_basic.py b/test/test_basic.py index d6efa1f..e216d09 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -100,6 +100,9 @@ def test_group_merge(request): for vol in model.volumes: new_group.add_set(vol) + # using create_group should give same thing + assert model.create_group('mat:fuel') == new_group + assert orig_group == new_group assert len((new_group.volume_ids)) == len(model.volumes) @@ -130,6 +133,10 @@ def test_volume(request): assert new_vol.id == 100 assert model.volumes_by_id[100] == new_vol + new_vol2 = model.create_volume(200) + assert isinstance(new_vol2, dagmc.Volume) + assert new_vol2.id == 200 + assert model.volumes_by_id[200] == new_vol2 def test_surface(request): test_file = str(request.path.parent / 'fuel_pin.h5m') @@ -188,6 +195,11 @@ def test_id_safety(request): assert new_surf.id == 100 assert model.surfaces_by_id[100] == new_surf + new_surf2 = model.create_surface(200) + assert isinstance(new_surf2, dagmc.Surface) + assert new_surf2.id == 200 + assert model.surfaces_by_id[200] == new_surf2 + def test_hash(request): test_file = str(request.path.parent / 'fuel_pin.h5m') From deb9433f86a2e9c644573ce16e40b501ef794c47 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 26 Apr 2024 07:14:08 -0500 Subject: [PATCH 2/3] Add test for group creation --- test/test_basic.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_basic.py b/test/test_basic.py index e216d09..eafb2cb 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -114,6 +114,22 @@ def test_group_merge(request): assert 3 in fuel_group.volumes_by_id +def test_group_create(request): + test_file = str(request.path.parent / 'fuel_pin.h5m') + model = dagmc.DAGModel(test_file) + orig_num_groups = len(model.groups) + + # Create two new groups + new_group1 = dagmc.Group.create(model, 'mat:slime') + new_group2 = model.create_group('mat:plastic') + + assert 'mat:slime' in model.groups_by_name + assert 'mat:plastic' in model.groups_by_name + assert model.groups_by_name['mat:slime'] == new_group1 + assert model.groups_by_name['mat:plastic'] == new_group2 + assert len(model.groups) == orig_num_groups + 2 + + def test_volume(request): test_file = str(request.path.parent / 'fuel_pin.h5m') model = dagmc.DAGModel(test_file) From d8755cca9d000c019c8b6ded2a02970b709fb316 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 26 Apr 2024 07:14:57 -0500 Subject: [PATCH 3/3] Apply @gonuke suggestions from code review Co-authored-by: Paul Wilson --- dagmc/dagnav.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dagmc/dagnav.py b/dagmc/dagnav.py index 9664214..4d79bb6 100644 --- a/dagmc/dagnav.py +++ b/dagmc/dagnav.py @@ -157,16 +157,16 @@ def add_groups(self, group_map): "found in model volumes or surfaces.") def create_group(self, name: Optional[str] = None, group_id: Optional[int] = None) -> Group: - """Create a new group instance with the given name, + """Create a new empty group instance with the given name, or return an existing group if one exists.""" return Group.create(self, name, group_id) def create_volume(self, global_id: Optional[int] = None) -> Volume: - """Create a new volume""" + """Create a new empty volume set""" return Volume.create(self, global_id) def create_surface(self, global_id: Optional[int] = None) -> Surface: - """Create a new surface""" + """Create a new empty surface set""" return Surface.create(self, global_id)