added remove element to material

This commit is contained in:
Jonathan Shimwell 2022-06-22 08:19:00 +01:00
parent acd6c567c3
commit 9b36424e16
2 changed files with 18 additions and 1 deletions

View file

@ -407,6 +407,23 @@ class Material(IDManagerMixin):
if nuclide == nuc.name:
self.nuclides.remove(nuc)
def remove_element(self, element):
"""Remove an element from the material
Parameters
----------
element : str
Element to remove
"""
cv.check_type('element', element, str)
# If the Material contains the element, delete it
for nuc in reversed(self.nuclides):
element_name = re.split(r'(\d+)', nuc)
if nuc == element_name:
self.nuclides.remove(nuc)
def add_macroscopic(self, macroscopic):
"""Add a macroscopic to the material. This will also set the
density of the material to 1.0, unless it has been otherwise set,

View file

@ -43,7 +43,7 @@ def test_remove_elements():
m = openmc.Material()
for elem, percent in [('Li', 1.0), ('Be', 1.0)]:
m.add_element(elem, percent)
m.remove_nuclide('Li')
m.remove_element('Li')
assert len(m.nuclides) == 1
assert m.nuclides == ['Be9']
assert m.nuclides[0].percent == 1.0