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

Improving grid tests and documentation #1524

Merged
merged 5 commits into from
Dec 7, 2023
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
12 changes: 8 additions & 4 deletions armi/reactor/grids/hexagonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class HexGrid(StructuredGrid):
It is recommended to use :meth:`fromPitch` rather than
calling the ``__init__`` constructor directly.

.. impl:: Construct a hexagonal lattice.
:id: I_ARMI_GRID_HEX
:implements: R_ARMI_GRID_HEX

Notes
-----
In an axial plane (i, j) are as follows (second one is pointedEndUp)::
Expand All @@ -74,14 +78,14 @@ def fromPitch(pitch, numRings=25, armiObject=None, pointedEndUp=False, symmetry=
"""
Build a finite step-based 2-D hex grid from a hex pitch in cm.

.. impl:: Construct a hexagonal lattice.
:id: I_ARMI_GRID_HEX
:implements: R_ARMI_GRID_HEX

.. impl:: Hexagonal grids can be points-up or flats-up.
:id: I_ARMI_GRID_HEX_TYPE
:implements: R_ARMI_GRID_HEX_TYPE

.. impl:: The user can specify the symmetry of a hexagonal grid when creating one.
:id: I_ARMI_GRID_SYMMETRY1
:implements: R_ARMI_GRID_SYMMETRY

Parameters
----------
pitch : float
Expand Down
46 changes: 24 additions & 22 deletions armi/reactor/grids/tests/test_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,8 @@ def test_thirdAndFullSymmetry(self):
:id: T_ARMI_GRID_SYMMETRY
:tests: R_ARMI_GRID_SYMMETRY
"""
full = grids.HexGrid.fromPitch(1.0)
full.symmetry = str(
geometry.SymmetryType(
geometry.DomainType.FULL_CORE, geometry.BoundaryType.NO_SYMMETRY
)
)
third = grids.HexGrid.fromPitch(1.0)
third.symmetry = str(
geometry.SymmetryType(
geometry.DomainType.THIRD_CORE, geometry.BoundaryType.PERIODIC
)
)
full = grids.HexGrid.fromPitch(1.0, symmetry="full core")
third = grids.HexGrid.fromPitch(1.0, symmetry="third core periodic")

# check full core
self.assertEqual(full.getMinimumRings(2), 2)
Expand Down Expand Up @@ -453,16 +443,28 @@ def test_adjustPitch(self):
:id: T_ARMI_GRID_GLOBAL_POS0
:tests: R_ARMI_GRID_GLOBAL_POS
"""
grid = grids.HexGrid.fromPitch(1.0, numRings=3)
v1 = grid.getCoordinates((1, 0, 0))
grid.changePitch(2.0)
v2 = grid.getCoordinates((1, 0, 0))
assert_allclose(2 * v1, v2)
self.assertEqual(grid.pitch, 2.0)

# test number of rings
numRings = 3
self.assertEqual(grid._unitStepLimits[0][1], numRings)
# run this test for a grid with no offset, and then a few random offset values
for offset in [0, 1, 1.123, 3.14]:
# build a hex grid with pitch=1, 3 rings, and the above offset
grid = grids.HexGrid(
unitSteps=((1.5 / math.sqrt(3), 0.0, 0.0), (0.5, 1, 0.0), (0, 0, 0)),
unitStepLimits=((-3, 3), (-3, 3), (0, 1)),
offset=numpy.array([offset, offset, offset]),
)

# test that we CAN change the pitch, and it scales the grid (but not the offset)
v1 = grid.getCoordinates((1, 0, 0))
grid.changePitch(2.0)
v2 = grid.getCoordinates((1, 0, 0))
assert_allclose(2 * v1 - offset, v2)
self.assertEqual(grid.pitch, 2.0)

# basic sanity: test number of rings has changed
self.assertEqual(grid._unitStepLimits[0][1], 3)

# basic sanity: check the offset exists and is correct
for i in range(3):
self.assertEqual(grid.offset[i], offset)

def test_badIndices(self):
grid = grids.HexGrid.fromPitch(1.0, numRings=3)
Expand Down
11 changes: 10 additions & 1 deletion armi/reactor/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,9 +2077,18 @@ def test_gridCreation(self):
# Then it's spatialLocator must be of size 169
locations = c.spatialLocator
self.assertEqual(type(locations), grids.MultiIndexLocation)

mult = 0
for _ in locations:
uniqueLocations = set()
for loc in locations:
mult = mult + 1

# test for the uniqueness of the locations (since mult > 1)
if loc not in uniqueLocations:
uniqueLocations.add(loc)
else:
self.assertTrue(False, msg="Duplicate location found!")

self.assertEqual(mult, 169)

def test_gridNumPinsAndLocations(self):
Expand Down
Loading