switch universe deepcopying for a fresh instance on clones

This commit is contained in:
josh 2023-01-12 21:58:22 +00:00
parent 3f8f8f6701
commit e799346502
2 changed files with 16 additions and 3 deletions

View file

@ -1,7 +1,6 @@
from abc import ABC, abstractmethod
from collections import OrderedDict
from collections.abc import Iterable
from copy import deepcopy
from numbers import Integral, Real
from pathlib import Path
from tempfile import TemporaryDirectory
@ -138,8 +137,14 @@ class UniverseBase(ABC, IDManagerMixin):
# If no memoize'd clone exists, instantiate one
if self not in memo:
clone = deepcopy(self)
clone.id = None
clone = openmc.Universe(name=self.name)
clone.volume = self.volume
# Try to set DAGMCUniverse-specific attributes on the clone
try:
clone.auto_geom_ids = self.auto_geom_ids
clone.auto_mat_ids = self.auto_mat_ids
except AttributeError:
pass
# Clone all cells for the universe clone
clone._cells = OrderedDict()

View file

@ -120,6 +120,14 @@ def test_clone():
assert next(iter(u3.cells.values())).region ==\
next(iter(u1.cells.values())).region
dagmc_u = openmc.DAGMCUniverse(filename="")
dagmc_u.auto_geom_ids = True
dagmc_u.auto_mat_ids = True
dagmc_u1 = dagmc_u.clone()
assert dagmc_u1.name == dagmc_u.name
assert dagmc_u1.auto_geom_ids == dagmc_u.auto_geom_ids
assert dagmc_u1.auto_mat_ids == dagmc_u.auto_mat_ids
def test_create_xml(cell_with_lattice):
cells = [openmc.Cell() for i in range(5)]