def setUp(self): self.suite = cases.CaseSuite(settings.Settings()) geom = systemLayoutInput.SystemLayoutInput() geom.readGeomFromStream(io.StringIO(GEOM_INPUT)) bp = blueprints.Blueprints.load(BLUEPRINT_INPUT) self.c1 = cases.Case(cs=settings.Settings(), geom=geom, bp=bp) self.c1.cs.path = "c1.yaml" self.suite.add(self.c1) self.c2 = cases.Case(cs=settings.Settings(), geom=geom, bp=bp) self.c2.cs.path = "c2.yaml" self.suite.add(self.c2)
def setUpClass(cls): geom = systemLayoutInput.SystemLayoutInput() geom.readGeomFromStream(GEOM_INPUT) bp = blueprints.Blueprints.load(BLUEPRINT_INPUT_LINKS) cs = settings.Settings() bp._prepConstruction(cs) cls.baseCase = cases.Case(cs=cs, bp=bp, geom=geom)
def test_writeInput(self): fName = os.path.join(TEST_ROOT, "armiRun.yaml") cs = settings.Settings(fName) baseCase = cases.Case(cs) with directoryChangers.TemporaryDirectoryChanger(): case = baseCase.clone() case.writeInputs() self.assertTrue(os.path.exists(cs["shuffleLogic"]))
def test_independentVariables(self): """Ensure that independentVariables added to a case move with it.""" geom = systemLayoutInput.SystemLayoutInput() geom.readGeomFromStream(io.StringIO(GEOM_INPUT)) bp = blueprints.Blueprints.load(BLUEPRINT_INPUT) cs = settings.Settings(ARMI_RUN_PATH) cs["verbosity"] = "important" baseCase = cases.Case(cs, bp=bp, geom=geom) with directoryChangers.TemporaryDirectoryChanger() as cwd: # ensure we are not in IN_USE_TEST_ROOT vals = {"cladThickness": 1, "control strat": "good", "enrich": 0.9} case = baseCase.clone() case._independentVariables = vals # pylint: disable=protected-access case.writeInputs() newCs = settings.Settings(fName=case.title + ".yaml") newCase = cases.Case(newCs) for name, val in vals.items(): self.assertEqual(newCase.independentVariables[name], val)
def test_fullCoreConversion(self): cs = settings.Settings( os.path.join(test_reactors.TEST_ROOT, "armiRun.yaml")) case = cases.Case(cs=cs) mod = inputModifiers.FullCoreModifier() self.assertEqual(case.bp.gridDesigns["core"].symmetry, "third periodic") mod(case, case.bp, None) self.assertEqual(case.bp.gridDesigns["core"].symmetry, "full")
def test_summarizeDesign(self): """ Ensure that the summarizeDesign method runs. Any assertions are bonus. """ with directoryChangers.TemporaryDirectoryChanger(): # ensure we are not in IN_USE_TEST_ROOT cs = settings.Settings(ARMI_RUN_PATH) cs["verbosity"] = "important" case = cases.Case(cs) c2 = case.clone() c2.summarizeDesign(True, True) self.assertTrue(os.path.exists("Core Design Report.html"))
def test_summarizeDesign(self): """ Ensure that the summarizeDesign method runs. Any assertions are bonus. """ with directoryChangers.TemporaryDirectoryChanger( ): # ensure we are not in IN_USE_TEST_ROOT cs = settings.Settings(ARMI_RUN_PATH) cs = cs.modified(newSettings={"verbosity": "important"}) case = cases.Case(cs) c2 = case.clone() c2.summarizeDesign(True, True) self.assertTrue( os.path.exists( os.path.join("{}-reports".format(c2.cs.caseTitle), "index.html")))
def buildCase(): """Build input components and a case.""" bp = blueprints.Blueprints() bp.customIsotopics = isotopicOptions.CustomIsotopics() bp.nuclideFlags = isotopicOptions.genDefaultNucFlags() components = buildComponents() bp.blockDesigns = buildBlocks(components) bp.assemDesigns = buildAssemblies(bp.blockDesigns) bp.gridDesigns = buildGrids() bp.systemDesigns = buildSystems() cs = caseSettings.Settings() cs.path = None cs.caseTitle = "scripted-case" case = cases.Case(cs=cs, bp=bp) return case
def init(choice=None, fName=None, cs=None): """ Scan a directory for armi inputs and load one to interact with. Parameters ---------- choice : int, optional Automatically run with this item out of the menu that would be produced of existing xml files. fName : str, optional An actual case name to load. e.g. ntTwr1.xml cs : object, optional If supplied, supercede the other case input methods and use the object directly Examples -------- >>> o = armi.init() """ from armi import cases from armi import settings if cs is None: if fName is None: fName = settings.promptForSettingsFile(choice) cs = settings.Settings(fName) # clear out any old masterCs objects settings.setMasterCs(cs) armiCase = cases.Case(cs=cs) armiCase.checkInputs() try: return armiCase.initializeOperator() except: # Catch any and all errors. Naked exception on purpose. # Concatenate errors to the master log file. runLog.LOG.close() raise
def loadOperator(pathToDb, loadCycle, loadNode): """ Return an operator given the path to a database. Parameters ---------- pathToDb : str The path of the database to load from. loadCycle : int The cycle to load the reactor state from. loadNode : int The time node to load the reactor from. See Also -------- armi.operator.Operator.loadState: A method for loading reactor state that is useful if you already have an operator and a reactor object. loadOperator varies in that it supplies these given only a database file. loadState should be used if you are in the middle of an ARMI calculation and need load a different time step. Notes ----- The operator will have a reactor attached that is loaded to the specified cycle and node. The operator will not be in the same state that it was at that cycle and node, only the reactor. Examples -------- >>> o = db.loadOperator(r"pathToDatabase", 0, 1) >>> r = o.r >>> cs = o.cs >>> r.p.timeNode 1 >>> r.getFPMass() # Note since it is loaded from step 1 there are fission products. 12345.67 """ # `import armi` doesn't work if imported at top from armi import cases from armi import settings if not os.path.exists(pathToDb): raise ValueError( f"Specified database at path {pathToDb} does not exist. \n\n" "Double check that escape characters were correctly processed.\n" "Consider sending the full path, or change directory to be the directory " "of the database." ) db = Database3(pathToDb, "r") with db: # init Case here as it keeps track of execution time and assigns a reactor # attribute. This attribute includes the time it takes to initialize the reactor # so creating a reactor from the database should be included. cs = db.loadCS() thisCase = cases.Case(cs) r = db.load(loadCycle, loadNode) settings.setMasterCs(cs) # Update the global assembly number because, if the user is loading a reactor from # blueprints and does not have access to an operator, it is unlikely that there is # another reactor that has alter the global assem num. Fresh cases typically want # this updated. database3.updateGlobalAssemblyNum(r) o = thisCase.initializeOperator(r=r) runLog.warning( "The operator provided is not in the same state as the operator was.\n" "When the reactor was at the prescribed cycle and node, it should have\n" "access to the same interface stack, but the interfaces will also not be in the " "same state.\n" "ARMI does not support loading operator states, as they are not stored." ) return o
def invoke(self): # get the case title. from armi import cases inputCase = cases.Case(cs=self.cs) inputCase.clone(additionalFiles=self.args.additional_files)
def invoke(self): from armi import cases inputCase = cases.Case(cs=self.cs) inputCase.run()
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Unit tests for the SuiteBuilder """ import unittest from armi.cases.inputModifiers.inputModifiers import SamplingInputModifier from armi import cases, settings from armi.cases.suiteBuilder import LatinHyperCubeSuiteBuilder cs = settings.Settings("armi/tests/tutorials/anl-afci-177.yaml") case = cases.Case(cs) class LatinHyperCubeModifier(SamplingInputModifier): def __init__(self, name, paramType: str, bounds: list, independentVariable=None): super().__init__( name, paramType, bounds, independentVariable=independentVariable ) self.value = None def __call__(self, cs, bp, geom): cs = cs.modified(newSettings={self.name: self.value}) return cs, bp, geom class TestLatinHyperCubeSuiteBuilder(unittest.TestCase):
def _execute(self): # pylint: disable=import-outside-toplevel; need to be configured first from armi import cases from armi.cases import suiteBuilder from armi.cases.inputModifiers.inputModifiers import ( SettingsModifier, MultiSettingModifier, FullCoreModifier, ) self._updateSettings() bp = self._updateBlueprints() baseCase = cases.Case(cs=self.cs, bp=bp) builder = suiteBuilder.FullFactorialSuiteBuilder(baseCase) problemTypes = [ SettingsModifier(CONF_NEUTRONICS_KERNEL, "DIF3D-Nodal"), SettingsModifier(CONF_NEUTRONICS_KERNEL, "DIF3D-FD"), MultiSettingModifier( { CONF_NEUTRONICS_KERNEL: "VARIANT", CONF_VARIANT_TRANSPORT_AND_SCATTER_ORDER: "P1P0", } ), ] builder.addDegreeOfFreedom(problemTypes) solutionTypes = [ SettingsModifier(CONF_NEUTRONICS_TYPE, "real"), # turn off coarse mesh rebalancing in all adjoint cases so they converge. MultiSettingModifier( {CONF_NEUTRONICS_TYPE: "adjoint", CONF_COARSE_MESH_REBALANCE: -1} ), MultiSettingModifier( {CONF_NEUTRONICS_TYPE: "both", CONF_COARSE_MESH_REBALANCE: -1} ), ] builder.addDegreeOfFreedom(solutionTypes) # add a higher-order VARIANT case as well. # note that you can't do scattering order beyond P1 with Dragon-produced XS builder.addModiferSet( [ MultiSettingModifier( { CONF_NEUTRONICS_KERNEL: "VARIANT", CONF_VARIANT_TRANSPORT_AND_SCATTER_ORDER: "P3P1", } ), ] ) # need full core too builder.addModiferSet( [ FullCoreModifier(), ] ) def namingFunc(index, case, _mods): number = f"{index:0>4}" name = ( f"{case.cs[CONF_NEUTRONICS_KERNEL]}-" f"{case.cs[CONF_NEUTRONICS_TYPE]}-" f"{case.bp.gridDesigns['core'].symmetry}" ) return os.path.join( ".", "case-suite", f"{number}-{name}", f"{baseCase.title}-{number}", )