def test_setDefaultSettingsByLowestBuGroupOneDimensional(self): # Initialize some micro suffix in the cross sections cs = settings.Settings() xsModel = XSSettings() rq = XSModelingOptions( "RQ", geometry="1D cylinder", blockRepresentation="Average", meshSubdivisionsPerCm=1.0, ) xsModel["RQ"] = rq xsModel.setDefaults(cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) # Check that new micro suffix `RY` with higher burn-up group gets assigned the same settings as `RQ` self.assertNotIn("RY", xsModel) self.assertEqual(xsModel["RY"], xsModel["RQ"]) # Check that new micro suffix `RZ` with higher burn-up group gets assigned the same settings as `RQ` self.assertNotIn("RZ", xsModel) self.assertEqual(xsModel["RZ"], xsModel["RQ"]) # Check that new micro suffix `RA` with lower burn-up group does NOT get assigned the same settings as `RQ` self.assertNotIn("RA", xsModel) self.assertNotEqual(xsModel["RA"], xsModel["RQ"])
def test_pregeneratedCrossSections(self): xs = XSSettings() xa = XSModelingOptions("XA", fileLocation=["ISOXA"]) xs["XA"] = xa self.assertEqual(["ISOXA"], xa.fileLocation) self.assertNotIn("XB", xs) xs.setDefaults(settings.Settings()) # Check that the file location of 'XB' still points to the same file location as 'XA'. self.assertEqual(xa, xs["XB"])
def test_optionalKey(self): """Test that optional key shows up with default value.""" xsModel = XSSettings() da = XSModelingOptions("DA", geometry="1D slab", meshSubdivisionsPerCm=1.0) xsModel["DA"] = da xsModel.setDefaults(settings.Settings()) self.assertEqual(xsModel["DA"].mergeIntoClad, []) self.assertEqual(xsModel["DA"].criticalBuckling, False)
def test_pregeneratedCrossSections(self): cs = settings.Settings() xs = XSSettings() xa = XSModelingOptions("XA", fileLocation=["ISOXA"]) xs["XA"] = xa self.assertEqual(["ISOXA"], xa.fileLocation) self.assertNotIn("XB", xs) xs.setDefaults(cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) # Check that the file location of 'XB' still points to the same file location as 'XA'. self.assertEqual(xa, xs["XB"])
def test_homogeneousXsDefaultSettingAssignment(self): """ Make sure the object can whip up an unspecified xsID by default. This is used when user hasn't specified anything. """ xsModel = XSSettings() xsModel.setDefaults(settings.Settings()) self.assertNotIn("YA", xsModel) self.assertEqual(xsModel["YA"].geometry, "0D") self.assertEqual(xsModel["YA"].criticalBuckling, True)
def test_optionalKey(self): """Test that optional key shows up with default value.""" cs = settings.Settings() xsModel = XSSettings() da = XSModelingOptions("DA", geometry="1D cylinder", meshSubdivisionsPerCm=1.0) xsModel["DA"] = da xsModel.setDefaults(cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) self.assertEqual(xsModel["DA"].mergeIntoClad, ["gap"]) self.assertEqual(xsModel["DA"].meshSubdivisionsPerCm, 1.0)
def test_homogeneousXsDefaultSettingAssignment(self): """ Make sure the object can whip up an unspecified xsID by default. This is used when user hasn't specified anything. """ cs = settings.Settings() xsModel = XSSettings() xsModel.setDefaults(cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) self.assertNotIn("YA", xsModel) self.assertEqual(xsModel["YA"].geometry, "0D") self.assertEqual(xsModel["YA"].criticalBuckling, True)
def test_csBlockRepresentationFileLocation(self): """ Test that default blockRepresentation is applied correctly to a XSModelingOption that has the ``fileLocation`` attribute defined. """ cs = caseSettings.Settings() cs["xsBlockRepresentation"] = "FluxWeightedAverage" cs[CONF_CROSS_SECTION] = XSSettings() cs[CONF_CROSS_SECTION]["AA"] = XSModelingOptions("AA", fileLocation=[]) # Check FluxWeightedAverage cs[CONF_CROSS_SECTION].setDefaults( cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) self.assertEqual(cs[CONF_CROSS_SECTION]["AA"].blockRepresentation, "FluxWeightedAverage") # Check Average cs["xsBlockRepresentation"] = "Average" cs[CONF_CROSS_SECTION]["AA"] = XSModelingOptions("AA", fileLocation=[]) cs[CONF_CROSS_SECTION].setDefaults( cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) self.assertEqual(cs[CONF_CROSS_SECTION]["AA"].blockRepresentation, "Average") # Check Median cs["xsBlockRepresentation"] = "Average" cs[CONF_CROSS_SECTION]["AA"] = XSModelingOptions( "AA", fileLocation=[], blockRepresentation="Median") cs[CONF_CROSS_SECTION].setDefaults( cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) self.assertEqual(cs[CONF_CROSS_SECTION]["AA"].blockRepresentation, "Median")
def test_csBlockRepresentation(self): """ Test that the XS block representation is applied globally, but only to XS modeling options where the blockRepresentation has not already been assigned. """ cs = caseSettings.Settings() cs["xsBlockRepresentation"] = "FluxWeightedAverage" cs[CONF_CROSS_SECTION] = XSSettings() cs[CONF_CROSS_SECTION]["AA"] = XSModelingOptions("AA", geometry="0D") cs[CONF_CROSS_SECTION]["BA"] = XSModelingOptions( "BA", geometry="0D", blockRepresentation="Average") self.assertEqual(cs[CONF_CROSS_SECTION]["AA"].blockRepresentation, None) self.assertEqual(cs[CONF_CROSS_SECTION]["BA"].blockRepresentation, "Average") cs[CONF_CROSS_SECTION].setDefaults( cs["xsBlockRepresentation"], cs["disableBlockTypeExclusionInXsGeneration"]) self.assertEqual(cs[CONF_CROSS_SECTION]["AA"].blockRepresentation, "FluxWeightedAverage") self.assertEqual(cs[CONF_CROSS_SECTION]["BA"].blockRepresentation, "Average")
def _setInitialXSSettings(): cs = caseSettings.Settings() cs[CONF_CROSS_SECTION] = XSSettings() cs[CONF_CROSS_SECTION]["AA"] = XSModelingOptions("AA", geometry="0D") cs[CONF_CROSS_SECTION]["BA"] = XSModelingOptions("BA", geometry="0D") self.assertIn("AA", cs[CONF_CROSS_SECTION]) self.assertIn("BA", cs[CONF_CROSS_SECTION]) self.assertNotIn("CA", cs[CONF_CROSS_SECTION]) self.assertNotIn("DA", cs[CONF_CROSS_SECTION]) return cs
def test_setDefaultSettingsByLowestBuGroupHomogeneous(self): # Initialize some micro suffix in the cross sections xs = XSSettings() jd = XSModelingOptions("JD", geometry="0D", criticalBuckling=False) xs["JD"] = jd xs.setDefaults(settings.Settings()) self.assertIn("JD", xs) # Check that new micro suffix `JF` with higher burn-up group gets assigned the same settings as `JD` self.assertNotIn("JF", xs) self.assertEqual(xs["JD"], xs["JF"]) self.assertNotIn("JF", xs) # Check that new micro suffix `JG` with higher burn-up group gets assigned the same settings as `JD` self.assertNotIn("JG", xs) self.assertEqual(xs["JG"], xs["JD"]) # Check that new micro suffix `JB` with lower burn-up group does NOT get assigned the same settings as `JD` self.assertNotIn("JB", xs) self.assertNotEqual(xs["JD"], xs["JB"])
def test_yamlIO(self): """Ensure we can read/write this custom setting object to yaml""" yaml = YAML() inp = yaml.load(io.StringIO(XS_EXAMPLE)) xs = XSSettingDef("TestSetting", XSSettings()) xs._load(inp) # pylint: disable=protected-access self.assertEqual(xs.value["BA"].geometry, "1D slab") outBuf = io.StringIO() output = xs.dump() yaml.dump(output, outBuf) outBuf.seek(0) inp2 = yaml.load(outBuf) self.assertEqual(inp.keys(), inp2.keys())