Repository navigation
Add slice_tree_mesh utility for axis-aligned TreeMesh slices - #420
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #420 +/- ##
==========================================
+ Coverage 86.86% 87.06% +0.20%
==========================================
Files 93 93
Lines 19239 19348 +109
Branches 2154 2157 +3
==========================================
+ Hits 16712 16846 +134
+ Misses 1840 1814 -26
- Partials 687 688 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
discretize.utils.slice_tree_mesh builds the 2D TreeMesh of an axis-aligned slice through a 3D TreeMesh (one 2D cell per 3D cell cut by the plane), and can also return the index of the 3D cell each 2D cell comes from, so that values_2d = values_3d[indices]. A plane lying on cell faces takes the cells on its high side, or its low side at the top of the mesh, which makes slicing exactly at a boundary well defined. TreeMesh.plot_slice now uses it instead of building the slice itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bacc9b3 to
b90120c
Compare
santisoler
left a comment
There was a problem hiding this comment.
Looks nice! I like the fact to be able to slice a mesh and not necessarily just plotting it.
One idea: what if instead of defining a slice_tree_mesh we define a slice_mesh function that can take either a TreeMesh or a TensorMesh?
At least for now we could raise a NonImplementedError if the passed mesh is a TensorMesh, and we can add that functionality later.
Easy enough to add it for |
|
Yes, that should be fine. If we want to make it clearer, maybe we could name it to |
discretize.utils.slice_mesh replaces slice_tree_mesh and slices a 3D TensorMesh or TreeMesh, returning a 2D mesh of the same type (and optionally the index of the 3D cell each 2D cell comes from). It validates the inputs once and dispatches to a private implementation for each mesh type. Indices are only computed when requested. The plane bounds now use the mesh's own node arrays, so a location taken from e.g. mesh.nodes_x[-1] is no longer rejected because of round-off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tensor plot_slice now gets the 2D mesh and the 3D cell of each 2D cell from slice_mesh, like the TreeMesh version, instead of building the 2D mesh by hand and indexing a reshaped 3D array. The plotted values are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@santisoler I implemented it for the tensor mesh path as well since it let us get rid of redundant code within the plotting scripts in the same way |
|
Amazing! Thanks for taking care of this! |
This essentially moves the code that was internal to
plot_sliceto a user-facing utility.discretize.utils.slice_tree_meshbuilds the 2DTreeMeshof an axis-aligned slice through a 3DTreeMesh(one 2D cell per 3D cell cut by the plane), and can also return the index of the 3D cell each 2D cell comes from, so thatvalues_2d = values_3d[indices]. A plane lying on cell faces takes the cells on its high side, or its low side at the top of the mesh, which makes slicing exactly at a boundary well defined.TreeMesh.plot_slicenow uses it instead of building the slice itself.