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

Use clearer input syntax for hexagonal lattice pitch #1654

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
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[-8, 0], "6")

# Cartesian full, odd
Expand Down
Loading