Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterPSmith committed Nov 1, 2024
1 parent 00bdb8d commit 75c70b6
Showing 1 changed file with 90 additions and 32 deletions.
122 changes: 90 additions & 32 deletions armi/reactor/converters/tests/test_axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def _getConservationMetrics(self, a):
for c in iterSolidComponents(b):
# store mass and density of component
self.componentMass[c].append(c.getMass())
self.componentDensity[c].append(c.material.getProperty("density", c.temperatureInK))
self.componentDensity[c].append(
c.material.getProperty("density", c.temperatureInK)
)
# store steel mass for assembly
if c.p.flags in self.Steel_Component_Lst:
totalSteelMass += c.getMass()
Expand Down Expand Up @@ -166,14 +168,18 @@ def setUp(self):
AxialExpansionTestBase.setUp(self)
self.a = buildTestAssemblyWithFakeMaterial(name="FakeMat")

self.temp = Temperature(self.a.getTotalHeight(), numTempGridPts=11, tempSteps=10)
self.temp = Temperature(
self.a.getTotalHeight(), numTempGridPts=11, tempSteps=10
)

# get the right/expected answer
self._generateComponentWiseExpectedHeight()

# do the axial expansion
for idt in range(self.temp.tempSteps):
self.obj.performThermalAxialExpansion(self.a, self.temp.tempGrid, self.temp.tempField[idt, :], setFuel=True)
self.obj.performThermalAxialExpansion(
self.a, self.temp.tempGrid, self.temp.tempField[idt, :], setFuel=True
)
self._getConservationMetrics(self.a)

def tearDown(self):
Expand Down Expand Up @@ -207,9 +213,9 @@ def _generateComponentWiseExpectedHeight(self):
if ib > 0:
b.p.zbottom = assem[ib - 1].p.ztop
if idt > 0:
dll = (0.02 * aveBlockTemp[ib, idt] - 0.02 * aveBlockTemp[ib, idt - 1]) / (
100.0 + 0.02 * aveBlockTemp[ib, idt - 1]
)
dll = (
0.02 * aveBlockTemp[ib, idt] - 0.02 * aveBlockTemp[ib, idt - 1]
) / (100.0 + 0.02 * aveBlockTemp[ib, idt - 1])
thermExpansionFactor = 1.0 + dll
b.p.ztop = thermExpansionFactor * b.p.height + b.p.zbottom
self.trueZtop[ib, idt] = b.p.ztop
Expand Down Expand Up @@ -326,7 +332,9 @@ def complexConservationTest(self, a):
# adjust component temperatures by temp
for b in a:
for c in iterSolidComponents(b):
axialExpChngr.expansionData.updateComponentTemp(c, c.temperatureInC + temp)
axialExpChngr.expansionData.updateComponentTemp(
c, c.temperatureInC + temp
)
# get U235/B10 and FE56 mass pre-expansion
prevFE56Mass = a.getMass("FE56")
prevMass = self._getMass(a)
Expand All @@ -336,7 +344,9 @@ def complexConservationTest(self, a):
# ensure that total U235/B10 and FE56 mass is conserved post-expansion
newFE56Mass = a.getMass("FE56")
newMass = self._getMass(a)
self.assertAlmostEqual(newFE56Mass / prevFE56Mass, 1.0, places=14, msg=f"{a}")
self.assertAlmostEqual(
newFE56Mass / prevFE56Mass, 1.0, places=14, msg=f"{a}"
)
if newMass:
self.assertAlmostEqual(newMass / prevMass, 1.0, places=14, msg=f"{a}")

Expand Down Expand Up @@ -387,7 +397,9 @@ def test_prescribedExpansionContractionConservation(self):
fracLst = growthFrac + zeros(len(componentLst))
oldMasses, oldNDens = self._getComponentMassAndNDens(a)
# do the expansion
axExpChngr.performPrescribedAxialExpansion(a, componentLst, fracLst, setFuel=True)
axExpChngr.performPrescribedAxialExpansion(
a, componentLst, fracLst, setFuel=True
)
newMasses, newNDens = self._getComponentMassAndNDens(a)
self._checkMass(oldMasses, newMasses)
self._checkNDens(oldNDens, newNDens, growthFrac)
Expand All @@ -413,7 +425,9 @@ def _checkNDens(self, prevNDen, newNDens, ratio):
self.assertAlmostEqual(prev / new, ratio, msg=f"{prev} / {new}")

def _checkDetailedNDens(self, prevDetailedNDen, newDetailedNDens, ratio):
for prevComp, newComp in zip(prevDetailedNDen.values(), newDetailedNDens.values()):
for prevComp, newComp in zip(
prevDetailedNDen.values(), newDetailedNDens.values()
):
for prev, new in zip(prevComp, newComp):
if prev:
self.assertAlmostEqual(prev / new, ratio, msg=f"{prev} / {new}")
Expand Down Expand Up @@ -450,11 +464,15 @@ def test_targetComponentMassConservation(self):
self.expandAssemForMassConservationTest()
for cName, masses in self.componentMass.items():
for i in range(1, len(masses)):
self.assertAlmostEqual(masses[i], masses[i - 1], msg=f"{cName} mass not right")
self.assertAlmostEqual(
masses[i], masses[i - 1], msg=f"{cName} mass not right"
)

