Skip to content

Commit

Permalink
Adding code coverage to FH & GlobalFluxInt (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Jun 17, 2024
1 parent 3b822bc commit 8ab9099
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
19 changes: 19 additions & 0 deletions armi/physics/fuelCycle/tests/test_fuelHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,25 @@ def test_dischargeSwapIncompatibleStationaryBlocks(self):
with self.assertRaises(ValueError):
fh.dischargeSwap(a2, a1)

def test_getAssembliesInRings(self):
fh = fuelHandlers.FuelHandler(self.o)
aList0 = fh._getAssembliesInRings([0], Flags.FUEL, False, None, False)
self.assertEqual(len(aList0), 1)

aList1 = fh._getAssembliesInRings([0, 1, 2], Flags.FUEL, False, None, False)
self.assertEqual(len(aList1), 3)

aList2 = fh._getAssembliesInRings([0, 1, 2], Flags.FUEL, True, None, False)
self.assertEqual(len(aList2), 3)

aList3 = fh._getAssembliesInRings(
[0, 1, 2, "SFP"], Flags.FUEL, True, None, False
)
self.assertEqual(len(aList3), 4)

aList4 = fh._getAssembliesInRings([0, 1, 2], Flags.FUEL, False, None, True)
self.assertEqual(len(aList4), 3)


class TestFuelPlugin(unittest.TestCase):
"""Tests that make sure the plugin is being discovered well."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for generic global flux interface."""
import logging
import unittest
from unittest.mock import patch

import numpy

from armi import runLog
from armi import settings
from armi.nuclearDataIO.cccc import isotxs
from armi.physics.neutronics.globalFlux import globalFluxInterface
Expand All @@ -30,6 +32,7 @@
from armi.reactor.tests import test_blocks
from armi.reactor.tests import test_reactors
from armi.tests import ISOAA_PATH
from armi.tests import mockRunLogs


class MockReactorParams:
Expand Down Expand Up @@ -210,7 +213,7 @@ class TestGlobalFluxInterfaceWithExecuters(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.cs = settings.Settings()
_o, cls.r = test_reactors.loadTestReactor()
cls.r = test_reactors.loadTestReactor()[1]

def setUp(self):
self.r.core.p.keff = 1.0
Expand Down Expand Up @@ -362,7 +365,7 @@ def test_mapper(self):
# Test DoseResultsMapper. Pass in full list of blocks to apply() in order
# to exercise blockList option (does not change behavior, since this is what
# apply() does anyway)
opts = globalFluxInterface.GlobalFluxOptions("test")
opts = globalFluxInterface.GlobalFluxOptions("test_mapper")
opts.fromUserSettings(o.cs)
dosemapper = globalFluxInterface.DoseResultsMapper(1000, opts)
dosemapper.apply(r, blockList=r.core.getBlocks())
Expand All @@ -373,6 +376,70 @@ def test_mapper(self):
mapper.clearFlux()
self.assertEqual(len(block.p.mgFlux), 0)

@patch("armi.reactor.composites.ArmiObject.getMaxParam")
def test_updateCycleDoseParams(self, mockGetMaxParam):
# set up situation
mockGetMaxParam.return_value = 1.23
o, r = test_reactors.loadTestReactor()
applyDummyFlux(r)
r.core.lib = isotxs.readBinary(ISOAA_PATH)
r.p.timeNode = 1
r.p.cycleLength = 365
opts = globalFluxInterface.GlobalFluxOptions("test_updateCycleDoseParams")
opts.fromUserSettings(o.cs)
opts.aclpDoseLimit = 100

# build the mapper
mapper = globalFluxInterface.DoseResultsMapper(1000, opts)
mapper.r = r

# test the starting position
self.assertEqual(mapper.r.core.p.elevationOfACLP3Cycles, 0)
self.assertEqual(mapper.r.core.p.elevationOfACLP7Cycles, 0)
self.assertEqual(mapper.r.core.p.dpaFullWidthHalfMax, 0)

# test the logs, as this case won't change the param values
with mockRunLogs.BufferLog() as mock:
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_updateCycleDoseParams")
runLog.LOG.setVerbosity(logging.INFO)
mapper.updateCycleDoseParams()
stdOut = mock.getStdout()
somethingStrange = "Something strange with detailedDpaThisCycle"
self.assertIn(somethingStrange, stdOut)
self.assertEqual(stdOut.count(somethingStrange), 3)

# test the ending position
self.assertEqual(mapper.r.core.p.elevationOfACLP3Cycles, 0)
self.assertEqual(mapper.r.core.p.elevationOfACLP7Cycles, 0)
self.assertEqual(mapper.r.core.p.dpaFullWidthHalfMax, 0)

def test_updateLoadpadDose(self):
# init test reactor
o, r = test_reactors.loadTestReactor()

# init options
opts = globalFluxInterface.GlobalFluxOptions("test_updateLoadpadDose")
opts.fromUserSettings(o.cs)
opts.aclpDoseLimit = 100
opts.loadPadElevation = 12
opts.loadPadLength = 24

# init mapper
mapper = globalFluxInterface.DoseResultsMapper(1000, opts)
mapper.r = r

# test logging from updateLoadpadDose
with mockRunLogs.BufferLog() as mock:
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_updateLoadpadDose")
runLog.LOG.setVerbosity(logging.INFO)

mapper.updateLoadpadDose()
self.assertIn("Above-core load", mock.getStdout())
self.assertIn("The peak ACLP dose", mock.getStdout())
self.assertIn("The max avg", mock.getStdout())

def test_getDpaXs(self):
cs = settings.Settings()
mapper = globalFluxInterface.GlobalFluxResultMapper(cs=cs)
Expand Down

0 comments on commit 8ab9099

Please sign in to comment.