mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
First stab at implementing clone() methods for geometric and material primitives
This commit is contained in:
parent
e9dfad8519
commit
06a918c1b5
6 changed files with 101 additions and 0 deletions
|
|
@ -504,6 +504,20 @@ class Cell(object):
|
|||
|
||||
return universes
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this cell with a new unique ID, and clones
|
||||
the cell's region and fill."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
if self.region is not None:
|
||||
clone.region = self.region.clone()
|
||||
if self.fill is not None:
|
||||
clone.fill = self.fill.clone()
|
||||
|
||||
return clone
|
||||
|
||||
def create_xml_subelement(self, xml_element):
|
||||
element = ET.Element("cell")
|
||||
element.set("id", str(self.id))
|
||||
|
|
|
|||
|
|
@ -414,6 +414,25 @@ class Lattice(object):
|
|||
return []
|
||||
return [(self, idx)] + u.find(p)
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this lattice with a new unique ID, and clones
|
||||
all universes within this lattice."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
# Clone all unique universes in the lattice
|
||||
univ_clones = self.get_unique_universes()
|
||||
for univ_id in univ_clones:
|
||||
univ_clones[univ_id] = univ_clones[univ_id].clone()
|
||||
|
||||
# Assign universe clones to the lattice clone
|
||||
for index in self.indices:
|
||||
univ_id = self.universe[index].id
|
||||
clone.universes[index] = univ_clones[univ_id]
|
||||
|
||||
return clone
|
||||
|
||||
|
||||
class RectLattice(Lattice):
|
||||
"""A lattice consisting of rectangular prisms.
|
||||
|
|
|
|||
|
|
@ -1100,6 +1100,13 @@ class Materials(cv.CheckedList):
|
|||
for material in self:
|
||||
material.make_isotropic_in_lab()
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this material with a new unique ID."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.id = None
|
||||
return clone
|
||||
|
||||
def _create_material_subelements(self, root_element):
|
||||
for material in self:
|
||||
root_element.append(material.to_xml_element(self.cross_sections))
|
||||
|
|
|
|||
|
|
@ -221,6 +221,12 @@ class Region(object):
|
|||
# at the end
|
||||
return output[0]
|
||||
|
||||
@abstractmethod
|
||||
def clone(self):
|
||||
"""Create a copy of this region - each of the surfaces in the
|
||||
region's nodes will be cloned and will have new unique IDs."""
|
||||
return False
|
||||
|
||||
|
||||
class Intersection(Region):
|
||||
r"""Intersection of two or more regions.
|
||||
|
|
@ -300,6 +306,15 @@ class Intersection(Region):
|
|||
check_type('nodes', nodes, Iterable, Region)
|
||||
self._nodes = nodes
|
||||
|
||||
@abstractmethod
|
||||
def clone(self):
|
||||
"""Create a copy of this region - each of the surfaces in the
|
||||
intersection's nodes will be cloned and will have new unique IDs."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.nodes = [n.clone() for n in self.nodes]
|
||||
return clone
|
||||
|
||||
|
||||
class Union(Region):
|
||||
r"""Union of two or more regions.
|
||||
|
|
@ -377,6 +392,14 @@ class Union(Region):
|
|||
check_type('nodes', nodes, Iterable, Region)
|
||||
self._nodes = nodes
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this region - each of the surfaces in the
|
||||
union's nodes will be cloned and will have new unique IDs."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.nodes = [n.clone() for n in self.nodes]
|
||||
return clone
|
||||
|
||||
|
||||
class Complement(Region):
|
||||
"""Complement of a region.
|
||||
|
|
@ -473,3 +496,11 @@ class Complement(Region):
|
|||
for region in self.node:
|
||||
surfaces = region.get_surfaces(surfaces)
|
||||
return surfaces
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this region - each of the surfaces in the
|
||||
complement's node will be cloned and will have new unique IDs."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.node = self.node.clone()
|
||||
return clone
|
||||
|
|
|
|||
|
|
@ -171,6 +171,13 @@ class Surface(object):
|
|||
return (np.array([-np.inf, -np.inf, -np.inf]),
|
||||
np.array([np.inf, np.inf, np.inf]))
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this surface with a new unique ID."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.id = None
|
||||
return clone
|
||||
|
||||
def to_xml_element(self):
|
||||
"""Return XML representation of the surface
|
||||
|
||||
|
|
@ -1822,6 +1829,15 @@ class Halfspace(Region):
|
|||
self.surface = surface
|
||||
self.side = side
|
||||
|
||||
@abstractmethod
|
||||
def clone(self):
|
||||
"""Create a copy of this halfspace, with a cloned surface with a
|
||||
unique ID."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.surface = self.surface.clone()
|
||||
return clone
|
||||
|
||||
def __and__(self, other):
|
||||
if isinstance(other, Intersection):
|
||||
return Intersection(self, *other.nodes)
|
||||
|
|
|
|||
|
|
@ -517,6 +517,20 @@ class Universe(object):
|
|||
|
||||
return universes
|
||||
|
||||
def clone(self):
|
||||
"""Create a copy of this universe with a new unique ID, and clones
|
||||
all cells within this universe."""
|
||||
|
||||
clone = copy.deepcopy(self)
|
||||
clone.id = None
|
||||
|
||||
# Clone all cells for the universe clone
|
||||
clone._cells = OrderedDict()
|
||||
for cell in self._cells.values():
|
||||
clone.add_cell(cell.clone())
|
||||
|
||||
return clone
|
||||
|
||||
def create_xml_subelement(self, xml_element):
|
||||
# Iterate over all Cells
|
||||
for cell_id, cell in self._cells.items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue