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

Fixing bug when attempting to edit a cell geometry #562

Merged
merged 7 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
MontePy Changelog
=================

#Next Version#
--------------

**Bug Fixes**

* Fixed a bug raised in an edge case when editing cell geometry, by making the error clearer (:issue:`558`).

0.4.1
--------------

Expand Down
8 changes: 8 additions & 0 deletions montepy/surfaces/half_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ def _add_new_children_to_cell(self, other):
(cells, surfaces), (self._cell.complements, self._cell.surfaces)
):
for item in container:
if not isinstance(
item, (montepy.surfaces.surface.Surface, montepy.Cell)
):
raise IllegalState(
f"The geometry was not fully initialized, and cannot be changed. "
f"The offending cell is {self._cell}. "
f"Run cell.update_pointers."
)
if item not in parent:
parent.append(item)

Expand Down
17 changes: 2 additions & 15 deletions montepy/surfaces/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,8 @@ def __lt__(self, other):
return self.number < other.number

def __eq__(self, other):
return (
self.number == other.number
and self.surface_type == other.surface_type
and self.is_reflecting == other.is_reflecting
and self.is_white_boundary == other.is_white_boundary
and self.surface_constants == other.surface_constants
)

def __ne__(self, other):
return not self == other

def __hash__(self):
return hash((self.number, str(self.surface_type)))

def __eq__(self, other):
if not isinstance(other, type(self)):
return False
return (
self.number == other.number
and self.surface_type == other.surface_type
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies = [
[project.optional-dependencies]
test = [
"coverage[toml]>=6.3.2",
"hypothesis",
"pytest",
"pytest-profiling",
"montepy[build]",
Expand Down
40 changes: 40 additions & 0 deletions tests/test_geom_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from hypothesis import given
import hypothesis.strategies as st

import montepy

import pytest

geom_pair = st.tuples(st.integers(min_value=1), st.booleans())


@given(
st.integers(min_value=1), st.lists(geom_pair, min_size=1, unique_by=lambda x: x[0])
)
def test_build_arbitrary_cell_geometry(first_surf, new_surfaces):
input = montepy.input_parser.mcnp_input.Input(
[f"1 0 {first_surf} imp:n=1"], montepy.input_parser.block_type.BlockType.CELL
)
cell = montepy.Cell(input)
surf = montepy.surfaces.surface.Surface()
surf.number = first_surf
cell.update_pointers([], [], montepy.surface_collection.Surfaces([surf]))
for surf_num, operator in new_surfaces:
surf = montepy.surfaces.surface.Surface()
surf.number = surf_num
if operator:
cell.geometry &= +surf
else:
cell.geometry |= -surf
assert len(cell.geometry) == len(new_surfaces) + 1


def test_cell_geometry_set_warns():
input = montepy.input_parser.mcnp_input.Input(
[f"1 0 -1 imp:n=1"], montepy.input_parser.block_type.BlockType.CELL
)
cell = montepy.Cell(input)
with pytest.raises(montepy.errors.IllegalState):
surf = montepy.surfaces.surface.Surface()
surf.number = 5
cell.geometry &= +surf