Skip to content

Commit

Permalink
Merge pull request #22 from paulromano/create-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise authored Apr 26, 2024
2 parents 1ad729c + d8755cc commit 1141d5d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 empty volume set"""
return Volume.create(self, global_id)

def create_surface(self, global_id: Optional[int] = None) -> Surface:
"""Create a new empty surface set"""
return Surface.create(self, global_id)


class DAGSet:
"""
Expand Down
28 changes: 28 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -111,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)
Expand All @@ -130,6 +149,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')
Expand Down Expand Up @@ -188,6 +211,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')
Expand Down

0 comments on commit 1141d5d

Please sign in to comment.