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

Fixing assembly number issue in DB Load #615

Merged
merged 16 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion armi/bookkeeping/db/database3.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def prepRestartRun(self, dbCycle, dbNode):
self._db.mergeHistory(inputDB, self.cs["startCycle"], self.cs["startNode"])
self.loadState(dbCycle, dbNode)

# TODO: The use of "yield" here is suspect.
def _getLoadDB(self, fileName):
"""
Return the database to load from in order of preference.
Expand Down Expand Up @@ -1095,7 +1096,12 @@ def load(
parameterCollections.GLOBAL_SERIAL_NUM, layout.serialNum.max()
)
root = comps[0][0]
return root # usually reactor object

# ensure the max assembly number is correct
updateGlobalAssemblyNum(root)

# usually a reactor object
return root

@staticmethod
def _assignBlueprintsParams(blueprints, groupedComps):
Expand Down
54 changes: 54 additions & 0 deletions armi/bookkeeping/tests/test_databaseInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,60 @@ def tearDownClass(cls):
del cls.r
cls.r = None

def test_growToFullCore(self):
with Database3(self.dbName, "r") as db:
r = db.load(0, 0, allowMissing=True)

r.core.growToFullCore(None)

self.assertEqual(r.core.numRings, 9)
self.assertEqual(r.p.cycle, 0)
self.assertEqual(len(r.core.assembliesByName), 217)
self.assertEqual(len(r.core.circularRingList), 0)
self.assertEqual(len(r.core.blocksByName), 1085)

def test_growToFullCoreWithCS(self):
with Database3(self.dbName, "r") as db:
r = db.load(0, 0, allowMissing=True)

r.core.growToFullCore(self.cs)

self.assertEqual(r.core.numRings, 9)
self.assertEqual(r.p.cycle, 0)
self.assertEqual(len(r.core.assembliesByName), 217)
self.assertEqual(len(r.core.circularRingList), 0)
self.assertEqual(len(r.core.blocksByName), 1085)

def test_growToFullCoreFromFactory(self):
from armi.bookkeeping.db import databaseFactory

db = databaseFactory(self.dbName, "r")
with db:
r = db.load(0, 0, allowMissing=True)

r.core.growToFullCore(None)

self.assertEqual(r.core.numRings, 9)
self.assertEqual(r.p.cycle, 0)
self.assertEqual(len(r.core.assembliesByName), 217)
self.assertEqual(len(r.core.circularRingList), 0)
self.assertEqual(len(r.core.blocksByName), 1085)

def test_growToFullCoreFromFactoryWithCS(self):
from armi.bookkeeping.db import databaseFactory

db = databaseFactory(self.dbName, "r")
with db:
r = db.load(0, 0, allowMissing=True)

r.core.growToFullCore(self.cs)

self.assertEqual(r.core.numRings, 9)
self.assertEqual(r.p.cycle, 0)
self.assertEqual(len(r.core.assembliesByName), 217)
self.assertEqual(len(r.core.circularRingList), 0)
self.assertEqual(len(r.core.blocksByName), 1085)

def test_readWritten(self):
with Database3(self.dbName, "r") as db:
r2 = db.load(0, 0, self.cs, self.bp)
Expand Down
1 change: 0 additions & 1 deletion armi/reactor/assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def makeUnique(self):
self.p.assemNum = incrementAssemNum()
self.name = self.makeNameFromAssemNum(self.p.assemNum)
for bi, b in enumerate(self):
b.makeUnique()
b.setName(b.makeName(self.p.assemNum, bi))

@staticmethod
Expand Down
16 changes: 0 additions & 16 deletions armi/reactor/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def __init__(self, name, height=1.0, location=None):
`getVolume` assumes unit height.
"""
composites.Composite.__init__(self, name)
self.makeUnique()
self.p.height = height

if location:
Expand Down Expand Up @@ -219,21 +218,6 @@ def makeName(self, assemNum, axialIndex):
self.p.assemNum = assemNum
return "B{0:04d}-{1:03d}".format(assemNum, axialIndex)

def makeUnique(self):
"""
Assign a unique id (integer value) for each block.

This should be called whenever creating a block that is intended to be treated
as a unique object. For example, if you were to broadcast or pickle a block it
should have the same ID across all nodes. Likewise, if you deepcopy a block for
a temporary purpose to it should have the same ID. However, ARMI's assembly
construction also uses deepcopy, and in order to keep that functionality, this
method needs to be called after creating a fresh assembly (from deepcopy).
"""

