remove cell deepcopying for creating a fresh instance

This commit is contained in:
josh 2023-01-04 03:31:07 +00:00
parent 3f8f8f6701
commit ac2ba93b3a
2 changed files with 38 additions and 3 deletions

View file

@ -1,6 +1,5 @@
from collections import OrderedDict
from collections.abc import Iterable
from copy import deepcopy
from math import cos, sin, pi
from numbers import Real
from xml.etree import ElementTree as ET
@ -519,8 +518,14 @@ class Cell(IDManagerMixin):
paths = self._paths
self._paths = None
clone = deepcopy(self)
clone.id = None
clone = openmc.Cell()
clone.name = self.name
clone.temperature = self.temperature
clone.volume = self.volume
if self.translation is not None:
clone.translation = self.translation
if self.rotation is not None:
clone.rotation = self.rotation
clone._num_instances = None
# Restore paths on original instance

View file

@ -58,24 +58,54 @@ def test_clone():
cyl = openmc.ZCylinder()
c = openmc.Cell(fill=m, region=-cyl)
c.temperature = 650.
c.translation = (1,2,3)
c.rotation = (4,5,6)
c.volume = 100
c2 = c.clone()
assert c2.id != c.id
assert c2.fill != c.fill
assert c2.region != c.region
assert c2.temperature == c.temperature
assert all(c2.translation == c.translation)
assert all(c2.rotation == c.rotation)
assert c2.volume == c.volume
c3 = c.clone(clone_materials=False)
assert c3.id != c.id
assert c3.fill == c.fill
assert c3.region != c.region
assert c3.temperature == c.temperature
assert all(c2.translation == c.translation)
assert all(c2.rotation == c.rotation)
c4 = c.clone(clone_regions=False)
assert c4.id != c.id
assert c4.fill != c.fill
assert c4.region == c.region
assert c4.temperature == c.temperature
assert all(c2.translation == c.translation)
assert all(c2.rotation == c.rotation)
c5 = c.clone(clone_materials=False, clone_regions=False)
assert c5.id != c.id
assert c5.fill == c.fill
assert c5.region == c.region
assert c5.temperature == c.temperature
assert all(c2.translation == c.translation)
assert all(c2.rotation == c.rotation)
# Mutate the original to ensure the changes are not seen in the clones
c.fill = openmc.Material()
c.region = +openmc.ZCylinder()
c.translation = [-1,-2,-3]
c.rotation = [-4,-5,-6]
c.temperature = 1
assert c5.fill != c.fill
assert c5.region != c.region
assert c5.temperature != c.temperature
assert all(c2.translation != c.translation)
assert all(c2.rotation != c.rotation)
def test_temperature(cell_with_lattice):