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

Adding some code coverage #1798

Merged
merged 10 commits into from
Aug 1, 2024
12 changes: 10 additions & 2 deletions armi/reactor/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,12 @@ def test_getUraniumNumEnrich(self):
u5 = self.block.getNumberDensity("U235")
ref = u5 / (u8 + u5)

places = 6
self.assertAlmostEqual(cur, ref, places=places)
self.assertAlmostEqual(cur, ref, places=6)

# test the zero edge case
self.block.adjustUEnrich(0)
cur = self.block.getUraniumNumEnrich()
self.assertEqual(cur, 0.0)

def test_getNumberOfAtoms(self):
self.block.clearNumberDensities()
Expand Down Expand Up @@ -1217,6 +1221,10 @@ def test_getComponentsOfMaterial(self):
],
)

# test edge case
cur = self.block.getComponentsOfMaterial(None, "UZr")
self.assertEqual(cur[0], ref)

def test_getComponentByName(self):
"""Test children by name.

Expand Down
105 changes: 76 additions & 29 deletions armi/reactor/tests/test_composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,53 @@ def test_expandLFPs(self):
self.assertEqual(len(numDens), 9)
self.assertEqual(numDens["MO99"], 0)

def test_setChildrenLumpedFissionProducts(self):
# build a lumped fission product collection
fpd = getDummyLFPFile()
lfps = fpd.createLFPsFromFile()

# validate that the LFP collection is None
self.container.setChildrenLumpedFissionProducts(None)
for c in self.container.getChildren():
self.assertIsNone(c._lumpedFissionProducts)

# validate that the LFP collection is not None
self.container.setChildrenLumpedFissionProducts(lfps)
for c in self.container.getChildren():
self.assertIsNotNone(c._lumpedFissionProducts)

def test_requiresLumpedFissionProducts(self):
# build a lumped fission product collection
fpd = getDummyLFPFile()
lfps = fpd.createLFPsFromFile()
self.container.setChildrenLumpedFissionProducts(lfps)

# test the null case
result = self.container.requiresLumpedFissionProducts(None)
self.assertFalse(result)

# test the usual case
result = self.container.requiresLumpedFissionProducts(set())
self.assertFalse(result)
john-science marked this conversation as resolved.
Show resolved Hide resolved

# test a positive case
result = self.container.requiresLumpedFissionProducts(["LFP35"])
self.assertTrue(result)

def test_getLumpedFissionProductsIfNecessaryNullCase(self):
# build a lumped fission product collection
fpd = getDummyLFPFile()
lfps = fpd.createLFPsFromFile()
self.container.setChildrenLumpedFissionProducts(lfps)

# test the null case
result = self.container.getLumpedFissionProductsIfNecessary(None)
self.assertEqual(len(result), 0)

# test a positive case
result = self.container.getLumpedFissionProductsIfNecessary(["LFP35"])
self.assertGreater(len(result), 0)

def test_getIntegratedMgFlux(self):
mgFlux = self.container.getIntegratedMgFlux()
self.assertEqual(mgFlux, [0.0])
Expand Down Expand Up @@ -429,13 +476,13 @@ class TestCompositeTree(unittest.TestCase):

def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
self.Block = None
self.block = None
self.r = None

def setUp(self):
self.Block = loadTestBlock()
self.r = self.Block.core.r
self.Block.setHeight(100.0)
self.block = loadTestBlock()
self.r = self.block.core.r
self.block.setHeight(100.0)
self.refDict = {
"U235": 0.00275173784234,
"U238": 0.0217358415457,
Expand All @@ -447,28 +494,28 @@ def setUp(self):
"NA23": 2e-2,
"ZR": 0.00709003962772,
}
self.Block.setNumberDensities(self.refDict)
self.block.setNumberDensities(self.refDict)

def test_ordering(self):
a = assemblies.Assembly("dummy")
a.spatialGrid = grids.axialUnitGrid(2, armiObject=a)
otherBlock = deepcopy(self.Block)
a.add(self.Block)
otherBlock = deepcopy(self.block)
a.add(self.block)
a.add(otherBlock)
self.assertTrue(self.Block < otherBlock)
locator = self.Block.spatialLocator
self.Block.spatialLocator = otherBlock.spatialLocator
self.assertTrue(self.block < otherBlock)
locator = self.block.spatialLocator
self.block.spatialLocator = otherBlock.spatialLocator
otherBlock.spatialLocator = locator
self.assertTrue(otherBlock < self.Block)
self.assertTrue(otherBlock < self.block)

def test_summing(self):
a = assemblies.Assembly("dummy")
a.spatialGrid = grids.axialUnitGrid(2, armiObject=a)
otherBlock = deepcopy(self.Block)
a.add(self.Block)
otherBlock = deepcopy(self.block)
a.add(self.block)
a.add(otherBlock)

b = self.Block + otherBlock
b = self.block + otherBlock
self.assertEqual(len(b), 26)
self.assertFalse(b[0].is3D)
self.assertIn("Circle", str(b[0]))
Expand All @@ -486,7 +533,7 @@ def test_getNuclides(self):
The getNuclides should return all keys that have ever been in this block, including values
that are at trace.
"""
cur = self.Block.getNuclides()
cur = self.block.getNuclides()
ref = self.refDict.keys()
for key in ref:
self.assertIn(key, cur)
Expand Down Expand Up @@ -521,9 +568,9 @@ def test_getChildrenIncludeMaterials(self):
def test_getHMMass(self):
fuelDims = {"Tinput": 273.0, "Thot": 273.0, "od": 0.76, "id": 0.0, "mult": 1.0}
self.fuelComponent = components.Circle("fuel", "UZr", **fuelDims)
self.Block.add(self.fuelComponent)
self.block.add(self.fuelComponent)