self.p.id = self.__class__.uniqID
self.__class__.uniqID += 1

def getSmearDensity(self, cold=True):
"""
Compute the smear density of pins in this block.
Expand Down
38 changes: 0 additions & 38 deletions armi/reactor/reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,44 +945,6 @@ def buildCircularRingDictionary(self, ringPitch=1.0):

return circularRingDict

def getPowerProductionMassFromFissionProducts(self):
"""
Determines the power produced by Pu isotopes and Uranium isotopes by examining
the fission products in the block

The percentage of energy released adjusted mass produced by each LFP can be used to
determine the relative power production of each parent isotope.

Returns
-------
resultsEnergyCorrected : list of tuples
Contains the nuclide name, energy released adjusted mass
"""
# get the energy in Joules from the ISOTXS
energyDict = {}
nuclides = ["U235", "U238", "PU239", "PU240", "PU241"]
fissionProducts = ["LFP35", "LFP38", "LFP39", "LFP40", "LFP41"]

# initialize the energy in each nuclide
totEnergy = 0.0
for nuc in nuclides:
n = self.lib.getNuclide(nuc)
energyDict[nuc] = n.isotxsMetadata["efiss"]
totEnergy += n.isotxsMetadata["efiss"]

fissPower = {}
for b in self.getBlocks(Flags.FUEL):
for nuc, lfp in zip(nuclides, fissionProducts):
energy = fissPower.get(nuc, 0.0)
energy += b.getMass(lfp) * energyDict[nuc]
fissPower[nuc] = energy

resultsEnergyCorrected = []
# scale the energy mass by energy to get the corrected energy mass of each isotope
for nuc in nuclides:
resultsEnergyCorrected.append(fissPower[nuc] / totEnergy)
return zip(nuclides, resultsEnergyCorrected)

def _getAssembliesByName(self):
"""
If the assembly name-to-assembly object map is deleted or out of date, then this will
Expand Down
10 changes: 10 additions & 0 deletions armi/reactor/tests/test_reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,16 @@ def test_createAssemblyOfType(self):
)
self.assertAlmostEqual(aNew3.getMass(), bol.getMass())

def test_getAvgTemp(self):
t0 = self.r.core.getAvgTemp([Flags.CLAD, Flags.WIRE, Flags.DUCT])
self.assertAlmostEqual(t0, 459.267, delta=0.01)

t1 = self.r.core.getAvgTemp([Flags.CLAD, Flags.FUEL])
self.assertAlmostEqual(t1, 545.043, delta=0.01)

t2 = self.r.core.getAvgTemp([Flags.CLAD, Flags.WIRE, Flags.DUCT, Flags.FUEL])
self.assertAlmostEqual(t2, 521.95269, delta=0.01)


class CartesianReactorTests(ReactorTests):
def setUp(self):
Expand Down
11 changes: 11 additions & 0 deletions doc/developer/standards_and_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Also, do not **ever** code the following things into the code: user names, passw
environmental variables where possible and user-configurable settings elsewhere. You can also use the ``armi.ROOT``
variable (for the active code directory) or ``armi.RES``, and some other useful root-level variables.

Avoid the global keyword
========================
At all costs, avoid use of the ``global`` keyword in your code. Using this keyword can, and usually does, create
extremely fragile code that is nigh-impossible to use a debugger on. Especially as part of object-oriented programming,
this is extremely lazy design. A careful reader might notice that there are several files in ARMI that are currently
using the ``global`` keyword. These are all schedule for a refactor to remove the use of ``global``. But, for now,
changing the code would cause more annoyance for the ARMI ecosystem userbase than fixing it would. Still, all of those
instance in ARMI will be fixed soon.

No new uses of ``global`` will make it through the ARMI pull request process.

Naming conventions
==================

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 @@ -21,6 +21,7 @@ Bug fixes
#. Fixed issues finding ``ISOXX`` files cross-platform.
#. Fixed issue with docs not correctly loading their Git submodule in TOX.
#. Fixed issue with ``_swapFluxParams`` failing for assemblies with different blocks (`#566 <https://github.com/terrapower/armi/issues/566>`_)
#. Multiple bug fixes in ``growToFullCore``.
#. TBD


Expand Down