Skip to content

Commit

Permalink
black and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterPSmith committed Nov 1, 2024
1 parent 1bc99ed commit 00bdb8d
Showing 1 changed file with 33 additions and 88 deletions.
121 changes: 33 additions & 88 deletions armi/reactor/converters/tests/test_axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

"""Test axialExpansionChanger."""

import collections
import os
import unittest
Expand Down Expand Up @@ -94,9 +95,7 @@ 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 @@ -167,18 +166,14 @@ 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 @@ -212,9 +207,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 @@ -331,9 +326,7 @@ 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 @@ -343,9 +336,7 @@ 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 @@ -396,9 +387,7 @@ 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 @@ -424,9 +413,7 @@ 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 @@ -463,15 +450,11 @@ 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 @@ -499,9 +482,7 @@ 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 @@ -626,9 +607,7 @@ 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 @@ -648,14 +627,12 @@ 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}")
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}")
self.assertAlmostEqual(newMass / prevMass, 0.99, msg=f"{c}, {c.parent}")


class TestExceptions(AxialExpansionTestBase, unittest.TestCase):
Expand Down Expand Up @@ -710,19 +687,15 @@ 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 @@ -733,9 +706,7 @@ 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 @@ -750,9 +721,7 @@ 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 @@ -914,9 +883,7 @@ 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 @@ -994,9 +961,7 @@ 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 @@ -1023,9 +988,7 @@ 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 @@ -1107,28 +1070,20 @@ 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 @@ -1187,9 +1142,7 @@ 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 @@ -1201,17 +1154,11 @@ 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 @@ -1408,9 +1355,7 @@ 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 00bdb8d

Please sign in to comment.