def makeDecayConstantTable(directory=None, cs=None): """ Make decay constants of the nuclides from the RIPL files. Parameters ---------- directory : str file path to read cs : dict case settings Returns ------- nuclideDecayConstants : dict decay constants indexed to nuclideBases """ if directory is None: if cs is None: cs = Settings() directory = cs["nuclideHalflifeLibraryPath"] DECAY_CONSTANTS.clear() for riplDecayFile in discoverRiplDecayFiles(directory): riplDecay = getNuclideDecayConstants(riplDecayFile) DECAY_CONSTANTS.update(riplDecay)
def test_fuelPerformanceOptions(self): fpo = FuelPerformanceOptions("test_fuelPerformanceOptions") self.assertEqual(fpo.label, "test_fuelPerformanceOptions") cs = Settings() fpo.fromUserSettings(cs) self.assertEqual(fpo.bondRemoval, cs[CONF_BOND_REMOVAL])
def getMasterCs(): """ Return the global case-settings object (cs). This can be called at any time to create or obtain the master Cs, a module-level CS intended to be shared by many other objects. It can have multiple instances in multiprocessing cases. Returns ------- cs : Settings The loaded cs object """ cs = Settings.instance if cs is None: cs = Settings() setMasterCs(cs) return cs
def recursivelyLoadSettingsFiles( rootDir, patterns: List[str], recursive=True, ignorePatterns: List[str] = None, handleInvalids=True, ): """ Scans path for valid xml files and returns their paths. Parameters ---------- rootDir : str The base path to scan for settings files patterns : list file patterns to match file names recursive : bool (optional) load files recursively ignorePatterns : list (optional) list of filename patterns to ignore handleInvalids : bool option to suppress errors generated when finding files that appear to be settings files but fail to load. This may happen when old settings are present. Returns ------- csFiles : list list of :py:class:`~armi.settings.caseSettings.Settings` objects. """ assert not isinstance( ignorePatterns, str), "Bare string passed as ignorePatterns. Make sure to pass a list" assert not isinstance( patterns, str), "Bare string passed as patterns. Make sure to pass a list" possibleSettings = [] runLog.info( "Finding potential settings files matching {}.".format(patterns)) if recursive: for directory, _list, files in os.walk(rootDir): matches = set() for pattern in patterns: matches |= set(fnmatch.filter(files, pattern)) if ignorePatterns is not None: for ignorePattern in ignorePatterns: matches -= set(fnmatch.filter(files, ignorePattern)) possibleSettings.extend( [os.path.join(directory, fname) for fname in matches]) else: for pattern in patterns: possibleSettings.extend(glob.glob(pattern)) csFiles = [] runLog.info("Checking for valid settings files.") for possibleSettingsFile in possibleSettings: if os.path.getsize(possibleSettingsFile) > 1e6: runLog.info( "skipping {} -- looks too big".format(possibleSettingsFile)) continue try: cs = Settings() cs.loadFromInputFile(possibleSettingsFile, handleInvalids=handleInvalids) csFiles.append(cs) runLog.extra("loaded {}".format(possibleSettingsFile)) except exceptions.InvalidSettingsFileError as ee: runLog.info("skipping {}\n {}".format(possibleSettingsFile, ee)) except yaml.composer.ComposerError as ee: runLog.info( "skipping {}; it appears to be an incomplete YAML snippet\n {}" .format(possibleSettingsFile, ee)) except Exception as ee: runLog.error( "Failed to parse {}.\nIt looked like a settings file but gave this exception:\n{}: {}" .format(possibleSettingsFile, type(ee).__name__, ee)) raise csFiles.sort(key=lambda csFile: csFile.caseTitle) return csFiles
class CyclesSettingsTests(unittest.TestCase): """ Check that we can correctly access the various cycle settings from the operator. """ detailedCyclesSettings = """ metadata: version: uncontrolled settings: power: 1000000000.0 nCycles: 3 cycles: - name: startup sequence cumulative days: [1, 2, 3] power fractions: [0.1, 0.2, 0.3] availability factor: 0.1 - cycle length: 10 burn steps: 5 power fractions: [0.2, 0.2, 0.2, 0.2, 0] availability factor: 0.5 - name: prepare for shutdown step days: [3, R4] power fractions: [0.3, R4] runType: Standard """ powerFractionsSolution = [ [0.1, 0.2, 0.3], [0.2, 0.2, 0.2, 0.2, 0], [0.3, 0.3, 0.3, 0.3, 0.3], ] cycleNamesSolution = ["startup sequence", None, "prepare for shutdown"] availabilityFactorsSolution = [0.1, 0.5, 1] stepLengthsSolution = [ [1, 1, 1], [10 / 5 * 0.5, 10 / 5 * 0.5, 10 / 5 * 0.5, 10 / 5 * 0.5, 10 / 5 * 0.5], [3, 3, 3, 3, 3], ] cycleLengthsSolution = [30, 10, 15] burnStepsSolution = [3, 5, 5] maxBurnStepsSolution = 5 def setUp(self): self.standaloneDetailedCS = Settings() self.standaloneDetailedCS.loadFromString(self.detailedCyclesSettings) self.detailedOperator = Operator(self.standaloneDetailedCS) def test_getPowerFractions(self): self.assertEqual(self.detailedOperator.powerFractions, self.powerFractionsSolution) self.detailedOperator._powerFractions = None self.assertEqual(self.detailedOperator.powerFractions, self.powerFractionsSolution) def test_getCycleNames(self): self.assertEqual(self.detailedOperator.cycleNames, self.cycleNamesSolution) self.detailedOperator._cycleNames = None self.assertEqual(self.detailedOperator.cycleNames, self.cycleNamesSolution) def test_getAvailabilityFactors(self): self.assertEqual( self.detailedOperator.availabilityFactors, self.availabilityFactorsSolution, ) self.detailedOperator._availabilityFactors = None self.assertEqual( self.detailedOperator.availabilityFactors, self.availabilityFactorsSolution, ) def test_getStepLengths(self): self.assertEqual(self.detailedOperator.stepLengths, self.stepLengthsSolution) self.detailedOperator._stepLength = None self.assertEqual(self.detailedOperator.stepLengths, self.stepLengthsSolution) def test_getCycleLengths(self): self.assertEqual(self.detailedOperator.cycleLengths, self.cycleLengthsSolution) self.detailedOperator._cycleLengths = None self.assertEqual(self.detailedOperator.cycleLengths, self.cycleLengthsSolution) def test_getBurnSteps(self): self.assertEqual(self.detailedOperator.burnSteps, self.burnStepsSolution) self.detailedOperator._burnSteps = None self.assertEqual(self.detailedOperator.burnSteps, self.burnStepsSolution) def test_getMaxBurnSteps(self): self.assertEqual(self.detailedOperator.maxBurnSteps, self.maxBurnStepsSolution) self.detailedOperator._maxBurnSteps = None self.assertEqual(self.detailedOperator.maxBurnSteps, self.maxBurnStepsSolution)
def setUp(self): self.standaloneDetailedCS = Settings() self.standaloneDetailedCS.loadFromString(self.detailedCyclesSettings) self.detailedOperator = Operator(self.standaloneDetailedCS)
def setUp(self): self.standaloneDetailedCS = Settings() self.standaloneDetailedCS.loadFromString(self.detailedCyclesSettings) self.standaloneSimpleCS = Settings() self.standaloneSimpleCS.loadFromString(self.simpleCyclesSettings)
class CyclesSettingsTests(unittest.TestCase): """ Check reading of the various cycle history settings for both the detailed and simple input options. """ detailedCyclesSettings = """ metadata: version: uncontrolled settings: power: 1000000000.0 nCycles: 3 cycles: - name: dog cumulative days: [1, 2, 3] power fractions: [0.1, 0.2, 0.3] availability factor: 0.1 - cycle length: 10 burn steps: 5 power fractions: [0.2, 0.2, 0.2, 0.2, 0] availability factor: 0.5 - name: ferret step days: [3, R4] power fractions: [0.3, R4] runType: Standard """ simpleCyclesSettings = """ metadata: version: uncontrolled settings: power: 1000000000.0 nCycles: 3 availabilityFactors: [0.1, R2] cycleLengths: [1, 2, 3] powerFractions: [0.1, 0.2, R1] burnSteps: 3 runType: Standard """ powerFractionsDetailedSolution = [ [0.1, 0.2, 0.3], [0.2, 0.2, 0.2, 0.2, 0], [0.3, 0.3, 0.3, 0.3, 0.3], ] powerFractionsSimpleSolution = [[0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.2, 0.2, 0.2]] cycleNamesDetailedSolution = ["dog", None, "ferret"] cycleNamesSimpleSolution = [None, None, None] availabilityFactorsDetailedSolution = [0.1, 0.5, 1] availabilityFactorsSimpleSolution = [0.1, 0.1, 0.1] stepLengthsDetailedSolution = [ [1, 1, 1], [10 / 5 * 0.5, 10 / 5 * 0.5, 10 / 5 * 0.5, 10 / 5 * 0.5, 10 / 5 * 0.5], [3, 3, 3, 3, 3], ] stepLengthsSimpleSolution = [ [1 * 0.1 / 3, 1 * 0.1 / 3, 1 * 0.1 / 3], [2 * 0.1 / 3, 2 * 0.1 / 3, 2 * 0.1 / 3], [3 * 0.1 / 3, 3 * 0.1 / 3, 3 * 0.1 / 3], ] cycleLengthsDetailedSolution = [30, 10, 15] cycleLengthsSimpleSolution = [1, 2, 3] burnStepsDetailedSolution = [3, 5, 5] burnStepsSimpleSolution = [3, 3, 3] nodesPerCycleDetailedSolution = [4, 6, 6] nodesPerCycleSimpleSolution = [4, 4, 4] maxBurnStepsDetailedSolution = 5 maxBurnStepsSimpleSolution = 3 def setUp(self): self.standaloneDetailedCS = Settings() self.standaloneDetailedCS.loadFromString(self.detailedCyclesSettings) self.standaloneSimpleCS = Settings() self.standaloneSimpleCS.loadFromString(self.simpleCyclesSettings) def test_getPowerFractions(self): self.assertEqual( getPowerFractions(self.standaloneDetailedCS), self.powerFractionsDetailedSolution, ) self.assertEqual( getPowerFractions(self.standaloneSimpleCS), self.powerFractionsSimpleSolution, ) def test_getCycleNames(self): self.assertEqual(getCycleNames(self.standaloneDetailedCS), self.cycleNamesDetailedSolution) self.assertEqual(getCycleNames(self.standaloneSimpleCS), self.cycleNamesSimpleSolution) def test_getAvailabilityFactors(self): self.assertEqual( getAvailabilityFactors(self.standaloneDetailedCS), self.availabilityFactorsDetailedSolution, ) self.assertEqual( getAvailabilityFactors(self.standaloneSimpleCS), self.availabilityFactorsSimpleSolution, ) def test_getStepLengths(self): self.assertEqual( getStepLengths(self.standaloneDetailedCS), self.stepLengthsDetailedSolution, ) self.assertEqual( getStepLengths(self.standaloneSimpleCS), self.stepLengthsSimpleSolution, ) def test_getCycleLengths(self): self.assertEqual( getCycleLengths(self.standaloneDetailedCS), self.cycleLengthsDetailedSolution, ) self.assertEqual(getCycleLengths(self.standaloneSimpleCS), self.cycleLengthsSimpleSolution) def test_getBurnSteps(self): self.assertEqual(getBurnSteps(self.standaloneDetailedCS), self.burnStepsDetailedSolution) self.assertEqual(getBurnSteps(self.standaloneSimpleCS), self.burnStepsSimpleSolution) def test_getMaxBurnSteps(self): self.assertEqual( getMaxBurnSteps(self.standaloneDetailedCS), self.maxBurnStepsDetailedSolution, ) self.assertEqual(getMaxBurnSteps(self.standaloneSimpleCS), self.maxBurnStepsSimpleSolution) def test_getNodesPerCycle(self): self.assertEqual( getNodesPerCycle(self.standaloneDetailedCS), self.nodesPerCycleDetailedSolution, ) self.assertEqual(getNodesPerCycle(self.standaloneSimpleCS), self.nodesPerCycleSimpleSolution) def test_getCycleNodeFromCumulativeStep(self): self.assertEqual( getCycleNodeFromCumulativeStep(8, self.standaloneDetailedCS), (1, 4)) self.assertEqual( getCycleNodeFromCumulativeStep(12, self.standaloneDetailedCS), (2, 3)) self.assertEqual( getCycleNodeFromCumulativeStep(4, self.standaloneSimpleCS), (1, 0)) self.assertEqual( getCycleNodeFromCumulativeStep(8, self.standaloneSimpleCS), (2, 1)) def test_getCycleNodeFromCumulativeNode(self): self.assertEqual( getCycleNodeFromCumulativeNode(8, self.standaloneDetailedCS), (1, 4)) self.assertEqual( getCycleNodeFromCumulativeNode(12, self.standaloneDetailedCS), (2, 2)) self.assertEqual( getCycleNodeFromCumulativeNode(3, self.standaloneSimpleCS), (0, 3)) self.assertEqual( getCycleNodeFromCumulativeNode(8, self.standaloneSimpleCS), (2, 0)) def test_getPreviousTimeNode(self): with self.assertRaises(ValueError): getPreviousTimeNode(0, 0, "foo") self.assertEqual(getPreviousTimeNode(1, 1, self.standaloneSimpleCS), (1, 0)) self.assertEqual(getPreviousTimeNode(1, 0, self.standaloneSimpleCS), (0, 3)) self.assertEqual(getPreviousTimeNode(1, 0, self.standaloneDetailedCS), (0, 3)) self.assertEqual(getPreviousTimeNode(2, 4, self.standaloneDetailedCS), (2, 3)) def test_getCumulativeNodeNum(self): self.assertEqual(getCumulativeNodeNum(2, 0, self.standaloneSimpleCS), 8) self.assertEqual(getCumulativeNodeNum(1, 2, self.standaloneSimpleCS), 6) self.assertEqual(getCumulativeNodeNum(2, 0, self.standaloneDetailedCS), 10) self.assertEqual(getCumulativeNodeNum(1, 0, self.standaloneDetailedCS), 4)