diff --git a/openmc/cell.py b/openmc/cell.py index ba7a41435..522f9ab5d 100644 --- a/openmc/cell.py +++ b/openmc/cell.py @@ -1,4 +1,5 @@ from collections import OrderedDict, Iterable +from copy import deepcopy from math import cos, sin, pi from numbers import Real, Integral from xml.etree import ElementTree as ET @@ -508,7 +509,7 @@ class Cell(object): """Create a copy of this cell with a new unique ID, and clones the cell's region and fill.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None if self.region is not None: diff --git a/openmc/lattice.py b/openmc/lattice.py index 9f3f30385..b98ef0087 100644 --- a/openmc/lattice.py +++ b/openmc/lattice.py @@ -2,6 +2,7 @@ from __future__ import division from abc import ABCMeta from collections import OrderedDict, Iterable +from copy import deepcopy from math import sqrt, floor from numbers import Real, Integral from xml.etree import ElementTree as ET @@ -418,7 +419,7 @@ class Lattice(object): """Create a copy of this lattice with a new unique ID, and clones all universes within this lattice.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None # Clone all unique universes in the lattice @@ -427,9 +428,17 @@ class Lattice(object): 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] + for i in self.indices: + if isinstance(self, RectLattice): + univ_id = self.universes[i].id + clone.universes[i] = univ_clones[univ_id] + else: + if self.ndim == 2: + univ_id = self.universes[i[0]][i[1]].id + clone.universes[i[0]][i[1]] = univ_clones[univ_id] + else: + univ_id = self.universes[i[0]][i[1]][i[2]].id + clone.universes[i[0]][i[1]][i[2]] = univ_clones[univ_id] return clone diff --git a/openmc/material.py b/openmc/material.py index cb1482b8e..be13d619f 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -799,6 +799,13 @@ class Material(object): return nuclides + def clone(self): + """Create a copy of this material with a new unique ID.""" + + clone = deepcopy(self) + clone.id = None + return clone + def _get_nuclide_xml(self, nuclide, distrib=False): xml_element = ET.Element("nuclide") xml_element.set("name", nuclide[0].name) @@ -1100,13 +1107,6 @@ 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)) diff --git a/openmc/region.py b/openmc/region.py index 1ac4d8c94..b93d305fe 100644 --- a/openmc/region.py +++ b/openmc/region.py @@ -1,5 +1,6 @@ from abc import ABCMeta, abstractmethod from collections import Iterable, OrderedDict +from copy import deepcopy from six import add_metaclass import numpy as np @@ -306,12 +307,11 @@ 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 = deepcopy(self) clone.nodes = [n.clone() for n in self.nodes] return clone diff --git a/openmc/surface.py b/openmc/surface.py index b0aa250c0..866a9e2b9 100644 --- a/openmc/surface.py +++ b/openmc/surface.py @@ -1,5 +1,6 @@ from abc import ABCMeta from collections import Iterable, OrderedDict +from copy import deepcopy from numbers import Real, Integral from xml.etree import ElementTree as ET from math import sqrt @@ -174,7 +175,7 @@ class Surface(object): def clone(self): """Create a copy of this surface with a new unique ID.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None return clone @@ -1828,15 +1829,6 @@ class Halfspace(Region): def __init__(self, surface, side): 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): @@ -1918,6 +1910,14 @@ class Halfspace(Region): surfaces[self.surface.id] = self.surface return surfaces + def clone(self): + """Create a copy of this halfspace, with a cloned surface with a + unique ID.""" + + clone = deepcopy(self) + clone.surface = self.surface.clone() + return clone + def get_rectangular_prism(width, height, axis='z', origin=(0., 0.), boundary_type='transmission'): diff --git a/openmc/universe.py b/openmc/universe.py index 0f5e2da14..a2157f1d7 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -1,6 +1,6 @@ from __future__ import division -from copy import copy from collections import OrderedDict, Iterable +from copy import copy, deepcopy from numbers import Integral, Real import random import sys @@ -521,7 +521,7 @@ class Universe(object): """Create a copy of this universe with a new unique ID, and clones all cells within this universe.""" - clone = copy.deepcopy(self) + clone = deepcopy(self) clone.id = None # Clone all cells for the universe clone