From d393a74906d811e81f1700b8286dbb2b62e16e97 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 16 Mar 2018 14:38:37 -0500 Subject: [PATCH] Implement get_bin and get_bin_index for MeshSurfaceFilter --- docs/source/pythonapi/base.rst | 1 + openmc/filter.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/source/pythonapi/base.rst b/docs/source/pythonapi/base.rst index f1633f3f9..070b5bd20 100644 --- a/docs/source/pythonapi/base.rst +++ b/docs/source/pythonapi/base.rst @@ -109,6 +109,7 @@ Constructing Tallies openmc.CellbornFilter openmc.SurfaceFilter openmc.MeshFilter + openmc.MeshSurfaceFilter openmc.EnergyFilter openmc.EnergyoutFilter openmc.MuFilter diff --git a/openmc/filter.py b/openmc/filter.py index 7fa47cb4d..26d81112f 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -865,10 +865,25 @@ class MeshSurfaceFilter(MeshFilter): return 4*n_dim*reduce(operator.mul, self.mesh.dimension) def get_bin_index(self, filter_bin): - raise NotImplementedError + # Split bin into mesh/surface parts + *mesh_tuple, surf = filter_bin + + # Get index for mesh alone + mesh_index = super().get_bin_index(mesh_tuple) + + # Combine surface and mesh index + n_dim = len(self.mesh.dimension) + for surf_index, name in _CURRENT_NAMES.items(): + if surf == name: + return 4*n_dim*mesh_index + surf_index - 1 + else: + raise ValueError("'{}' is not a valid mesh surface.".format(surf)) def get_bin(self, bin_index): - raise NotImplementedError + n_dim = len(self.mesh.dimension) + mesh_index, surf_index = divmod(bin_index, 4*n_dim) + mesh_bin = super().get_bin(mesh_index) + return mesh_bin + (_CURRENT_NAMES[surf_index + 1],) def get_pandas_dataframe(self, data_size, stride, **kwargs): """Builds a Pandas DataFrame for the Filter's bins.