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

Fix getNeighboringCellIndices #1614

Merged
merged 3 commits into from
Jan 25, 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
2 changes: 1 addition & 1 deletion armi/reactor/grids/structuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def _meshBaseByBounds(index, bounds):
@staticmethod
def getNeighboringCellIndices(i, j=0, k=0):
"""Return the indices of the immediate neighbors of a mesh point in the plane."""
return ((i + 1, j, k), (1, j + 1, k), (i - 1, j, k), (i, j - 1, k))
return ((i + 1, j, k), (i, j + 1, k), (i - 1, j, k), (i, j - 1, k))

@staticmethod
def getAboveAndBelowCellIndices(indices):
Expand Down
27 changes: 27 additions & 0 deletions armi/reactor/tests/test_reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,3 +1376,30 @@ def test_getNuclideCategoriesLogging(self):

self.assertIn("Nuclide categorization", messages)
self.assertIn("Structure", messages)


class CartesianReactorNeighborTests(ReactorTests):
def setUp(self):
self.r = loadTestReactor(TEST_ROOT, inputFileName="zpprTest.yaml")[1]

def test_findNeighborsCartesian(self):
"""Find neighbors of a given assembly in a Cartesian grid."""
loc = self.r.core.spatialGrid[1, 1, 0]
a = self.r.core.childrenByLocator[loc]
neighbs = self.r.core.findNeighbors(a)
locs = [tuple(a.spatialLocator.indices[:2]) for a in neighbs]
self.assertEqual(len(neighbs), 4)
self.assertIn((2, 1), locs)
self.assertIn((1, 2), locs)
self.assertIn((0, 1), locs)
self.assertIn((1, 0), locs)

# try with edge assembly
loc = self.r.core.spatialGrid[0, 0, 0]
a = self.r.core.childrenByLocator[loc]
neighbs = self.r.core.findNeighbors(a, showBlanks=False)
locs = [tuple(a.spatialLocator.indices[:2]) for a in neighbs]
self.assertEqual(len(neighbs), 2)
# in this case no locations that aren't actually in the core should be returned
self.assertIn((1, 0), locs)
self.assertIn((0, 1), locs)
2 changes: 1 addition & 1 deletion doc/release/0.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ What's new in ARMI?

Bug Fixes
---------
#. TBD
#. ``StructuredGrid.getNeighboringCellIndices()`` was incorrectly implemented for the second neighbor. (`PR#1614 <https://github.com/terrapower/armi/pull/1614>`_)

Changes that Affect Requirements
--------------------------------
Expand Down
Loading