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 DAGSet.create classmethod #13

Merged
merged 5 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions dagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ def delete(self):
self.handle = None
self.model = None

@classmethod
def create(cls, model: DAGModel, global_id: Optional[int] = None) -> Surface:
"""Create new set"""
paulromano marked this conversation as resolved.
Show resolved Hide resolved
# Add necessary tags for this meshset to be identified appropriately
ent_set = DAGSet(model, model.mb.create_meshset())
ent_set.geom_dimension = cls._geom_dimension
ent_set.category = cls._category
if global_id is not None:
gonuke marked this conversation as resolved.
Show resolved Hide resolved
ent_set.id = global_id

# Now that entity set has proper tags, create derived class and return
return cls(model, ent_set.handle)
paulromano marked this conversation as resolved.
Show resolved Hide resolved


class Surface(DAGSet):

_category = 'Surface'
Expand Down Expand Up @@ -508,6 +522,7 @@ def volume(self):
volume += sign * sum
return volume / 6.0


class Group(DAGSet):

_category: str = 'Group'
Expand Down
10 changes: 10 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def test_volume(request):
assert v1 in model.groups_by_name['mat:olive oil']
assert v1 not in model.groups_by_name['mat:fuel']

new_vol = dagmc.Volume.create(model, 100)
assert isinstance(new_vol, dagmc.Volume)
assert new_vol.id == 100
assert model.volumes[100] == new_vol


def test_surface(request):
test_file = str(request.path.parent / 'fuel_pin.h5m')
Expand Down Expand Up @@ -178,6 +183,11 @@ def test_id_safety(request):
assert g1.id == safe_grp_id


new_surf = dagmc.Surface.create(model, 100)
assert isinstance(new_surf, dagmc.Surface)
assert new_surf.id == 100
assert model.surfaces[100] == new_surf
paulromano marked this conversation as resolved.
Show resolved Hide resolved


def test_hash(request):
test_file = str(request.path.parent / 'fuel_pin.h5m')
Expand Down
Loading