self.Block.clearNumberDensities()
self.block.clearNumberDensities()
self.refDict = {
"U235": 0.00275173784234,
"U238": 0.0217358415457,
Expand All @@ -535,14 +582,14 @@ def test_getHMMass(self):
"NA23": 2e-2,
"ZR": 0.00709003962772,
}
self.Block.setNumberDensities(self.refDict)
self.block.setNumberDensities(self.refDict)

cur = self.Block.getHMMass()
cur = self.block.getHMMass()

mass = 0.0
for nucName in self.refDict.keys():
if nucDir.isHeavyMetal(nucName):
mass += self.Block.getMass(nucName)
mass += self.block.getMass(nucName)

places = 6
self.assertAlmostEqual(cur, mass, places=places)
Expand All @@ -551,28 +598,28 @@ def test_getFPMass(self):
fuelDims = {"Tinput": 273.0, "Thot": 273.0, "od": 0.76, "id": 0.0, "mult": 1.0}
self.fuelComponent = components.Circle("fuel", "UZr", **fuelDims)
self.fuelComponent.material.setMassFrac("LFP38", 0.25)
self.Block.add(self.fuelComponent)
self.block.add(self.fuelComponent)

refDict = {"LFP35": 0.1, "LFP38": 0.05, "LFP39": 0.7}
self.fuelComponent.setNumberDensities(refDict)

cur = self.Block.getFPMass()
cur = self.block.getFPMass()

mass = 0.0
for nucName in refDict.keys():
mass += self.Block.getMass(nucName)
mass += self.block.getMass(nucName)
ref = mass

places = 6
self.assertAlmostEqual(cur, ref, places=places)

def test_getFissileMass(self):
cur = self.Block.getFissileMass()
cur = self.block.getFissileMass()

mass = 0.0
for nucName in self.refDict.keys():
if nucName in nuclideBases.NuclideBase.fissile:
mass += self.Block.getMass(nucName)
mass += self.block.getMass(nucName)
ref = mass

places = 6
Expand All @@ -585,12 +632,12 @@ def test_getMaxParam(self):
:id: T_ARMI_CMP_PARAMS0
:tests: R_ARMI_CMP_PARAMS
"""
for ci, c in enumerate(self.Block):
for ci, c in enumerate(self.block):
if isinstance(c, basicShapes.Circle):
c.p.id = ci
lastSeen = c
lastIndex = ci
cMax, comp = self.Block.getMaxParam("id", returnObj=True)
cMax, comp = self.block.getMaxParam("id", returnObj=True)
self.assertEqual(cMax, lastIndex)
self.assertIs(comp, lastSeen)

Expand All @@ -601,12 +648,12 @@ def test_getMinParam(self):
:id: T_ARMI_CMP_PARAMS1
:tests: R_ARMI_CMP_PARAMS
"""
for ci, c in reversed(list(enumerate(self.Block))):
for ci, c in reversed(list(enumerate(self.block))):
if isinstance(c, basicShapes.Circle):
c.p.id = ci
lastSeen = c
lastIndex = ci
cMax, comp = self.Block.getMinParam("id", returnObj=True)
cMax, comp = self.block.getMinParam("id", returnObj=True)
self.assertEqual(cMax, lastIndex)
self.assertIs(comp, lastSeen)

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 @@ -384,6 +384,16 @@ def test_getAllXsSuffixes(self):
expectedSuffixes = ["AA"]
self.assertListEqual(expectedSuffixes, actualSuffixes)

def test_genBlocksByLocName(self):
self.r.core.genBlocksByLocName()
self.assertGreater(len(self.r.core.blocksByLocName), 300)
self.assertIn("009-009-004", self.r.core.blocksByLocName)

def test_setPitchUniform(self):
self.r.core.setPitchUniform(0.0)
for b in self.r.core.getBlocks():
self.assertEqual(b.getPitch(), 0.0)

def test_countBlocksOfType(self):
numControlBlocks = self.r.core.countBlocksWithFlags([Flags.DUCT, Flags.CONTROL])

Expand Down
Loading