Skip to content

Commit

Permalink
Merge f83297a into 6163e94
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjarrett committed Feb 28, 2024
2 parents 6163e94 + f83297a commit fed2083
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
70 changes: 63 additions & 7 deletions armi/reactor/blueprints/gridBlueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,50 @@ def __init__(self, x=0.0, y=0.0, z=0.0):
self.z = z


class Pitch(yamlize.Object):
"""A x, y, z triplet or triangular hex pitch for coordinates or lattice pitch."""

hex = yamlize.Attribute(type=float, default=0.0)
x = yamlize.Attribute(type=float, default=0.0)
y = yamlize.Attribute(type=float, default=0.0)
z = yamlize.Attribute(type=float, default=0.0)

def __init__(self, hex=0.0, x=0.0, y=0.0, z=0.0):
"""
Parameters
----------
hex : float, optional
Triangular/hex lattice pitch
x : float, optional
Cartesian grid: pitch in the x direction
Hexagonal grid: interpreted as hex lattice pitch
y : float, optional
Cartesian grid: pitch in the y direction
z : float, optional
Pitch in the z direction
Raises
------
InputError
* If a `hex` pitch and `x` or `y` pitch are provided simultaneously.
* If no non-zero value is provided for any parameter.
"""
if hex and (x or y):
raise InputError(
"Cannot mix `hex` with `x` and `y` attributes of `latticePitch`."
)

if not any(hex, x, y, z):
raise InputError(
"`lattice pitch` must have at least one non-zero attribute! Check the blueprints."
)

self.hex = hex or x
self.x = x
self.y = y
self.z = z


class GridBlueprint(yamlize.Object):
"""
A grid input blueprint.
Expand Down Expand Up @@ -174,9 +218,9 @@ class GridBlueprint(yamlize.Object):
The geometry of the grid (e.g. 'cartesian')
latticeMap : str
An asciimap representation of the lattice contents
latticeDimensions : Triplet
An x/y/z Triplet with grid dimensions in cm. This is used to specify a uniform
grid, such as Cartesian or Hex. Mutually exclusive with gridBounds.
latticeDimensions : Pitch
An x/y/z pitch or hex pitch with grid dimensions in cm. This is used to specify a
uniform grid, such as Cartesian or Hex. Mutually exclusive with gridBounds.
gridBounds : dict
A dictionary containing explicit grid boundaries. Specific keys used will depend
on the type of grid being defined. Mutually exclusive with latticeDimensions.
Expand All @@ -190,9 +234,7 @@ class GridBlueprint(yamlize.Object):
name = yamlize.Attribute(key="name", type=str)
geom = yamlize.Attribute(key="geom", type=str, default=geometry.HEX)
latticeMap = yamlize.Attribute(key="lattice map", type=str, default=None)
latticeDimensions = yamlize.Attribute(
key="lattice pitch", type=Triplet, default=None
)
latticeDimensions = yamlize.Attribute(key="lattice pitch", type=Pitch, default=None)
gridBounds = yamlize.Attribute(key="grid bounds", type=dict, default=None)
symmetry = yamlize.Attribute(
key="symmetry",
Expand Down Expand Up @@ -313,7 +355,21 @@ def _constructSpatialGrid(self):
)
spatialGrid = grids.ThetaRZGrid(bounds=(theta, radii, (0.0, 0.0)))
if geom in (geometry.HEX, geometry.HEX_CORNERS_UP):
pitch = self.latticeDimensions.x if self.latticeDimensions else 1.0
if not self.latticeDimensions:
pitch = 1.0
else:
ld = self.latticeDimensions
if ld.hex and (ld.x or ld.y):
raise InputError(
"Cannot mix `hex` with `x` and `y` attributes of `latticePitch`."
)

if not any([ld.hex, ld.x, ld.y, ld.z]):
raise InputError(
"`lattice pitch` must have at least one non-zero attribute! Check the blueprints."
)

pitch = ld.hex or ld.x
# add 2 for potential dummy assems
spatialGrid = grids.HexGrid.fromPitch(
pitch,
Expand Down
4 changes: 3 additions & 1 deletion armi/reactor/blueprints/tests/test_gridBlueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
control:
geom: hex_corners_up
symmetry: full
lattice pitch: {{hex: 1.2}}
lattice map: |
- - - - - - - - - 1 1 1 1 1 1 1 1 1 4
- - - - - - - - 1 1 1 1 1 1 1 1 1 1 1
Expand Down Expand Up @@ -360,7 +361,8 @@ def tearDown(self):

def test_simpleRead(self):
gridDesign = self.grids["control"]
_ = gridDesign.construct()
grid = gridDesign.construct()
self.assertAlmostEqual(grid.pitch, 1.2)
self.assertEqual(gridDesign.gridContents[0, -8], "6")

# Cartesian full, odd
Expand Down
2 changes: 1 addition & 1 deletion armi/reactor/grids/hexagonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def pitch(self) -> float:
--------
armi.reactor.grids.HexGrid.fromPitch
"""
return self._unitSteps[1][1]
return sqrt(self._unitSteps[0][0] ** 2 + self._unitSteps[1][0] ** 2)

@staticmethod
def indicesToRingPos(i: int, j: int) -> Tuple[int, int]:
Expand Down
7 changes: 5 additions & 2 deletions armi/reactor/grids/tests/test_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ def test_pointsUpFlatsUp(self):
self.assertEqual(tipsUp._unitSteps[0][0], 0.5)
self.assertAlmostEqual(flatsUp._unitSteps[0][0], 0.8660254037844388)

self.assertAlmostEqual(tipsUp.pitch, 1.0)
self.assertAlmostEqual(flatsUp.pitch, 1.0)

def test_triangleCoords(self):
g = grids.HexGrid.fromPitch(8.15)
indices1 = g.getIndicesFromRingAndPos(5, 3) + (0,)
Expand Down Expand Up @@ -434,7 +437,7 @@ def test_is_pickleable(self):
assert_allclose(loc.indices, newLoc.indices)

def test_adjustPitch(self):
"""Adjust the pich of a hexagonal lattice.
"""Adjust the pitch of a hexagonal lattice.
.. test:: Construct a hexagonal lattice with three rings.
:id: T_ARMI_GRID_HEX
Expand All @@ -458,7 +461,7 @@ def test_adjustPitch(self):
grid.changePitch(2.0)
v2 = grid.getCoordinates((1, 0, 0))
assert_allclose(2 * v1 - offset, v2)
self.assertEqual(grid.pitch, 2.0)
self.assertAlmostEqual(grid.pitch, 2.0)

# basic sanity: test number of rings has changed
self.assertEqual(grid._unitStepLimits[0][1], 3)
Expand Down
2 changes: 1 addition & 1 deletion armi/reactor/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ def test_retainState(self):
with self.HexBlock.retainState():
self.HexBlock.setType("fuel")
self.HexBlock.spatialGrid.changePitch(2.0)
self.assertEqual(self.HexBlock.spatialGrid.pitch, 1.0)
self.assertAlmostEqual(self.HexBlock.spatialGrid.pitch, 1.0)
self.assertTrue(self.HexBlock.hasFlags(Flags.INTERCOOLANT))

def test_getPinCoords(self):
Expand Down

0 comments on commit fed2083

Please sign in to comment.