for cName, density in self.componentDensity.items():
for i in range(1, len(density)):
self.assertLess(density[i], density[i - 1], msg=f"{cName} density not right.")
self.assertLess(
density[i], density[i - 1], msg=f"{cName} density not right."
)

for i in range(1, len(self.totalAssemblySteelMass)):
self.assertAlmostEqual(
Expand Down Expand Up @@ -482,7 +500,9 @@ def test_noMovementACLP(self):
assembly.add(_buildTestBlock("fuel", "FakeMat", 25.0, 10.0))
assembly.add(_buildTestBlock("fuel", "FakeMat", 25.0, 10.0))
assembly.add(_buildTestBlock("plenum", "FakeMat", 25.0, 10.0))
assembly.add(_buildTestBlock("aclp", "FakeMat", 25.0, 10.0)) # "aclp plenum" also works
assembly.add(
_buildTestBlock("aclp", "FakeMat", 25.0, 10.0)
) # "aclp plenum" also works
assembly.add(_buildTestBlock("plenum", "FakeMat", 25.0, 10.0))
assembly.add(_buildDummySodium(25.0, 10.0))
assembly.calculateZCoords()
Expand Down Expand Up @@ -607,7 +627,9 @@ def test_manageCoreMesh(self):

def test_componentConservation(self):
self.axialExpChngr.manageCoreMesh(self.r)
newDetailedNDens, newVolumes = self._getComponentDetailedNDensAndVol(self.componentLst)
newDetailedNDens, newVolumes = self._getComponentDetailedNDensAndVol(
self.componentLst
)
for c in newVolumes.keys():
self._checkMass(
self.origDetailedNDens[c],
Expand All @@ -627,9 +649,13 @@ def _getComponentDetailedNDensAndVol(self, componentLst):
return (detailedNDens, volumes)

def _checkMass(self, origDetailedNDens, origVolume, newDetailedNDens, newVolume, c):
for prevMass, newMass in zip(origDetailedNDens * origVolume, newDetailedNDens * newVolume):
for prevMass, newMass in zip(
origDetailedNDens * origVolume, newDetailedNDens * newVolume
):
if c.parent.hasFlags(Flags.FUEL):
self.assertAlmostEqual(prevMass, newMass, delta=1e-12, msg=f"{c}, {c.parent}")
self.assertAlmostEqual(
prevMass, newMass, delta=1e-12, msg=f"{c}, {c.parent}"
)
else:
# should not conserve mass here as it is structural material above active fuel
self.assertAlmostEqual(newMass / prevMass, 0.99, msg=f"{c}, {c.parent}")
Expand Down Expand Up @@ -687,15 +713,19 @@ def test_updateComponentTempsBy1DTempFieldValueError(self):
tempGrid = [5.0, 15.0, 35.0]
tempField = linspace(25.0, 310.0, 3)
with self.assertRaises(ValueError) as cm:
self.obj.expansionData.updateComponentTempsBy1DTempField(tempGrid, tempField)
self.obj.expansionData.updateComponentTempsBy1DTempField(
tempGrid, tempField
)
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)

def test_updateComponentTempsBy1DTempFieldRuntimeError(self):
tempGrid = [5.0, 15.0, 35.0]
tempField = linspace(25.0, 310.0, 10)
with self.assertRaises(RuntimeError) as cm:
self.obj.expansionData.updateComponentTempsBy1DTempField(tempGrid, tempField)
self.obj.expansionData.updateComponentTempsBy1DTempField(
tempGrid, tempField
)
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)

Expand All @@ -706,7 +736,9 @@ def test_AssemblyAxialExpansionException(self):
temp = Temperature(self.a.getTotalHeight(), numTempGridPts=11, tempSteps=10)
with self.assertRaises(ArithmeticError) as cm:
for idt in range(temp.tempSteps):
self.obj.expansionData.updateComponentTempsBy1DTempField(temp.tempGrid, temp.tempField[idt, :])
self.obj.expansionData.updateComponentTempsBy1DTempField(
temp.tempGrid, temp.tempField[idt, :]
)
self.obj.expansionData.computeThermalExpansionFactors()
self.obj.axiallyExpandAssembly()

