Skip to content

Commit

Permalink
Adding code coverage to GlobalFluxInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Jun 16, 2024
1 parent 5b2a304 commit 0b77d7b
Showing 1 changed file with 68 additions and 1 deletion.
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 @@ -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(customSettings={CONF_XS_KERNEL: "MC2v2"})
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(customSettings={CONF_XS_KERNEL: "MC2v2"})

# 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 0b77d7b

Please sign in to comment.