From 55e1ebff2d06c4c70599ab6c3dbe07cb57a5b3ae Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 7 Jun 2016 17:11:59 -0500 Subject: [PATCH] Use multiple universes for TRISOs --- openmc/model/triso.py | 52 +++++++++++++------------------ tests/test_triso/inputs_true.dat | 2 +- tests/test_triso/plots.xml | 6 ++++ tests/test_triso/results_true.dat | 2 +- tests/test_triso/test_triso.py | 28 +++++++++++------ 5 files changed, 48 insertions(+), 42 deletions(-) create mode 100644 tests/test_triso/plots.xml diff --git a/openmc/model/triso.py b/openmc/model/triso.py index dc53e6ec0..ca519ed6f 100644 --- a/openmc/model/triso.py +++ b/openmc/model/triso.py @@ -12,18 +12,17 @@ class TRISO(object): Parameters ---------- - materials : Iterable of openmc.Material - Material to be assigned to each layer of the TRISO particle starting - with the innermost and proceeding outwards - radii : Iterable of float - Outer radii in cm of each layer of the TRISO particle in ascending order + outer_radius : int + Outer radius of TRISO particle + inner_univ : openmc.Universe + Universe which contains all layers of the TRISO particle center : Iterable of float Cartesian coordinates of the center of the TRISO particle in cm Attributes ---------- - cells : list of opemc.Cell - Each layer of the TRISO particle + cell : opemc.Cell + Cell which contains the TRISO universe center : numpy.ndarray Cartesian coordinates of the center of the TRISO particle in cm outside : openmc.Region @@ -34,27 +33,18 @@ class TRISO(object): """ - def __init__(self, materials, radii, center=(0., 0., 0.)): - surfaces = [openmc.Sphere(R=r) for r in radii] - cells = [] - for i, m in enumerate(materials): - c = openmc.Cell(fill=m) - if i == 0: - c.region = -surfaces[i] - else: - c.region = +surfaces[i-1] & -surfaces[i] - cells.append(c) - self._cells = cells - self._surfaces = surfaces + def __init__(self, outer_radius, inner_univ, center=(0., 0., 0.)): + self._surface = openmc.Sphere(R=outer_radius) + self._cell = openmc.Cell(fill=inner_univ, region=-self._surface) self.center = np.asarray(center) @property def bounding_box(self): - return self.cells[-1].region.bounding_box + return self.cell.region.bounding_box @property - def cells(self): - return self._cells + def cell(self): + return self._cell @property def center(self): @@ -62,13 +52,15 @@ class TRISO(object): @property def outside(self): - return ~self.cells[-1].region.nodes[-1] + return +self._surface @center.setter def center(self, center): cv.check_type('TRISO center', center, Iterable, Real) - for s in self._surfaces: - s.x0, s.y0, s.z0 = center + self._surface.x0 = center[0] + self._surface.y0 = center[1] + self._surface.z0 = center[2] + self.cell.translation = center self._center = center def classify(self, lattice): @@ -136,11 +128,9 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background): # Create copy of TRISO particle with materials preserved and # different cell/surface IDs t_copy = copy.deepcopy(t) - for c, c_copy in zip(t.cells, t_copy.cells): - c_copy.id = None - c_copy.fill = c.fill - for s in t_copy._surfaces: - s.id = None + t_copy.cell.id = None + t_copy.cell.fill = t.cell.fill + t_copy._surface.id = None triso_locations[idx].append(t_copy) # Create universes @@ -155,7 +145,7 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background): u = openmc.Universe() u.add_cell(background_cell) for t in triso_list: - u.add_cells(t.cells) + u.add_cell(t.cell) iz, iy, ix = idx t.center = lattice.get_local_coordinates(t.center, (ix, iy, iz)) diff --git a/tests/test_triso/inputs_true.dat b/tests/test_triso/inputs_true.dat index 40f312850..3e54e5e6f 100644 --- a/tests/test_triso/inputs_true.dat +++ b/tests/test_triso/inputs_true.dat @@ -1 +1 @@ -6c6fecedf3db0b91b69b7b7b57b3a52c42947253bea4ee3889d6bbd6e74935cc4e599c1c743eb589a1045868412f3f88c5fef7cf10e180bdc4bd182970c9ee15 \ No newline at end of file +2dcfd1a17cba671874e60192a7355deb57e2e51467a474fd168c8b51e454a977edb34df07ae11625c0a43906112152c75113e442a9a8f240a4c9d1a11ee4771d \ No newline at end of file diff --git a/tests/test_triso/plots.xml b/tests/test_triso/plots.xml new file mode 100644 index 000000000..60ae7d9d8 --- /dev/null +++ b/tests/test_triso/plots.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/tests/test_triso/results_true.dat b/tests/test_triso/results_true.dat index 8f968f65a..ea7da21ed 100644 --- a/tests/test_triso/results_true.dat +++ b/tests/test_triso/results_true.dat @@ -1,2 +1,2 @@ k-combined: -1.685303E+00 1.121936E-01 +1.662675E+00 1.475968E-02 diff --git a/tests/test_triso/test_triso.py b/tests/test_triso/test_triso.py index f7f4daa7b..d1ac4e5cd 100644 --- a/tests/test_triso/test_triso.py +++ b/tests/test_triso/test_triso.py @@ -50,22 +50,31 @@ class TRISOTestHarness(PyAPITestHarness): graphite.add_s_alpha_beta('Graph', '71t') # Create TRISO particles - materials = [fuel, porous_carbon, ipyc, sic, opyc] - radii = np.array([212.5, 312.5, 347.5, 382.5, 422.5])*1e-4 + spheres = [openmc.Sphere(R=r*1e-4) + for r in [212.5, 312.5, 347.5, 382.5]] + c1 = openmc.Cell(fill=fuel, region=-spheres[0]) + c2 = openmc.Cell(fill=porous_carbon, region=+spheres[0] & -spheres[1]) + c3 = openmc.Cell(fill=ipyc, region=+spheres[1] & -spheres[2]) + c4 = openmc.Cell(fill=sic, region=+spheres[2] & -spheres[3]) + c5 = openmc.Cell(fill=opyc, region=+spheres[3]) + inner_univ = openmc.Universe(cells=[c1, c2, c3, c4, c5]) + + outer_radius = 422.5*1e-4 trisos = [] random.seed(1) for i in range(100): # Randomly sample location - x = random.uniform(-0.5, 0.5) - y = random.uniform(-0.5, 0.5) - z = random.uniform(-0.5, 0.5) - t = openmc.model.TRISO(materials, radii, (x, y, z)) + lim = 0.5 - outer_radius*1.001 + x = random.uniform(-lim, lim) + y = random.uniform(-lim, lim) + z = random.uniform(-lim, lim) + t = openmc.model.TRISO(outer_radius, inner_univ, (x, y, z)) # Make sure TRISO doesn't overlap with another for tp in trisos: xp, yp, zp = tp.center distance = sqrt((x - xp)**2 + (y - yp)**2 + (z - zp)**2) - if distance <= 2*radii[-1]: + if distance <= 2*outer_radius: break else: trisos.append(t) @@ -82,8 +91,9 @@ class TRISOTestHarness(PyAPITestHarness): # Create lattice ll, ur = box.region.bounding_box shape = (3, 3, 3) + pitch = (ur - ll) / shape lattice = openmc.model.create_triso_lattice( - trisos, ll, (ur - ll)/shape, shape, graphite) + trisos, ll, pitch, shape, graphite) box.fill = lattice root = openmc.Universe(0, cells=[box]) @@ -93,7 +103,7 @@ class TRISOTestHarness(PyAPITestHarness): settings = openmc.Settings() settings.batches = 5 settings.inactive = 0 - settings.particles = 50 + settings.particles = 100 settings.source = openmc.Source(space=openmc.stats.Point()) settings.export_to_xml()