Skip to content

Commit

Permalink
Cleaning out the overly-specific methods in ArmiObject (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Apr 8, 2024
1 parent 45ef386 commit 6b34896
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,6 @@ def getMassFracDenom(self):
massFracDenom += self[nuc] * nuc.weight
return massFracDenom

def printDensities(self, lfpDens):
"""
Print number densities of nuclides within the lumped fission product.
Parameters
----------
lfpDens : float
Number density (atom/b-cm) of the lumped fission product
Notes
-----
This multiplies the provided number density for the lumped fission
product by the yield of each nuclide.
"""
for n in sorted(self.keys()):
runLog.info("{0:6s} {1:.7E}".format(n.name, lfpDens * self[n]))


class LumpedFissionProductCollection(dict):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ def test_gaseousYieldFraction(self):
# data for these tests.
self.assertEqual(lfp.getGaseousYieldFraction(), 8.9000e-05)

def test_printDensities(self):
_ = nuclideBases.fromName("XE135")
lfp = self.fpd.createSingleLFPFromFile("LFP38")
lfp.printDensities(10.0)

def test_isGas(self):
"""Tests that a nuclide is a gas or not at STP based on its chemical phase."""
nb = nuclideBases.byName["H1"]
Expand Down
4 changes: 4 additions & 0 deletions armi/reactor/assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,10 @@ def rotate(self, rad):
for b in self.getBlocks():
b.rotate(rad)

def isOnWhichSymmetryLine(self):
grid = self.parent.spatialGrid
return grid.overlapsWhichSymmetryLine(self.spatialLocator.getCompleteIndices())


class HexAssembly(Assembly):
"""Placeholder, so users can explicitly define a hex-based Assembly."""
Expand Down
46 changes: 30 additions & 16 deletions armi/reactor/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from armi import nuclideBases
from armi import runLog
from armi.bookkeeping import report
from armi.nucDirectory import elements
from armi.physics.neutronics import GAMMA
from armi.physics.neutronics import NEUTRON
from armi.reactor import blockParameters
Expand Down Expand Up @@ -628,17 +629,6 @@ def setBuLimitInfo(self):
def getMaxArea(self):
raise NotImplementedError

def getMaxVolume(self):
"""
The maximum volume of this object if it were totally full.
Returns
-------
vol : float
volume in cm^3.
"""
return self.getMaxArea() * self.getHeight()

def getArea(self, cold=False):
"""
Return the area of a block for a full core or a 1/3 core model.
Expand Down Expand Up @@ -727,11 +717,6 @@ def getSymmetryFactor(self):
"""
return 1.0

def isOnWhichSymmetryLine(self):
"""Block symmetry lines are determined by the reactor, not the parent."""
grid = self.core.spatialGrid
return grid.overlapsWhichSymmetryLine(self.spatialLocator.getCompleteIndices())

def adjustDensity(self, frac, adjustList, returnMass=False):
"""
adjusts the total density of each nuclide in adjustList by frac.
Expand Down Expand Up @@ -1648,6 +1633,35 @@ def getPinCoordinates(self):
coords.append(clad.spatialLocator.getLocalCoordinates())
return coords

def getBoronMassEnrich(self):
"""Return B-10 mass fraction."""
b10 = self.getMass("B10")
b11 = self.getMass("B11")
total = b11 + b10
if total == 0.0:
return 0.0
return b10 / total

def getPuMoles(self):
"""Returns total number of moles of Pu isotopes."""
nucNames = [nuc.name for nuc in elements.byZ[94].nuclides]
puN = sum(self.getNuclideNumberDensities(nucNames))

return (
puN
/ units.MOLES_PER_CC_TO_ATOMS_PER_BARN_CM
* self.getVolume()
* self.getSymmetryFactor()
)

def getUraniumMassEnrich(self):
"""Returns U-235 mass fraction assuming U-235 and U-238 only."""
u5 = self.getMass("U235")
if u5 < 1e-10:
return 0.0
u8 = self.getMass("U238")
return u5 / (u8 + u5)


class HexBlock(Block):
"""
Expand Down
17 changes: 14 additions & 3 deletions armi/reactor/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ def computeVolume(self):
"""
return self._deriveVolumeAndArea()

def getMaxVolume(self):
"""
The maximum volume of the parent Block.
Returns
-------
vol : float
volume in cm^3.
"""
return self.parent.getMaxArea() * self.parent.getHeight()

def _deriveVolumeAndArea(self):
"""
Derive the volume and area of a ``DerivedShape``.
Expand Down Expand Up @@ -383,7 +394,7 @@ def _deriveVolumeAndArea(self):
except: # noqa: bare-except
siblingArea = None

remainingVolume = self.parent.getMaxVolume() - siblingVolume
remainingVolume = self.getMaxVolume() - siblingVolume
if siblingArea:
remainingArea = self.parent.getMaxArea() - siblingArea

Expand All @@ -393,8 +404,8 @@ def _deriveVolumeAndArea(self):
f"The component areas in {self.parent} exceed the maximum "
"allowable volume based on the geometry. Check that the "
"geometry is defined correctly.\n"
f"Maximum allowable volume: {self.parent.getMaxVolume()} cm^3\n"
f"Volume of all non-derived shape components: {siblingVolume} cm^3\n"
f"Maximum allowable volume: {self.getMaxVolume()} "
f"cm^3\nVolume of all non-derived shape components: {siblingVolume} cm^3\n"
)
runLog.error(msg)
raise ValueError(
Expand Down
98 changes: 0 additions & 98 deletions armi/reactor/composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,17 +898,6 @@ def getMaxArea(self):
"""
raise NotImplementedError()

def getMaxVolume(self):
"""
The maximum volume of this object if it were totally full.
Returns
-------
vol : float
volume in cm^3.
"""
raise NotImplementedError()

def getMass(self, nuclideNames=None):
"""
Determine the mass in grams of nuclide(s) and/or elements in this object.
Expand Down Expand Up @@ -1765,23 +1754,6 @@ def getFissileMassEnrich(self):
else:
return 0.0

def getBoronMassEnrich(self):
"""Return B-10 mass fraction."""
b10 = self.getMass("B10")
b11 = self.getMass("B11")
total = b11 + b10
if total == 0.0:
return 0.0
return b10 / total

def getUraniumMassEnrich(self):
"""Returns U-235 mass fraction assuming U-235 and U-238 only."""
u5 = self.getMass("U235")
if u5 < 1e-10:
return 0.0
u8 = self.getMass("U238")
return u5 / (u8 + u5)

def getUraniumNumEnrich(self):
"""Returns U-235 number fraction."""
u8 = self.getNumberDensity("U238")
Expand All @@ -1790,20 +1762,6 @@ def getUraniumNumEnrich(self):
u5 = self.getNumberDensity("U235")
return u5 / (u8 + u5)

def getPuN(self):
"""Returns total number density of Pu isotopes."""
nucNames = [nuc.name for nuc in elements.byZ[94].nuclides]
return sum(self.getNuclideNumberDensities(nucNames))

def getPuMoles(self):
"""Returns total number of moles of Pu isotopes."""
return (
self.getPuN()
/ units.MOLES_PER_CC_TO_ATOMS_PER_BARN_CM
* self.getVolume()
* self.getSymmetryFactor()
)

def calcTotalParam(
self,
param,
Expand Down Expand Up @@ -2145,48 +2103,6 @@ def getHMDens(self):
hmDens = sum(self.getNuclideNumberDensities(hmNuclides))
return hmDens

def getPuMass(self):
"""Get the mass of Pu in this object in grams."""
nucs = []
for nucName in [nuc.name for nuc in elements.byZ[94].nuclides]:
nucs.append(nucName)
pu = self.getMass(nucs)
return pu

def getPuFrac(self):
"""
Compute the Pu/HM mass fraction in this object.
Returns
-------
puFrac : float
The pu mass fraction in heavy metal in this assembly
"""
hm = self.getHMMass()
pu = self.getPuMass()
if hm == 0.0:
return 0.0
else:
return pu / hm

def getZrFrac(self):
"""Return the total zr/(hm+zr) fraction in this assembly."""
hm = self.getHMMass()
zrNucs = [nuc.name for nuc in elements.bySymbol["ZR"].nuclides]
zr = self.getMass(zrNucs)
if hm + zr > 0:
return zr / (hm + zr)
else:
return 0.0

def getMaxUraniumMassEnrich(self):
maxV = 0
for child in self:
v = child.getUraniumMassEnrich()
if v > maxV:
maxV = v
return maxV

def getFPMass(self):
"""Returns mass of fission products in this block in grams."""
nucs = []
Expand Down Expand Up @@ -2597,16 +2513,6 @@ def setComponentDimensionsReport(self):

return reportGroups

def printDensities(self, expandFissionProducts=False):
"""Get lines that have the number densities of a object."""
numberDensities = self.getNumberDensities(
expandFissionProducts=expandFissionProducts
)
lines = []
for nucName, nucDens in numberDensities.items():
lines.append("{0:6s} {1:.7E}".format(nucName, nucDens))
return lines

def expandAllElementalsToIsotopics(self):
reactorNucs = self.getNuclides()
for elemental in nuclideBases.where(
Expand Down Expand Up @@ -3310,10 +3216,6 @@ def printContents(self, includeNuclides=True):
for c in self.getChildren():
c.printContents(includeNuclides=includeNuclides)

def isOnWhichSymmetryLine(self):
grid = self.parent.spatialGrid
return grid.overlapsWhichSymmetryLine(self.spatialLocator.getCompleteIndices())

def _genChildByLocationLookupTable(self):
"""Update the childByLocation lookup table."""
runLog.extra("Generating location-to-child lookup table.")
Expand Down
25 changes: 4 additions & 21 deletions armi/reactor/tests/test_assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ def setUp(self):

self.assembly.calculateZCoords()

def test_isOnWhichSymmetryLine(self):
line = self.assembly.isOnWhichSymmetryLine()
self.assertEqual(line, 2)

def test_notesParameter(self):
self.assertEqual(self.assembly.p.notes, "")

Expand Down Expand Up @@ -488,18 +492,6 @@ def test_getFissileMass(self):
ref = sum(bi.getMass(["U235", "PU239"]) for bi in self.assembly)
self.assertAlmostEqual(cur, ref)

def test_getPuFrac(self):
puAssem = self.assembly.getPuFrac()
fuelBlock = self.assembly[1]
puBlock = fuelBlock.getPuFrac()
self.assertAlmostEqual(puAssem, puBlock)

#
fuelComp = fuelBlock.getComponent(Flags.FUEL)
fuelComp.setNumberDensity("PU239", 0.012)
self.assertGreater(self.assembly.getPuFrac(), puAssem)
self.assertGreater(fuelBlock.getPuFrac(), puAssem)

def test_getMass(self):
mass0 = self.assembly.getMass("U235")
mass1 = sum(bi.getMass("U235") for bi in self.assembly)
Expand All @@ -514,15 +506,6 @@ def test_getMass(self):
fuelBlock.setMass("U238", 0.0)
self.assertAlmostEqual(blockU35Mass * 2, fuelBlock.getMass("U235"))

def test_getZrFrac(self):
self.assertAlmostEqual(self.assembly.getZrFrac(), 0.1)

def test_getMaxUraniumMassEnrich(self):
baseEnrich = self.assembly[0].getUraniumMassEnrich()
self.assertAlmostEqual(self.assembly.getMaxUraniumMassEnrich(), baseEnrich)
self.assembly[2].setNumberDensity("U235", 2e-1)
self.assertGreater(self.assembly.getMaxUraniumMassEnrich(), baseEnrich)

def test_getAge(self):
res = 5.0
for b in self.assembly:
Expand Down

0 comments on commit 6b34896

Please sign in to comment.