Skip to content

Commit

Permalink
Improving testing and crumbs for blueprints (#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Dec 12, 2023
1 parent 38a3f38 commit 1bc3b6f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
12 changes: 5 additions & 7 deletions armi/reactor/blueprints/gridBlueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class GridBlueprint(yamlize.Object):
The grids get origins either from a parent block (for pin lattices)
or from a System (for Cores, SFPs, and other components).
.. impl:: Define a lattice map in reactor core.
:id: I_ARMI_BP_GRID
:implements: R_ARMI_BP_GRID
Attributes
----------
name : str
Expand All @@ -163,7 +167,6 @@ class GridBlueprint(yamlize.Object):
gridContents : dict
A {(i,j): str} dictionary mapping spatialGrid indices
in 2-D to string specifiers of what's supposed to be in the grid.
"""

name = yamlize.Attribute(key="name", type=str)
Expand Down Expand Up @@ -246,12 +249,7 @@ def readFromLatticeMap(self, value):
self._readFromLatticeMap = value

def construct(self):
"""Build a Grid from a grid definition.
.. impl:: Define a lattice map in reactor core.
:id: I_ARMI_BP_GRID
:implements: R_ARMI_BP_GRID
"""
"""Build a Grid from a grid definition."""
self._readGridContents()
grid = self._constructSpatialGrid()
return grid
Expand Down
60 changes: 60 additions & 0 deletions armi/reactor/blueprints/tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Tests the blueprints (loading input) file."""
import io
import os
import pathlib
import unittest
Expand All @@ -30,6 +31,7 @@
from armi.tests import TEST_ROOT
from armi.utils import directoryChangers
from armi.utils import textProcessors
from armi.reactor.blueprints.gridBlueprint import saveToStream


class TestBlueprints(unittest.TestCase):
Expand Down Expand Up @@ -64,6 +66,64 @@ def setUpClass(cls):
def tearDownClass(cls):
cls.directoryChanger.close()

@staticmethod
def __stubify(latticeMap):
"""Little helper method to allow lattie maps to be compared free of whitespace."""
return latticeMap.replace(" ", "").replace("-", "").replace("\n", "")

def test_roundTripCompleteBP(self):
"""Test the round-tip of reading and writing blueprint files.
.. test:: Validates the round trip of reading and writing blueprints.
:id: T_ARMI_BP_TO_DB1
:tests: R_ARMI_BP_TO_DB
"""
# the correct lattice map
latticeMap = """- - SH
- SH SH
- SH OC SH
SH OC OC SH
OC IC OC SH
OC IC IC OC SH
IC IC IC OC SH
IC IC PC OC SH
IC PC IC IC OC SH
LA IC IC IC OC
IC IC IC IC SH
IC LB IC IC OC
IC IC PC IC SH
LA IC IC OC
IC IC IC IC SH
IC IC IC OC
IC IC IC PC SH"""
latticeMap = self.__stubify(latticeMap)

# validate some core elements from the blueprints
self.assertEqual(self.blueprints.gridDesigns["core"].symmetry, "third periodic")
map0 = self.__stubify(self.blueprints.gridDesigns["core"].latticeMap)
self.assertEqual(map0, latticeMap)

# save the blueprint to a stream
stream = io.StringIO()
stream.seek(0)
self.blueprints.dump(self.blueprints)
saveToStream(stream, self.blueprints, True, True)
stream.seek(0)

with directoryChangers.TemporaryDirectoryChanger():
# save the stream to a file
filePath = "test_roundTripCompleteBP.yaml"
with open(filePath, "w") as fout:
fout.write(stream.read())

# load the blueprint from that file again
bp = blueprints.Blueprints.load(open(filePath, "r").read())

# re-validate some core elements from the blueprints
self.assertEqual(bp.gridDesigns["core"].symmetry, "third periodic")
map1 = self.__stubify(bp.gridDesigns["core"].latticeMap)
self.assertEqual(map1, latticeMap)

def test_nuclides(self):
"""Tests the available sets of nuclides work as expected."""
actives = set(self.blueprints.activeNuclides)
Expand Down
8 changes: 4 additions & 4 deletions armi/reactor/blueprints/tests/test_gridBlueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"""


class TestRoundTrip(unittest.TestCase):
class TestGridBPRoundTrip(unittest.TestCase):
def setUp(self):
self.grids = Grids.load(SMALL_HEX)

Expand All @@ -316,8 +316,8 @@ def test_roundTrip(self):
"""
Test saving blueprint data to a stream.
.. test:: Blueprints settings can be written to disk.
:id: T_ARMI_BP_TO_DB
.. test:: Grid blueprints can be written to disk.
:id: T_ARMI_BP_TO_DB0
:tests: R_ARMI_BP_TO_DB
"""
stream = io.StringIO()
Expand All @@ -326,7 +326,7 @@ def test_roundTrip(self):
gridBp = Grids.load(stream)
self.assertIn("third", gridBp["core"].symmetry)

def test_tiny_map(self):
def test_tinyMap(self):
"""
Test that a lattice map can be defined, written, and read in from blueprint file.
Expand Down

0 comments on commit 1bc3b6f

Please sign in to comment.