Skip to content

Commit

Permalink
Force snapshots to use database blueprints (#872)
Browse files Browse the repository at this point in the history
* Subsequent DB loads no longer cause the assembly count to increase (due to blueprints)
  • Loading branch information
albeanth committed Sep 14, 2022
1 parent 46ee8dd commit 1a24d7a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
13 changes: 6 additions & 7 deletions armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ def loadState(
timeNode,
statePointName=timeStepName,
cs=self.cs,
bp=self.r.blueprints,
allowMissing=True,
updateGlobalAssemNum=updateGlobalAssemNum,
)
Expand Down Expand Up @@ -1087,11 +1086,11 @@ def load(
):
"""Load a new reactor from (cycle, node).
Case settings, blueprints, and geom can be provided by the client, or read from
the database itself. Providing these from the client could be useful when
performing snapshot runs or the like, where it is expected to use results from a
run using different settings, then continue with new settings. Even in this
case, the blueprints and geom should probably be the same as the original run.
Case settings and blueprints can be provided by the client, or read from the database itself.
Providing these from the client could be useful when performing snapshot runs
or where it is expected to use results from a run using different settings and
continue with new settings (or if blueprints are not on the database).
Geom is read from the database itself.
Parameters
----------
Expand All @@ -1101,7 +1100,7 @@ def load(
time node
cs : armi.settings.Settings (optional)
if not provided one is read from the database
bp : armi.reactor.Blueprints (Optional)
bp : armi.reactor.Blueprints (optional)
if not provided one is read from the database
statePointName : str
Optional arbitrary statepoint name (e.g., "special" for "c00n00-special/")
Expand Down
31 changes: 21 additions & 10 deletions armi/bookkeeping/db/tests/test_database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setUp(self):

self.dbi = database3.DatabaseInterface(self.r, self.o.cs)
self.dbi.initDB(fName=self._testMethodName + ".h5")
self.db: db.Database3 = self.dbi.database
self.db: database3.Database3 = self.dbi.database
self.stateRetainer = self.r.retainState().__enter__()

# used to test location-based history. see details below
Expand Down Expand Up @@ -332,23 +332,34 @@ def test_load_updateGlobalAssemNum(self):
from armi.reactor import assemblies
from armi.reactor.assemblies import resetAssemNumCounter

self.makeShuffleHistory()
self.makeHistory()

resetAssemNumCounter()
self.assertEqual(assemblies._assemNum, 0)

# there will 77 assemblies added to the newly created core
self.db.load(0, 0, allowMissing=True, updateGlobalAssemNum=False)
self.assertEqual(assemblies._assemNum, 85)
r = self.db.load(0, 0, allowMissing=True, updateGlobalAssemNum=False)
# len(r.core.sfp) is zero but these nums are still reserved
numSFPBlueprints = 4
expectedNum = len(r.core) + numSFPBlueprints
self.assertEqual(assemblies._assemNum, expectedNum)

# now do the same call again and show that the global _assemNum just keeps going up
# now do the same call again and show that the global _assemNum keeps going up.
# in db.load, rector objects are built in layout._initComps() so the global assem num
# will continue to grow (in this case, double).
self.db.load(0, 0, allowMissing=True, updateGlobalAssemNum=False)
self.assertEqual(assemblies._assemNum, 85 * 2)
self.assertEqual(assemblies._assemNum, expectedNum * 2)

# now load but set updateGlobalAssemNum=True and show that the global assem num
# is updated and equal to self.r.p.maxAssemNum + 1 which is equal to the number of
# assemblies in blueprints/core.
r = self.db.load(0, 0, allowMissing=True, updateGlobalAssemNum=True)
expected = len(self.r.core) + len(self.r.blueprints.assemblies.values())
self.assertEqual(assemblies._assemNum, expected)

# now load but also updateGlobalAssemNum and show that it updates to the value
# stored in self.r.p.maxAssemNum plus 1
# repeat the test above to show that subsequent db loads (with updateGlobalAssemNum=True)
# do not continue to increase the global assem num.
self.db.load(0, 0, allowMissing=True, updateGlobalAssemNum=True)
self.assertEqual(assemblies._assemNum, self.r.core.p.maxAssemNum + 1)
self.assertEqual(assemblies._assemNum, expected)

def test_history(self):
self.makeShuffleHistory()
Expand Down
2 changes: 1 addition & 1 deletion armi/bookkeeping/mainInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def interactEveryNode(self, cycle, node):
pass
else:
with Database3(self.cs["reloadDBName"], "r") as db:
r = db.load(cycle, node, self.cs, self.r.blueprints)
r = db.load(cycle, node, self.cs)

self.o.reattach(r, self.cs)

Expand Down
2 changes: 1 addition & 1 deletion armi/bookkeeping/tests/test_databaseInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_growToFullCoreFromFactoryWithCS(self):

def test_readWritten(self):
with Database3(self.dbName, "r") as db:
r2 = db.load(0, 0, self.cs, self.bp)
r2 = db.load(0, 0, self.cs)

for a1, a2 in zip(self.r.core, r2.core):
# assemblies assign a name based on assemNum at initialization
Expand Down
13 changes: 13 additions & 0 deletions armi/reactor/blueprints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,23 @@ def _prepConstruction(self, cs):
self._assembliesBySpecifier.clear()
self.assemblies.clear()

# retrieve current count of assemblies to restore after
# creating blueprints assemblies. This is particularly useful for
# doing snapshot based runs and multiple database loads, and ensures
# that each database load/snapshot to not cumulative increase the assembly
# count during creation of blueprints assemblies. During initial
# constructions the first N numbers are reserved for blueprints, so this
# ensures consistency.
currentCount = assemblies.getAssemNum()
# reset the assembly counter so that blueprints assemblies are always
# numbered 0 to len(self.assemDesigns)
assemblies.resetAssemNumCounter()
for aDesign in self.assemDesigns:
a = aDesign.construct(cs, self)
self._assembliesBySpecifier[aDesign.specifier] = a
self.assemblies[aDesign.name] = a
if currentCount != 0:
assemblies.setAssemNumCounter(currentCount)

self._checkAssemblyAreaConsistency(cs)

Expand Down
1 change: 1 addition & 0 deletions doc/release/0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ What's new in ARMI
#. Updated NHFLUX reader to store VARIANT data that was being discarded. Reading/writing VARIANT NHFLUX files now show binary equivalance.
#. The ``newReports`` were moved into their final location in ``armi/bookkeeping/report/``.
#. Refactored the ``UniformMeshGeometryConverter`` again to auto-detect if block-level parameters are scalar or array values and implemented a feature to optionally disable number density mapping.
#. Remove ability for users to use separate blueprints in snapshot runs. They are only determined from database. (`PR#872 https://github.com/terrapower/armi/pull/872`)
#. TBD

Bug fixes
Expand Down

0 comments on commit 1a24d7a

Please sign in to comment.