Skip to content

Commit

Permalink
Merge e3b07e7 into 46ee8dd
Browse files Browse the repository at this point in the history
  • Loading branch information
albeanth authored Sep 14, 2022
2 parents 46ee8dd + e3b07e7 commit 9382709
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
15 changes: 5 additions & 10 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 @@ -1080,18 +1079,16 @@ def load(
cycle,
node,
cs=None,
bp=None,
statePointName=None,
allowMissing=False,
updateGlobalAssemNum=True,
):
"""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 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. Blueprints and geom are read from the database itself.
Parameters
----------
Expand All @@ -1101,8 +1098,6 @@ def load(
time node
cs : armi.settings.Settings (optional)
if not provided one is read from the database
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/")
allowMissing : bool
Expand All @@ -1122,7 +1117,7 @@ def load(
cs = cs or self.loadCS()
# apply to avoid defaults in getMasterCs calls
settings.setMasterCs(cs)
bp = bp or self.loadBlueprints()
bp = self.loadBlueprints()

h5group = self.h5db[getH5GroupName(cycle, node, statePointName)]

Expand Down
23 changes: 15 additions & 8 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,21 +332,28 @@ 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
# there will 77 assemblies (73 core and 4 blueprints sfp grid) added to the newly created core
self.db.load(0, 0, allowMissing=True, updateGlobalAssemNum=False)
self.assertEqual(assemblies._assemNum, 85)
self.assertEqual(assemblies._assemNum, 77)

# 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, 77 * 2)

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

# 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)

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
10 changes: 10 additions & 0 deletions armi/reactor/blueprints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,20 @@ 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 with database loads where the
# assembly counter is likely not equal to 0.
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

0 comments on commit 9382709

Please sign in to comment.