Skip to content

Commit

Permalink
Merge pull request #5 from paulromano/surface-vol-props
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored Feb 15, 2024
2 parents a400ca6 + 4357068 commit e596565
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
59 changes: 57 additions & 2 deletions dagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ def geom_dimension_tag(self):
create_if_missing=True,
)

@cached_property
def surf_sense_tag(self):
"""Surface sense tag."""
return self.mb.tag_get_handle(
"GEOM_SENSE_2",
2,
types.MB_TYPE_HANDLE,
types.MB_TAG_SPARSE,
create_if_missing=True,
)

def write_file(self, filename):
"""Write the model to a file.
Expand All @@ -100,6 +111,7 @@ def write_file(self, filename):
"""
self.mb.write_file(filename)


class DAGSet:
"""
Generic functionality for a DAGMC EntitySet.
Expand Down Expand Up @@ -303,10 +315,53 @@ def __init__(self, model: DAGModel, handle: np.uint64):
super().__init__(model, handle)
self._check_category_and_dimension()

def get_volumes(self):
@property
def surf_sense(self) -> list[Optional[Volume]]:
"""Surface sense data."""
try:
handles = self.model.mb.tag_get_data(
self.model.surf_sense_tag, self.handle, flat=True
)
except RuntimeError:
return [None, None]
return [Volume(self.model, handle) if handle != 0 else None
for handle in handles]

@surf_sense.setter
def surf_sense(self, volumes: list[Optional[Volume]]):
if len(volumes) != 2:
raise ValueError("surf_sense should be a list of two volumes.")
sense_data = [vol.handle if vol is not None else np.uint64(0)
for vol in volumes]
self._tag_set_data(self.model.surf_sense_tag, sense_data)

# Establish parent-child relationships
for vol in volumes:
if vol is not None:
self.model.mb.add_parent_child(vol.handle, self.handle)

@property
def forward_volume(self) -> Optional[Volume]:
"""Volume with forward sense with respect to the surface."""
return self.surf_sense[0]

@forward_volume.setter
def forward_volume(self, volume: Volume):
self.surf_sense = [volume, self.reverse_volume]

@property
def reverse_volume(self) -> Optional[Volume]:
"""Volume with reverse sense with respect to the surface."""
return self.surf_sense[1]

@reverse_volume.setter
def reverse_volume(self, volume: Volume):
self.surf_sense = [self.forward_volume, volume]

def get_volumes(self) -> list[Volume]:
"""Get the parent volumes of this surface.
"""
return [Volume(self.model.mb, h) for h in self.model.mb.get_parent_meshsets(self.handle)]
return [Volume(self.model, h) for h in self.model.mb.get_parent_meshsets(self.handle)]

def num_triangles(self):
"""Returns the number of triangles in this surface"""
Expand Down
18 changes: 18 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ def test_volume(request):
assert v1 not in model.groups['mat:fuel']


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

s1 = model.surfaces[1]
assert s1.get_volumes() == [model.volumes[1], model.volumes[2]]
assert s1.forward_volume == model.volumes[1]
assert s1.reverse_volume == model.volumes[2]

s1.forward_volume = model.volumes[3]
assert s1.forward_volume == model.volumes[3]
assert s1.surf_sense == [model.volumes[3], model.volumes[2]]

s1.reverse_volume = model.volumes[1]
assert s1.reverse_volume == model.volumes[1]
assert s1.surf_sense == [model.volumes[3], model.volumes[1]]


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

0 comments on commit e596565

Please sign in to comment.