From 1dca4d842bfff20f6ea3cb8a9a5faab2734f8792 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Wed, 5 Aug 2015 19:10:03 -0600 Subject: [PATCH] Fix hex lattices in HDF5 summary --- openmc/summary.py | 72 ++++++++++++++++++++++++++++++++++++++------ src/hdf5_summary.F90 | 8 ++--- 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/openmc/summary.py b/openmc/summary.py index c0673ef23..2165d114a 100644 --- a/openmc/summary.py +++ b/openmc/summary.py @@ -411,16 +411,70 @@ class Summary(object): if outer != -22: lattice.outer = self.universes[outer] - # Build array of Universe pointers for the Lattice - universes = \ - np.ndarray(tuple(universe_ids.shape), dtype=openmc.Universe) + # Build array of Universe pointers for the Lattice. Note that + # we need to convert between the HDF5's square array of + # (x, alpha, z) to the PythonAPI's format of a ragged nested + # nested list of (z, ring, theta). + universes = [] + for z in range(lattice.num_axial): + # Add a list for this axial level. + universes.append([]) + x = lattice.num_rings - 1 + a = 2*lattice.num_rings - 2 + for r in range(lattice.num_rings - 1, 0, -1): + # Add a list for this ring. + universes[-1].append([]) - for i in range(universe_ids.shape[0]): - for j in range(universe_ids.shape[1]): - for k in range(universe_ids.shape[2]): - if universe_ids[i, j, k] != -1: - universes[i, j, k] = self.get_universe_by_id( - universe_ids[i, j, k]) + # Climb down the top-right. + for i in range(r): + universes[-1][-1].append(universe_ids[z, a, x]) + x += 1 + a -= 1 + + # Climb down the right. + for i in range(r): + universes[-1][-1].append(universe_ids[z, a, x]) + a -= 1 + + # Climb down the bottom-right. + for i in range(r): + universes[-1][-1].append(universe_ids[z, a, x]) + x -= 1 + + # Climb up the bottom-left. + for i in range(r): + universes[-1][-1].append(universe_ids[z, a, x]) + x -= 1 + a += 1 + + # Climb up the left. + for i in range(r): + universes[-1][-1].append(universe_ids[z, a, x]) + a += 1 + + # Climb up the top-left. + for i in range(r): + universes[-1][-1].append(universe_ids[z, a, x]) + x += 1 + + # Move down to the next ring. + a -= 1 + + # Convert the ids into Universe objects. + universes[-1][-1] = [self.get_universe_by_id(u_id) + for u_id in universes[-1][-1]] + + # Handle the degenerate center ring separately. + u_id = universe_ids[z, a, x] + universes[-1].append([self.get_universe_by_id(u_id)]) + + # Add the universes to the lattice. + if len(pitch) == 2: + # Lattice is 3D + lattice.universes = universes + else: + # Lattice is 2D; extract the only axial level + lattice.universes = universes[0] if offset_size > 0: lattice.offsets = offsets diff --git a/src/hdf5_summary.F90 b/src/hdf5_summary.F90 index 161246f1c..15caf2edf 100644 --- a/src/hdf5_summary.F90 +++ b/src/hdf5_summary.F90 @@ -394,7 +394,7 @@ contains ! Write number of lattice cells. call su % write_data(lat % n_rings, "n_rings", & group="geometry/lattices/lattice " // trim(to_str(lat % id))) - call su % write_data(lat % n_rings, "n_axial", & + call su % write_data(lat % n_axial, "n_axial", & group="geometry/lattices/lattice " // trim(to_str(lat % id))) ! Write lattice center, pitch and outer universe. @@ -407,10 +407,10 @@ contains end if if (lat % is_3d) then - call su % write_data(lat % pitch, "pitch", length=3, & + call su % write_data(lat % pitch, "pitch", length=2, & group="geometry/lattices/lattice " // trim(to_str(lat % id))) else - call su % write_data(lat % pitch, "pitch", length=2, & + call su % write_data(lat % pitch, "pitch", length=1, & group="geometry/lattices/lattice " // trim(to_str(lat % id))) end if @@ -447,7 +447,7 @@ contains end do end do call su % write_data(lattice_universes, "universes", & - &length=(/lat % n_axial, 2*lat % n_rings-1, 2*lat % n_rings-1/), & + &length=(/2*lat % n_rings-1, 2*lat % n_rings-1, lat % n_axial/), & &group="geometry/lattices/lattice " // trim(to_str(lat % id))) deallocate(lattice_universes) end select