Skip to content

Commit

Permalink
Cleaning up comments and adding some tests (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed May 5, 2022
1 parent 945a381 commit 6ac6c66
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 469 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ def generateLatticePhysicsInputs(
See Also
--------
:py:meth:`terrapower.physics.neutronics.mc2.mc2Writers.Mc2V2Writer.write`
:py:meth:`armi.physics.neutronics.latticePhysics.serpentWriters.SerpentWriter.write`
terrapower.physics.neutronics.mc2.mc2Writers.Mc2V2Writer.write
"""
returnedFromWriters = []
baseList = set(baseList or [])
Expand Down
38 changes: 20 additions & 18 deletions armi/reactor/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,10 @@ def setHeight(self, modifiedHeight, conserveMass=False, adjustList=None):
See Also
--------
reactors.Core.updateAxialMesh : May need to be called after this.
assemblies.Assembly.calculateZCoords : Recalculates z-coords, automatically called by this.
armi.reactor.reactors.Core.updateAxialMesh
May need to be called after this.
armi.reactor.assemblies.Assembly.calculateZCoords
Recalculates z-coords, automatically called by this.
"""
originalHeight = self.getHeight() # get before modifying
if modifiedHeight < 0.0:
Expand Down Expand Up @@ -514,11 +516,12 @@ def getFlowAreaPerPin(self):
Return the flowing coolant area in cm^2.
NumPins looks for max number of fuel, clad, control, etc.
See Also
--------
getNumPins : figures out numPins.
armi.reactor.blocks.Block.getNumPins
figures out numPins
"""

numPins = self.getNumPins()
try:
return self.getComponent(Flags.COOLANT, exact=True).getArea() / numPins
Expand Down Expand Up @@ -621,8 +624,8 @@ def getArea(self, cold=False):
See Also
--------
getMaxArea : return the full area of the physical assembly disregarding model symmetry
armi.reactor.blocks.Block.getMaxArea
return the full area of the physical assembly disregarding model symmetry
"""
# this caching requires that you clear the cache every time you adjust anything
# including temperature and dimensions.
Expand Down Expand Up @@ -670,8 +673,7 @@ def getSymmetryFactor(self):
See Also
--------
armi.reactor.reactors.Core.addEdgeAssemblies
terrapower.physics.neutronics.dif3d.dif3dInterface.Dif3dReader.scaleParamsRelatedToSymmetry
armi.reactor.converters.geometryConverter.EdgeAssemblyChanger.scaleParamsRelatedToSymmetry
"""
return 1.0

Expand Down Expand Up @@ -1400,7 +1402,6 @@ def breakFuelComponentsIntoIndividuals(self):
The fuel will become fuel001 through fuel169 if there are 169 pins.
"""

fuels = self.getChildrenWithFlags(Flags.FUEL)
if len(fuels) != 1:
runLog.error(
Expand All @@ -1410,6 +1411,7 @@ def breakFuelComponentsIntoIndividuals(self):
"Cannot break {0} into multiple fuel components b/c there is not a single fuel"
" component.".format(self)
)

fuel = fuels[0]
fuelFlags = fuel.p.flags
nPins = self.getNumPins()
Expand Down Expand Up @@ -1532,7 +1534,8 @@ def rotate(self, deg):
Parameters
----------
deg - float
number specifying the angle of counter clockwise rotation"""
number specifying the angle of counter clockwise rotation
"""
raise NotImplementedError


Expand Down Expand Up @@ -1645,10 +1648,9 @@ def rotate(self, deg):
See Also
--------
rotatePins : rotates the pins only and not the duct
armi.reactor.blocks.HexBlock.rotatePins
Rotates the pins only and not the duct.
"""

rotNum = round((deg % (2 * math.pi)) / math.radians(60))
self.rotatePins(rotNum)
params = self.p.paramDefs.atLocation(ParamLocation.CORNERS).names
Expand Down Expand Up @@ -1723,8 +1725,8 @@ def rotatePins(self, rotNum, justCompute=False):
See Also
--------
rotate : rotates the entire block (pins and spatial quantities). Generally rotatePins should be
called via the rotate function.
armi.reactor.blocks.HexBlock.rotate
Rotates the entire block (pins, ducts, and spatial quantities).
Examples
--------
Expand All @@ -1743,9 +1745,8 @@ def rotatePins(self, rotNum, justCompute=False):
rotNum = int((self.getRotationNum() + rotNum) % 6)

# non-trivial rotation requested
for pinNum in range(
2, numPins + 1
): # start at 2 because pin 1 never changes (it's in the center!)
# start at 2 because pin 1 never changes (it's in the center!)
for pinNum in range(2, numPins + 1):
if rotNum == 0:
# rotation to reference orientation. Pin locations are pin IDs.
pass
Expand All @@ -1767,6 +1768,7 @@ def rotatePins(self, rotNum, justCompute=False):

if not justCompute:
self.setRotationNum(rotNum)

return rotateIndexLookup

def verifyBlockDims(self):
Expand Down
8 changes: 4 additions & 4 deletions armi/reactor/converters/axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ def axiallyExpandAssembly(self, thermal: bool = False):
blockHeight = b.p.heightBOL
else:
blockHeight = b.p.height
## set bottom of block equal to top of block below it
# set bottom of block equal to top of block below it
# if ib == 0, leave block bottom = 0.0
if ib > 0:
b.p.zbottom = self.linked.linkedBlocks[b][0].p.ztop
## if not in the dummy block, get expansion factor, do alignment, and modify block
# if not in the dummy block, get expansion factor, do alignment, and modify block
if ib < (numOfBlocks - 1):
for c in b:
growFrac = self.expansionData.getExpansionFactor(c)
Expand All @@ -186,14 +186,14 @@ def axiallyExpandAssembly(self, thermal: bool = False):
if self.expansionData.isTargetComponent(c):
b.p.ztop = c.ztop

## see also b.setHeight()
# see also b.setHeight()
# - the above not chosen due to call to calculateZCoords
oldComponentVolumes = [c.getVolume() for c in b]
oldHeight = b.getHeight()
b.p.height = b.p.ztop - b.p.zbottom
_checkBlockHeight(b)
_conserveComponentMass(b, oldHeight, oldComponentVolumes)
## set block mid point and redo mesh
# set block mid point and redo mesh
# - functionality based on assembly.calculateZCoords()
b.p.z = b.p.zbottom + b.p.height / 2.0
mesh.append(b.p.ztop)
Expand Down
58 changes: 29 additions & 29 deletions armi/reactor/converters/tests/test_axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def _getConservationMetrics(self, a):
mass = 0.0
for b in a:
for c in b:
## store mass and density of target component
# store mass and density of target component
if self.obj.expansionData.isTargetComponent(c):
self._storeTargetComponentMassAndDensity(c)
## store steel mass for assembly
# store steel mass for assembly
if c.p.flags in self.Steel_Component_Lst:
mass += c.getMass()

Expand Down Expand Up @@ -143,7 +143,7 @@ def _generateTempField(self, coldTemp, hotInletTemp, uniform):
- temperature grid : physical locations in which
temperature is measured
"""
## Generate temp field
# Generate temp field
self.tempField[0, :] = coldTemp
if not uniform:
for i in range(1, self.tempSteps):
Expand All @@ -163,7 +163,7 @@ class TestAxialExpansionHeight(Base, unittest.TestCase):

def setUp(self):
Base.setUp(self)
self.a = buildTestAssemblyWithFakeMaterial(name="Fake")
self.a = buildTestAssemblyWithFakeMaterial(name="FakeMat")

self.temp = Temperature(
self.a.getTotalHeight(), numTempGridPts=11, tempSteps=10
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_AxialMesh(self):

def _generateComponentWiseExpectedHeight(self):
"""calculate the expected height, external of AssemblyAxialExpansion()"""
assem = buildTestAssemblyWithFakeMaterial(name="Fake")
assem = buildTestAssemblyWithFakeMaterial(name="FakeMat")
aveBlockTemp = zeros((len(assem), self.temp.tempSteps))
self.trueZtop = zeros((len(assem), self.temp.tempSteps))
self.trueHeight = zeros((len(assem), self.temp.tempSteps))
Expand Down Expand Up @@ -301,7 +301,7 @@ class TestConservation(Base, unittest.TestCase):

def setUp(self):
Base.setUp(self)
self.a = buildTestAssemblyWithFakeMaterial(name="Fake")
self.a = buildTestAssemblyWithFakeMaterial(name="FakeMat")

# initialize class variables for conservation checks
self.oldMass = {}
Expand All @@ -327,7 +327,7 @@ def test_ExpansionContractionConservation(self):
- 10 total expansion steps: 5 at +1%, and 5 at -1%
- assertion on if original axial mesh matches the final axial mesh
"""
a = buildTestAssemblyWithFakeMaterial(name="Fake")
a = buildTestAssemblyWithFakeMaterial(name="FakeMat")
obj = AxialExpansionChanger()
oldMesh = a.getAxialMesh()
componentLst = [c for b in a for c in b]
Expand Down Expand Up @@ -389,30 +389,30 @@ def test_NoMovementACLP(self):
assembly = HexAssembly("testAssemblyType")
assembly.spatialGrid = grids.axialUnitGrid(numCells=1)
assembly.spatialGrid.armiObject = assembly
assembly.add(_buildTestBlock("shield", "Fake"))
assembly.add(_buildTestBlock("fuel", "Fake"))
assembly.add(_buildTestBlock("fuel", "Fake"))
assembly.add(_buildTestBlock("plenum", "Fake"))
assembly.add(_buildTestBlock("aclp", "Fake")) # "aclp plenum" also works
assembly.add(_buildTestBlock("plenum", "Fake"))
assembly.add(_buildTestBlock("shield", "FakeMat"))
assembly.add(_buildTestBlock("fuel", "FakeMat"))
assembly.add(_buildTestBlock("fuel", "FakeMat"))
assembly.add(_buildTestBlock("plenum", "FakeMat"))
assembly.add(_buildTestBlock("aclp", "FakeMat")) # "aclp plenum" also works
assembly.add(_buildTestBlock("plenum", "FakeMat"))
assembly.add(_buildDummySodium())
assembly.calculateZCoords()
assembly.reestablishBlockOrder()

## get zCoords for aclp
# get zCoords for aclp
aclp = assembly.getChildrenWithFlags(Flags.ACLP)[0]
aclpZTop = aclp.p.ztop
aclpZBottom = aclp.p.zbottom

## expand fuel
# expand fuel
# get fuel components
cList = [c for b in assembly for c in b if c.hasFlags(Flags.FUEL)]
# 10% growth of fuel components
pList = zeros(len(cList)) + 0.1
chngr = AxialExpansionChanger()
chngr.performPrescribedAxialExpansion(assembly, cList, pList, setFuel=True)

## do assertion
# do assertion
self.assertEqual(
aclpZBottom,
aclp.p.zbottom,
Expand All @@ -430,15 +430,15 @@ class TestExceptions(Base, unittest.TestCase):

def setUp(self):
Base.setUp(self)
self.a = buildTestAssemblyWithFakeMaterial(name="FakeException")
self.a = buildTestAssemblyWithFakeMaterial(name="FakeMatException")
self.obj.setAssembly(self.a)

def test_isTopDummyBlockPresent(self):
# build test assembly without dummy
assembly = HexAssembly("testAssemblyType")
assembly.spatialGrid = grids.axialUnitGrid(numCells=1)
assembly.spatialGrid.armiObject = assembly
assembly.add(_buildTestBlock("shield", "Fake"))
assembly.add(_buildTestBlock("shield", "FakeMat"))
assembly.calculateZCoords()
assembly.reestablishBlockOrder()
# create instance of expansion changer
Expand Down Expand Up @@ -491,8 +491,8 @@ def test_specifyTargetComponentRuntimeErrorFirst(self):
b = HexBlock("test", height=10.0)
fuelDims = {"Tinput": 25.0, "Thot": 25.0, "od": 0.76, "id": 0.00, "mult": 127.0}
cladDims = {"Tinput": 25.0, "Thot": 25.0, "od": 0.80, "id": 0.77, "mult": 127.0}
mainType = Circle("main", "Fake", **fuelDims)
clad = Circle("clad", "Fake", **cladDims)
mainType = Circle("main", "FakeMat", **fuelDims)
clad = Circle("clad", "FakeMat", **cladDims)
b.add(mainType)
b.add(clad)
b.setType("test")
Expand All @@ -509,8 +509,8 @@ def test_specifyTargetComponentRuntimeErrorSecond(self):
b = HexBlock("test", height=10.0)
fuelDims = {"Tinput": 25.0, "Thot": 25.0, "od": 0.76, "id": 0.00, "mult": 127.0}
cladDims = {"Tinput": 25.0, "Thot": 25.0, "od": 0.80, "id": 0.77, "mult": 127.0}
mainType = Circle("test", "Fake", **fuelDims)
clad = Circle("test", "Fake", **cladDims)
mainType = Circle("test", "FakeMat", **fuelDims)
clad = Circle("test", "FakeMat", **cladDims)
b.add(mainType)
b.add(clad)
b.setType("test")
Expand All @@ -532,8 +532,8 @@ def test_isFuelLocked(self):
"id": 0.77,
"mult": 127.0,
}
fuel = Circle("fuel", "Fake", **fuelDims)
fuel2 = Circle("fuel", "Fake", **fuel2Dims)
fuel = Circle("fuel", "FakeMat", **fuelDims)
fuel2 = Circle("fuel", "FakeMat", **fuel2Dims)
b_TwoFuel.add(fuel)
b_TwoFuel.add(fuel2)
b_TwoFuel.setType("test")
Expand All @@ -546,7 +546,7 @@ def test_isFuelLocked(self):
self.assertEqual(the_exception.error_code, 3)

b_NoFuel = HexBlock("fuel", height=10.0)
shield = Circle("shield", "Fake", **fuelDims)
shield = Circle("shield", "FakeMat", **fuelDims)
b_NoFuel.add(shield)
with self.assertRaises(RuntimeError) as cm:
expdata._isFuelLocked(b_NoFuel) # pylint: disable=protected-access
Expand Down Expand Up @@ -633,7 +633,7 @@ def _buildDummySodium():
return b


class Fake(materials.ht9.HT9): # pylint: disable=abstract-method
class FakeMat(materials.ht9.HT9): # pylint: disable=abstract-method
"""Fake material used to verify armi.reactor.converters.axialExpansionChanger
Notes
Expand All @@ -644,7 +644,7 @@ class Fake(materials.ht9.HT9): # pylint: disable=abstract-method
and contraction. See TestConservation.
"""

name = "Fake"
name = "FakeMat"

def __init__(self):
materials.ht9.HT9.__init__(self)
Expand All @@ -655,7 +655,7 @@ def linearExpansionPercent(self, Tk=None, Tc=None):
return 0.02 * Tc


class FakeException(materials.ht9.HT9): # pylint: disable=abstract-method
class FakeMatException(materials.ht9.HT9): # pylint: disable=abstract-method
"""Fake material used to verify TestExceptions
Notes
Expand All @@ -664,7 +664,7 @@ class FakeException(materials.ht9.HT9): # pylint: disable=abstract-method
is higher to ensure that a negative block height is caught in TestExceptions:test_AssemblyAxialExpansionException.
"""

name = "FakeException"
name = "FakeMatException"

def __init__(self):
materials.ht9.HT9.__init__(self)
Expand Down
Loading

0 comments on commit 6ac6c66

Please sign in to comment.