Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create multiple groups of volumes at once #9

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions dagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ def write_file(self, filename):
"""
self.mb.write_file(filename)

def add_groups(self, group_map):
"""Adds groups of DAGSets to the model.

Parameters
----------
group_map : dict
eepeterson marked this conversation as resolved.
Show resolved Hide resolved
A dictionary whose keys are 2-tuples of (str, int) containing the
group name and group ID respectively and whose values are iterables
of DAGSet objects or DAGSet ID numbers.
"""
for (group_name, group_id), dagsets in group_map.items():
group = Group.create(self, name=group_name, group_id=group_id)

for dagset in dagsets:
if isinstance(dagset, DAGSet):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case isn't tested. No reason to think it won't work, but may as well keep the test coverage up...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point - I added a case for volume and surfaces

group.add_set(dagset)
else:
if dagset in self.volumes:
group.add_set(self.volumes[dagset])
elif dagset in self.surfaces:
group.add_set(self.surfaces[dagset])
else:
raise ValueError(f"DAGSet ID={dagset} could not be "
"found in model volumes or surfaces.")


class DAGSet:
"""
Expand Down
32 changes: 31 additions & 1 deletion test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,34 @@ def test_area(request):
10: np.pi * 10**2,
11: np.pi * 10**2 }
for surf_id, exp_area in exp_areas.items():
pytest.approx(model.surfaces[surf_id].area, exp_area)
pytest.approx(model.surfaces[surf_id].area, exp_area)


def test_add_groups(request):
test_file = str(request.path.parent / 'fuel_pin.h5m')
model = dagmc.DAGModel(test_file)
volumes = model.volumes
surfaces = model.surfaces

for group in model.groups.values():
group.delete()

assert len(model.groups) == 0

group_map = {("mat:fuel", 1): [1, 2],
("mat:Graveyard", 0): [volumes[6]],
("mat:41", 2): [3],
("boundary:Reflecting", 3): [27, 28, 29],
("boundary:Vacuum", 4): [surfaces[24], surfaces[25]]
}

model.add_groups(group_map)

groups = model.groups

assert len(groups) == 5
assert [1, 2] == sorted(groups['mat:fuel'].get_volume_ids())
assert [6] == groups['mat:Graveyard'].get_volume_ids()
assert [3] == groups['mat:41'].get_volume_ids()
assert [27, 28, 29] == sorted(groups['boundary:Reflecting'].get_surface_ids())
assert [24, 25] == sorted(groups['boundary:Vacuum'].get_surface_ids())
Loading