Build mesh filter dataframe columns from mesh.indices - #4095
Open
GuySten wants to merge 2 commits into
Open
Conversation
GuySten
marked this pull request as ready for review
August 31, 2026 21:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build mesh filter dataframe columns from
mesh.indicesNo change to any existing dataframe. Verified column-for-column against
developfor every mesh type -- regular (2D and 3D), rectilinear, cylindrical,spherical and unstructured -- for both
MeshFilterandMeshSurfaceFilter.Problem
MeshFilter.get_pandas_dataframereconstructs mesh element indices per axis,including a special case for the one mesh type that is 0-based:
MeshSurfaceFilter.get_pandas_dataframedoes the same thing again with adifferent stride.
Every mesh class already exposes exactly this as
indices, in bin order andwith the right base. The filter is reimplementing it, which means the index
convention for a mesh type is stated in two places, and a new mesh type needs
filter.pyedited to get correct columns. It also assumes every mesh has oneindex per axis with a fixed per-axis stride, which is true of the current mesh
types but is a property of those meshes rather than of meshes in general.
Changes
Both methods now take the index tuples from the mesh:
_repeat_and_tilegainsaxis=0on itsnp.repeatcall so that an index tupleis repeated as a row rather than being flattened.
The
isinstance(self.mesh, openmc.UnstructuredMesh)special case goes away, asdoes the duplicated per-axis loop in the surface filter.
_mesh_current_namesis untouched.
Testing
New
tests/unit_tests/test_mesh_filter_dataframe.py, parametrized over regular3D, regular 2D, rectilinear, cylindrical and spherical, plus a separate
unstructured case:
axis_labels, withsurfappended last for thesurface filter
list(mesh.indices), in ordermesh.dimensionconstant across one element's surface bins
element_indexcolumnThese pin the conventions the implementation now depends on, so a future change
to
indicescannot quietly alter every user's dataframe.I also diffed the full dataframe output between
developand this branch forall five mesh types and both filters: columns, column order, row counts and
values are identical.
Notes
On the 0-based case specifically:
UnstructuredMeshalready reportsso the removed
idx_startbranch was reproducing whatindicesalready gave.The old code built
np.arange(0, n_elements)for the same single column, andthe two agree element for element.
This is the first of several pieces split out of #3857, and is useful
independently of that work: it removes the duplicated index logic and the mesh
type
isinstancefromfilter.py.Checklist
I have run clang-format (version 18) on any C++ source files (if applicable)I have made corresponding changes to the documentation (if applicable)