Expand All @@ -721,7 +753,9 @@ def test_isFuelLocked(self):
This is implemented by creating a fuel block that contains no fuel component
and passing it to ExpansionData::_isFuelLocked.
"""
expdata = ExpansionData(HexAssembly("testAssemblyType"), setFuel=True, expandFromTinputToThot=False)
expdata = ExpansionData(
HexAssembly("testAssemblyType"), setFuel=True, expandFromTinputToThot=False
)
b_NoFuel = HexBlock("fuel", height=10.0)
shieldDims = {
"Tinput": 25.0,
Expand Down Expand Up @@ -883,7 +917,9 @@ def test_manuallySetTargetComponent(self):
)

# check that target component is stored on expansionData object correctly
self.expData._componentDeterminesBlockHeight[b.getComponentByName(b.p.axialExpTargetComponent)] = True
self.expData._componentDeterminesBlockHeight[
b.getComponentByName(b.p.axialExpTargetComponent)
] = True
self.assertTrue(self.expData.isTargetComponent(duct))


Expand Down Expand Up @@ -961,7 +997,9 @@ def test_coldAssemblyExpansion(self):
),
)
for bStd, bExp in zip(aStd, aExp):
hasCustomMaterial = any(isinstance(c.material, custom.Custom) for c in bStd)
hasCustomMaterial = any(
isinstance(c.material, custom.Custom) for c in bStd
)
if hasCustomMaterial:
checkColdBlockHeight(bStd, bExp, self.assertAlmostEqual, "the same")
else:
Expand All @@ -988,7 +1026,9 @@ def test_coldAssemblyExpansion(self):
msg=msg,
)

def checkColdHeightBlockMass(self, bStd: HexBlock, bExp: HexBlock, flagType: Flags, nuclide: str):
def checkColdHeightBlockMass(
self, bStd: HexBlock, bExp: HexBlock, flagType: Flags, nuclide: str
):
"""Checks that nuclide masses for blocks with input cold heights and
"inputHeightsConsideredHot": True are underpredicted.
Expand Down Expand Up @@ -1070,20 +1110,28 @@ def runTest(
if assertionBool:
self.assertTrue(
areAxiallyLinked(typeA, typeB),
msg="Test {0:s} failed for component type {1:s}!".format(name, str(method)),
msg="Test {0:s} failed for component type {1:s}!".format(
name, str(method)
),
)
self.assertTrue(
areAxiallyLinked(typeB, typeA),
msg="Test {0:s} failed for component type {1:s}!".format(name, str(method)),
msg="Test {0:s} failed for component type {1:s}!".format(
name, str(method)
),
)
else:
self.assertFalse(
areAxiallyLinked(typeA, typeB),
msg="Test {0:s} failed for component type {1:s}!".format(name, str(method)),
msg="Test {0:s} failed for component type {1:s}!".format(
name, str(method)
),
)
self.assertFalse(
areAxiallyLinked(typeB, typeA),
msg="Test {0:s} failed for component type {1:s}!".format(name, str(method)),
msg="Test {0:s} failed for component type {1:s}!".format(
name, str(method)
),
)

def test_overlappingSolidPins(self):
Expand Down Expand Up @@ -1142,7 +1190,9 @@ def test_annularPinNotOverlappingWithAnnulus(self):
componentTypesToTest = {
Circle: [{"od": 0.6, "id": 0.3}, {"od": 1.0, "id": 0.6}],
}
self.runTest(componentTypesToTest, False, "test_annularPinNotOverlappingWithAnnulus")
self.runTest(
componentTypesToTest, False, "test_annularPinNotOverlappingWithAnnulus"
)

def test_annularPinOverlappingWithAnnuls(self):
componentTypesToTest = {
Expand All @@ -1154,11 +1204,17 @@ def test_thinAnnularPinOverlappingWithThickAnnulus(self):
componentTypesToTest = {
Circle: [{"od": 0.7, "id": 0.3}, {"od": 0.6, "id": 0.5}],
}
self.runTest(componentTypesToTest, True, "test_thinAnnularPinOverlappingWithThickAnnulus")
self.runTest(
componentTypesToTest, True, "test_thinAnnularPinOverlappingWithThickAnnulus"
)

def test_AnnularHexOverlappingThickAnnularHex(self):
componentTypesToTest = {Hexagon: [{"op": 1.0, "ip": 0.8}, {"op": 1.2, "ip": 0.8}]}
self.runTest(componentTypesToTest, True, "test_AnnularHexOverlappingThickAnnularHex")
componentTypesToTest = {
Hexagon: [{"op": 1.0, "ip": 0.8}, {"op": 1.2, "ip": 0.8}]
}
self.runTest(
componentTypesToTest, True, "test_AnnularHexOverlappingThickAnnularHex"
)

def test_liquids(self):
componentTypesToTest = {
Expand Down Expand Up @@ -1355,7 +1411,9 @@ def test_multiBlock(self):

def test_emptyBlocks(self):
"""Test even smaller edge case when no blocks are passed."""
with self.assertRaisesRegex(ValueError, "No blocks passed. Cannot determine links"):
with self.assertRaisesRegex(
ValueError, "No blocks passed. Cannot determine links"
):
AssemblyAxialLinkage.getLinkedBlocks([])

def test_onAssembly(self):
Expand Down

0 comments on commit 75c70b6

Please sign in to comment.