Skip to content

Commit

Permalink
Bug fix for global material namespace order (#1046)
Browse files Browse the repository at this point in the history
- isolate global namespace change to be local in test_axialExpansionChanger.py
  • Loading branch information
albeanth committed Dec 21, 2022
1 parent e3e7027 commit 15a710f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
54 changes: 39 additions & 15 deletions armi/reactor/converters/tests/test_axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,13 @@
_determineLinked,
)
from armi import materials
from armi.materials import custom
from armi.materials import custom, _MATERIAL_NAMESPACE_ORDER
from armi.reactor.flags import Flags
from armi.tests import mockRunLogs
from armi.utils import units

# set namespace order for materials so that fake HT9 material can be found
materials.setMaterialNamespaceOrder(
["armi.reactor.converters.tests.test_axialExpansionChanger", "armi.materials"]
)


class Base(unittest.TestCase):
class AxialExpansionTestBase(unittest.TestCase):
"""common methods and variables for unit tests"""

Steel_Component_Lst = [
Expand All @@ -69,6 +64,18 @@ def setUp(self):
self.massAndDens = {}
self.steelMass = []
self.blockHeights = {}
self.origNameSpace = _MATERIAL_NAMESPACE_ORDER
# set namespace order for materials so that fake HT9 material can be found
materials.setMaterialNamespaceOrder(
[
"armi.reactor.converters.tests.test_axialExpansionChanger",
"armi.materials",
]
)

def tearDown(self):
# reset global namespace
materials.setMaterialNamespaceOrder(self.origNameSpace)

def _getConservationMetrics(self, a):
"""retrieves and stores various conservation metrics
Expand Down Expand Up @@ -170,11 +177,11 @@ def _generateTempField(self, coldTemp, hotInletTemp, uniform):
self.tempField[i, :] = tmp[i]


class TestAxialExpansionHeight(Base, unittest.TestCase):
class TestAxialExpansionHeight(AxialExpansionTestBase, unittest.TestCase):
"""verify that test assembly is expanded correctly"""

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

self.temp = Temperature(
Expand All @@ -193,6 +200,9 @@ def setUp(self):
self._getConservationMetrics(self.a)
self.axialMeshLocs[idt, :] = self.a.getAxialMesh()

def tearDown(self):
AxialExpansionTestBase.tearDown(self)

def test_AssemblyAxialExpansionHeight(self):
"""test the axial expansion gives correct heights for component-based expansion"""
for idt in range(self.temp.tempSteps):
Expand Down Expand Up @@ -264,13 +274,16 @@ def _getAveTemp(self, ib, idt, assem):
return mean(tmpMapping)


class TestConservation(Base, unittest.TestCase):
class TestConservation(AxialExpansionTestBase, unittest.TestCase):
"""verify that conservation is maintained in assembly-level axial expansion"""

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

def tearDown(self):
AxialExpansionTestBase.tearDown(self)

def expandAssemForMassConservationTest(self):
"""initialize class variables for mass conservation checks"""
# pylint: disable=attribute-defined-outside-init
Expand Down Expand Up @@ -560,14 +573,17 @@ def test_manageCoreMesh(self):
self.assertLess(old, new)


class TestExceptions(Base, unittest.TestCase):
class TestExceptions(AxialExpansionTestBase, unittest.TestCase):
"""Verify exceptions are caught"""

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

def tearDown(self):
AxialExpansionTestBase.tearDown(self)

def test_isTopDummyBlockPresent(self):
# build test assembly without dummy
assembly = HexAssembly("testAssemblyType")
Expand Down Expand Up @@ -701,16 +717,20 @@ def test_getLinkedComponents(self):
self.assertEqual(cm.exception, 3)


class TestDetermineTargetComponent(unittest.TestCase):
class TestDetermineTargetComponent(AxialExpansionTestBase, unittest.TestCase):
"""verify determineTargetComponent method is properly updating _componentDeterminesBlockHeight"""

def setUp(self):
AxialExpansionTestBase.setUp(self)
self.obj = AxialExpansionChanger()
self.a = buildTestAssemblyWithFakeMaterial(name="FakeMatException")
self.obj.setAssembly(self.a)
# need an empty dictionary because we want to test for the added component only
self.obj.expansionData._componentDeterminesBlockHeight = {}

def tearDown(self):
AxialExpansionTestBase.tearDown(self)

def test_determineTargetComponent(self):
# build a test block
b = HexBlock("fuel", height=10.0)
Expand Down Expand Up @@ -897,13 +917,17 @@ def checkColdBlockHeight(bStd, bExp, assertType, strForAssertion):
)


class TestLinkage(unittest.TestCase):
class TestLinkage(AxialExpansionTestBase, unittest.TestCase):
"""test axial linkage between components"""

def setUp(self):
"""contains common dimensions for all component class types"""
AxialExpansionTestBase.setUp(self)
self.common = ("test", "FakeMat", 25.0, 25.0) # name, material, Tinput, Thot

def tearDown(self):
AxialExpansionTestBase.tearDown(self)

def runTest(
self,
componentsToTest: dict,
Expand Down
1 change: 1 addition & 0 deletions doc/release/0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Bug fixes
#. Fixed bug with database writing and tight coupling. (`PR#1005 https://github.com/terrapower/armi/pull/1005`)
#. Fixed a bug where snapshot load would not respect the new cs["power"] setting.
#. Froze the NumPy version to be <= 1.23.5 (`PR#1035 https://github.com/terrapower/armi/pull/1035`) to continue to support numpy jagged arrays within the Database interface.
#. Fixed a bug where the material namespace order for test_axialExpansionChanger.py was persisting beyond the tests. (`PR#1046 https://github.com/terrapower/armi/pull/1046`)

ARMI v0.2.5
===========
Expand Down

0 comments on commit 15a710f

Please sign in to comment.