Skip to content

Commit

Permalink
Merge 417b399 into deb7c0f
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Oct 24, 2022
2 parents deb7c0f + 417b399 commit d50e603
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
6 changes: 3 additions & 3 deletions armi/reactor/converters/geometryConverters.py
Expand Up @@ -208,7 +208,7 @@ def convert(self, r):
# Add new fuel assembly to the core
if assem.hasFlags(self.overwriteList):
fuelAssem = self._sourceReactor.core.createAssemblyOfType(
assemType=self.fuelType
assemType=self.fuelType, cs=self._cs
)
# Remove existing assembly in the core location before adding new assembly
if assem.hasFlags(self.overwriteList):
Expand Down Expand Up @@ -308,8 +308,8 @@ def addRing(self, assemType="big shield"):
if dist <= newRingDist: # check distance
if assem is None: # no assembly in that position, add assembly
newAssem = r.core.createAssemblyOfType(
assemType=assemType
) # create a fuel assembly
assemType=assemType, cs=self._cs
)
r.core.add(newAssem, locator) # put new assembly in reactor!
else: # all other types of assemblies (fuel, control, etc) leave as is
pass
Expand Down
26 changes: 12 additions & 14 deletions armi/reactor/reactors.py
Expand Up @@ -27,18 +27,18 @@
The Reactor contains a Core, which contains a heirachical collection of Assemblies, which in turn
each contain a collection of Blocks.
"""
from typing import Optional
import collections
import copy
import itertools
import os
import time
from typing import Optional

import numpy
import tabulate

from armi import runLog
from armi import getPluginManagerOrFail, materials, nuclearDataIO, settings
from armi import runLog
from armi.nuclearDataIO import xsLibraries
from armi.reactor import assemblies
from armi.reactor import assemblyLists
Expand All @@ -49,13 +49,13 @@
from armi.reactor import reactorParameters
from armi.reactor import systemLayoutInput
from armi.reactor import zones
from armi.reactor.converters.axialExpansionChanger import AxialExpansionChanger
from armi.reactor.flags import Flags
from armi.settings.fwSettings.globalSettings import CONF_MATERIAL_NAMESPACE_ORDER
from armi.utils import createFormattedStrWithDelimiter, units
from armi.utils import directoryChangers
from armi.utils.iterables import Sequence
from armi.utils.mathematics import average1DWithinTolerance
from armi.reactor.converters.axialExpansionChanger import AxialExpansionChanger


class Reactor(composites.Composite):
Expand Down Expand Up @@ -164,10 +164,6 @@ class Core(composites.Composite):
assemblies : list
List of assembly objects that are currently in the core
cs : CaseSettings object
Global settings for the case
"""

