Skip to content
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
# TODO: add PyMOAB once on PyPI
dependencies = ["numpy"]

Expand All @@ -49,4 +49,4 @@ ci = ["pytest-cov"]
[tool.setuptools_scm]

[tool.setuptools]
package-dir = {"" = "src"}
package-dir = {"" = "src"}
44 changes: 36 additions & 8 deletions src/pydagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def volumes_by_material(self) -> Dict[str, list[Volume]]:
A dictionary where keys are material names (str) and values
are lists of Volume objects.
"""
material_map: DefaultDict[str, list[Volume]] = defaultdict(list)
material_map: defaultdict[str, list[Volume]] = defaultdict(list)
for volume in self.volumes:
if volume.material is None:
continue
Expand Down Expand Up @@ -347,7 +347,7 @@ def _check_category_and_dimension(self):
raise ValueError(f"{identifier} has no category or geom_dimension tags assigned.")

def __eq__(self, other):
return type(other) == type(self) and \
return type(other) is type(self) and \
self.model == other.model and \
self.handle == other.handle

Expand Down Expand Up @@ -403,6 +403,11 @@ def category(self, category: str):
"""Set the DAGMC set's category."""
self._tag_set_data(self.model.category_tag, category)

@property
def groups(self) -> list[Group]:
"""Get list of groups containing this DAGMC set."""
return [group for group in self.model.groups if self in group]

@abstractmethod
def _get_triangle_sets(self):
"""Retrieve all (surface) sets under this set that contain triangle elements.
Expand Down Expand Up @@ -584,6 +589,34 @@ def reverse_volume(self) -> Optional[Volume]:
def reverse_volume(self, volume: Volume):
self.senses = [self.forward_volume, volume]

@property
def _boundary_group(self) -> Optional[Group]:
for group in self.groups:
if "boundary:" in group.name:
return group
return None

@property
def boundary(self) -> Optional[str]:
"""Name of the boundary assigned to this surface."""
group = self._boundary_group
if group is not None:
return group.name.removeprefix('boundary:')
return None

@boundary.setter
def boundary(self, name: Optional[str]):
group = self._boundary_group

if group is not None:
# Remove surface from existing group
group.remove_set(self)

# create a new group or get an existing group
if name is not None:
group = Group.create(self.model, name=f"boundary:{name}")
group.add_set(self)

@property
def volumes(self) -> list[Volume]:
"""Get the parent volumes of this surface.
Expand Down Expand Up @@ -619,12 +652,7 @@ def __init__(self, model: Model, handle: np.uint64):
self._check_category_and_dimension()

@property
def groups(self) -> list[Group]:
"""Get list of groups containing this volume."""
return [group for group in self.model.groups if self in group]

@property
def _material_group(self):
def _material_group(self) -> Optional[Group]:
for group in self.groups:
if "mat:" in group.name:
return group
Expand Down
26 changes: 25 additions & 1 deletion test/test_dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ def test_surface_sense_value_error_on_wrong_length():

# Create dummy volumes for valid input
vol1 = model.create_volume(global_id=1)

# Empty list
with pytest.raises(ValueError, match="Senses should be a list of two volumes."):
surf.senses = []
Expand Down Expand Up @@ -948,6 +948,30 @@ def test_surface_create_invalid_filename():
model.create_surface(filename='my_model.step')


def test_surface_boundary():
"""Test the boundary property of Surface."""
model = pydagmc.Model()
surf = model.create_surface(global_id=1)

# Initially, boundary should be None
assert surf.boundary is None

# Set a valid boundary condition
surf.boundary = 'Reflecting'
assert surf.boundary == 'Reflecting'
assert [1] == sorted(model.groups_by_name['boundary:Reflecting'].surface_ids)

# Change the boundary condition
surf.boundary = 'Vacuum'
assert surf.boundary == 'Vacuum'
assert [1] == sorted(model.groups_by_name['boundary:Vacuum'].surface_ids)
assert [] == sorted(model.groups_by_name['boundary:Reflecting'].surface_ids)

# Remove the boundary condition by setting it to None
surf.boundary = None
assert surf.boundary is None


def test_geometryset_category_runtime_error(request):
"""Test category returns None when tag is missing."""
model = pydagmc.Model()
Expand Down
Loading