def _expandElementMassFracs(self): """ Expand the custom isotopics input entries that are elementals to isotopics. This is necessary when the element name is not a elemental nuclide. Most everywhere else expects Nuclide objects (or nuclide names). This input allows a user to enter "U" which would expand to the naturally occurring uranium isotopics. This is different than the isotopic expansion done for meeting user-specified modeling options (such as an MC**2, or MCNP expecting elements or isotopes), because it translates the user input into something that can be used later on. """ elementsToExpand = [] for nucName in self.massFracs: if nucName not in nuclideBases.byName: element = elements.bySymbol.get(nucName) if element is not None: runLog.info( "Expanding custom isotopic `{}` element `{}` to natural isotopics" .format(self.name, nucName)) # include all natural isotopes with None flag elementsToExpand.append((element, None)) else: raise exceptions.InputError( "Unrecognized nuclide/isotope/element in input: {}". format(nucName)) densityTools.expandElementalMassFracsToNuclides( self.massFracs, elementsToExpand)
def expandElementals(mat, blueprint): """ Expand elements to isotopics during material construction. Does so as required by modeling options or user input. See Also -------- armi.reactor.blueprints.Blueprints._resolveNuclides Sets the metadata defining this behavior. """ elementExpansionPairs = [] for elementToExpand in blueprint.elementsToExpand: if elementToExpand.symbol not in mat.p.massFrac: continue nucFlags = blueprint.nuclideFlags.get(elementToExpand.symbol) nuclidesToBecome = ( [nuclideBases.byName[nn] for nn in nucFlags.expandTo] if (nucFlags and nucFlags.expandTo) else None ) elementExpansionPairs.append((elementToExpand, nuclidesToBecome)) densityTools.expandElementalMassFracsToNuclides( mat.p.massFrac, elementExpansionPairs )
def _constructMaterial(self, blueprint, matMods): nucsInProblem = blueprint.allNuclidesInProblem mat = materials.resolveMaterialClassByName( self.material)() # make material with defaults if self.isotopics is not None: blueprint.customIsotopics.apply(mat, self.isotopics) appliedMatMods = False if any(matMods): try: mat.applyInputParams( **matMods ) # update material with updated input params from YAML file. appliedMatMods = True except TypeError: # This component does not accept material modification inputs of the names passed in # Keep going since the modification could work for another component pass # expand elementals densityTools.expandElementalMassFracsToNuclides( mat.p.massFrac, blueprint.elementsToExpand) missing = set(mat.p.massFrac.keys()).difference(nucsInProblem) if missing: raise exceptions.ConsistencyError( "The nuclides {} are present in material {} by compositions, but are not " "specified in the input file. They need to be added.".format( missing, mat)) return mat, appliedMatMods
def test_expandElementalMassFracsToNuclides(self): element = elements.bySymbol["N"] mass = {"N": 1.0} densityTools.expandElementalMassFracsToNuclides(mass, [element]) self.assertNotIn("N", mass) self.assertIn("N15", mass) self.assertIn("N14", mass) self.assertAlmostEqual(sum(mass.values()), 1.0) self.assertNotIn("N13", mass) # nothing unnatural.
def setDefaultMassFracs(self): massFrac = {"H": 2.0 / 3.0, "O": 1.0 / 3.0} elements = [ nuclideBases.elements.bySymbol["H"], nuclideBases.elements.bySymbol["O"], ] densityTools.expandElementalMassFracsToNuclides(massFrac, elements) for nucName, mfrac in massFrac.items(): self.setMassFrac(nucName, mfrac)
def test_expandElementalZeroMassFrac(self): """As above, but try with a zero mass frac elemental.""" elementals = [elements.bySymbol["N"], elements.bySymbol["O"]] mass = {"N": 0.0, "O": 1.0} densityTools.expandElementalMassFracsToNuclides(mass, elementals) self.assertNotIn("N", mass) self.assertNotIn("O", mass) # Current expectation is for elements with zero mass fraction get expanded and # isotopes with zero mass remain in the dictionary. self.assertIn("N14", mass) self.assertAlmostEqual(sum(mass.values()), 1.0)