pDefs = reactorParameters.defineCoreParameters()
Expand Down Expand Up @@ -1646,20 +1642,20 @@ def setMoveList(self, cycle, oldLoc, newLoc, enrichList, assemblyType, assemName
self.moveList[cycle].remove(data)
self.moveList[cycle].append(data)

def createFreshFeed(self):
def createFreshFeed(self, cs=None):
"""
Creates a new feed assembly.
Parameters
----------
cs : CaseSettings object
Global settings for the case
See Also
--------
createAssemblyOfType: creates an assembly
Notes
-----
createFreshFeed and createAssemblyOfType and this
all need to be merged together somehow.
"""
return self.createAssemblyOfType(assemType=self._freshFeedType)
return self.createAssemblyOfType(assemType=self._freshFeedType, cs=cs)

def createAssemblyOfType(self, assemType=None, enrichList=None, cs=None):
"""
Expand All @@ -1671,6 +1667,8 @@ def createAssemblyOfType(self, assemType=None, enrichList=None, cs=None):
The assembly type to create
enrichList : list
weight percent enrichments of each block
cs : CaseSettings object
Global settings for the case
Returns
-------
Expand Down
14 changes: 10 additions & 4 deletions armi/reactor/tests/test_reactors.py
Expand Up @@ -751,7 +751,7 @@ def test_createAssemblyOfType(self):
"""Test creation of new assemblies."""
# basic creation
aOld = self.r.core.getFirstAssembly(Flags.FUEL)
aNew = self.r.core.createAssemblyOfType(aOld.getType())
aNew = self.r.core.createAssemblyOfType(aOld.getType(), cs=self.o.cs)
self.assertAlmostEqual(aOld.getMass(), aNew.getMass())

# test axial mesh alignment
Expand All @@ -762,7 +762,7 @@ def test_createAssemblyOfType(self):
) # use i+1 to skip 0.0

# creation with modified enrichment
aNew2 = self.r.core.createAssemblyOfType(aOld.getType(), 0.195)
aNew2 = self.r.core.createAssemblyOfType(aOld.getType(), 0.195, self.o.cs)
fuelBlock = aNew2.getFirstBlock(Flags.FUEL)
self.assertAlmostEqual(fuelBlock.getUraniumMassEnrich(), 0.195)

Expand All @@ -771,12 +771,18 @@ def test_createAssemblyOfType(self):
bol = self.r.blueprints.assemblies[aOld.getType()]
changer = AxialExpansionChanger()
changer.performPrescribedAxialExpansion(bol, [fuelComp], [0.05])
aNew3 = self.r.core.createAssemblyOfType(aOld.getType(), 0.195)
aNew3 = self.r.core.createAssemblyOfType(aOld.getType(), 0.195, self.o.cs)
self.assertAlmostEqual(
aNew3.getFirstBlock(Flags.FUEL).getUraniumMassEnrich(), 0.195
)
self.assertAlmostEqual(aNew3.getMass(), bol.getMass())

def test_createFreshFeed(self):
# basic creation
aOld = self.r.core.getFirstAssembly(Flags.FEED)
aNew = self.r.core.createFreshFeed(cs=self.o.cs)
self.assertAlmostEqual(aOld.getMass(), aNew.getMass())

def test_createAssemblyOfTypeExpandedCore(self):
"""Test creation of new assemblies in an expanded core."""
# change the mesh of inner blocks
Expand All @@ -793,7 +799,7 @@ def test_createAssemblyOfTypeExpandedCore(self):
aType = self.r.core.getFirstAssembly(Flags.FUEL).getType()

# demonstrate we can still create assemblies
self.assertTrue(self.r.core.createAssemblyOfType(aType))
self.assertTrue(self.r.core.createAssemblyOfType(aType, cs=self.o.cs))

def test_getAvgTemp(self):
t0 = self.r.core.getAvgTemp([Flags.CLAD, Flags.WIRE, Flags.DUCT])
Expand Down
28 changes: 19 additions & 9 deletions armi/utils/tests/test_codeTiming.py
Expand Up @@ -12,23 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Unit tests for code timing.
"""
import unittest
"""Unit tests for code timing"""
# pylint: disable=missing-function-docstring,missing-class-docstring,protected-access,invalid-name,no-self-use,no-method-argument,import-outside-toplevel
import time
import unittest

from armi.utils import codeTiming


class CodeTimingTest(unittest.TestCase):
def setUp(self):
codeTiming._Timer._frozen = False # pylint: disable=protected-access
codeTiming.MasterTimer._instance = None # pylint: disable=protected-access
codeTiming._Timer._frozen = False
codeTiming.MasterTimer._instance = None

def tearDown(self):
codeTiming._Timer._frozen = False # pylint: disable=protected-access
codeTiming.MasterTimer._instance = None # pylint: disable=protected-access
codeTiming._Timer._frozen = False
codeTiming.MasterTimer._instance = None

def test_method_definitions(self):
@codeTiming.timed
Expand Down Expand Up @@ -92,16 +91,18 @@ def test_master(self):
def test_messy_starts_and_stops(self):
master = codeTiming.getMasterTimer()

name = "sometimerthatihaventmadeyet"
larger_time_start = master.time()
time.sleep(0.01)
timer = master.getTimer("sometimerthatihaventmadeyet")
timer = master.getTimer(name)
time.sleep(0.01)
lesser_time_start = master.time()

timer.start() # 1st time pair
timer.start() # 2nd time pair
timer.start() # 3rd time pair
timer.stop()
self.assertIn(name, str(timer))
self.assertTrue(timer.isActive)

timer.stop()
Expand All @@ -116,13 +117,22 @@ def test_messy_starts_and_stops(self):
lesser_time_end = master.time()
time.sleep(0.01)
timer.stop()
self.assertIn(name, str(timer))
self.assertEqual(len(timer.times), 4)
time.sleep(0.01)
larger_time_end = master.time()

# even with all the starts and stops the total time needs to be between these two values.
self.assertGreater(timer.time, lesser_time_end - lesser_time_start)
self.assertLess(timer.time, larger_time_end - larger_time_start)
self.assertEqual(timer.pauses, 3)

# test report
table = codeTiming.MasterTimer.report(inclusion_cutoff=0.01, total_time=True)
self.assertIn("TIMER REPORTS", table)
self.assertIn(name, table)
self.assertIn("CUMULATIVE", table)
self.assertIn("ACTIVE", table)


if __name__ == "__main__":
Expand Down

0 comments on commit d50e603

Please sign in to comment.