mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Merge pull request #2200 from shimwell/adding_element_filter_to_get_nuclides_without_sorting
added element filter to get_nuclide
This commit is contained in:
commit
28a945f6ca
2 changed files with 38 additions and 4 deletions
|
|
@ -795,16 +795,33 @@ class Material(IDManagerMixin):
|
|||
|
||||
return sorted({re.split(r'(\d+)', i)[0] for i in self.get_nuclides()})
|
||||
|
||||
def get_nuclides(self):
|
||||
"""Returns all nuclides in the material
|
||||
def get_nuclides(self, element: Optional[str] = None):
|
||||
"""Returns a list of all nuclides in the material, if the element
|
||||
argument is specified then just nuclides of that element are returned.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
element : str
|
||||
Specifies the element to match when searching through the nuclides
|
||||
|
||||
Returns
|
||||
-------
|
||||
nuclides : list of str
|
||||
List of nuclide names
|
||||
|
||||
"""
|
||||
return [x.name for x in self._nuclides]
|
||||
|
||||
matching_nuclides = []
|
||||
if element:
|
||||
for nuclide in self._nuclides:
|
||||
if re.split(r'(\d+)', nuclide.name)[0] == element:
|
||||
if nuclide.name not in matching_nuclides:
|
||||
matching_nuclides.append(nuclide.name)
|
||||
else:
|
||||
for nuclide in self._nuclides:
|
||||
if nuclide.name not in matching_nuclides:
|
||||
matching_nuclides.append(nuclide.name)
|
||||
|
||||
return matching_nuclides
|
||||
|
||||
def get_nuclide_densities(self):
|
||||
"""Returns all nuclides in the material and their densities
|
||||
|
|
|
|||
|
|
@ -299,6 +299,23 @@ def test_isotropic():
|
|||
assert m2.isotropic == ['H1']
|
||||
|
||||
|
||||
def test_get_nuclides():
|
||||
mat = openmc.Material()
|
||||
|
||||
mat.add_nuclide('Li6', 1.0)
|
||||
assert mat.get_nuclides() == ['Li6']
|
||||
assert mat.get_nuclides(element='Li') == ['Li6']
|
||||
assert mat.get_nuclides(element='Be') == []
|
||||
|
||||
mat.add_element('Li', 1.0)
|
||||
assert mat.get_nuclides() == ['Li6', 'Li7']
|
||||
assert mat.get_nuclides(element='Be') == []
|
||||
|
||||
mat.add_element('Be', 1.0)
|
||||
assert mat.get_nuclides() == ['Li6', 'Li7', 'Be9']
|
||||
assert mat.get_nuclides(element='Be') == ['Be9']
|
||||
|
||||
|
||||
def test_get_elements():
|
||||
# test that zero elements exist on creation
|
||||
m = openmc.Material()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue