Skip to content

Adds DomainMesh improvements, docs, and bugfixes#1558

Merged
peterdsharpe merged 39 commits intoNVIDIA:mainfrom
peterdsharpe:psharpe/domainmesh-improvements-and-docs
Apr 21, 2026
Merged

Adds DomainMesh improvements, docs, and bugfixes#1558
peterdsharpe merged 39 commits intoNVIDIA:mainfrom
peterdsharpe:psharpe/domainmesh-improvements-and-docs

Conversation

@peterdsharpe
Copy link
Copy Markdown
Collaborator

PhysicsNeMo Pull Request

Description

Contains a bunch of small improvements to DomainMesh, such as:

  • Adding DomainMesh.draw() to mirror Mesh.draw() with multi-mesh support.
  • Allows multi-mesh plotting capabilities with PyVista visualization backend.
  • Fixes a bug in DomainMesh.n_boundaries, where we were incorrectly returning the `TensorDict
  • DomainMesh.check_boundary_watertight() bugfix by deduplicating vertices before watertightness check

Checklist

Dependencies

Review Process

All PRs are reviewed by the PhysicsNeMo team before merging.

Depending on which files are changed, GitHub may automatically assign a maintainer for review.

We are also testing AI-based code review tools (e.g., Greptile), which may add automated comments with a confidence score.
This score reflects the AI’s assessment of merge readiness and is not a qualitative judgment of your work, nor is
it an indication that the PR will be accepted / rejected.

AI-generated feedback should be reviewed critically for usefulness.
You are not required to respond to every AI comment, but they are intended to help both authors and reviewers.
Please react to Greptile comments with 👍 or 👎 to provide feedback on their accuracy.

…at allows selective application of functions to interior and boundary meshes. Update related tests to validate the new functionality and ensure proper behavior with global data preservation.
…ing existing plotters. This allows overlaying multiple meshes on the same scene.
…ns to support both matplotlib and PyVista backends, allowing for overlaying multiple meshes on the same scene.
…uce geometry-only meshes, improving check_boundary_watertight to include a cleaning step. Documentation for these methods has also been added or updated.
…streamline boundary mesh representation, enhancing readability and consistency in displayed mesh information.
…t sets

This new function utilizes KNN to find and return matched indices of source and target points within a specified tolerance, enhancing the sampling capabilities of the mesh module.
@peterdsharpe peterdsharpe requested a review from coreyjadams April 9, 2026 22:40
@peterdsharpe peterdsharpe marked this pull request as ready for review April 9, 2026 22:41
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 9, 2026

Greptile Summary

This PR adds DomainMesh.draw() for multi-mesh visualization (with PyVista overlay support), correctly fixes n_boundaries (was returning a TensorDict instead of an int), and fixes is_boundary_watertight() by calling .clean() before the watertightness check to deduplicate shared vertices across independently-meshed patches. It also exports find_nearest_cells and match_points from the sampling __init__.py, and ships a comprehensive test suite for DomainMesh transforms. The one minor inconsistency is that show_edges is forwarded to the interior draw but not to boundary draws in DomainMesh.draw().

Important Files Changed

Filename Overview
physicsnemo/mesh/domain_mesh.py Adds DomainMesh.draw(), fixes n_boundaries (was returning TensorDict), and fixes is_boundary_watertight() with .clean() dedup; one minor inconsistency with show_edges not forwarded to boundary draws.
physicsnemo/mesh/visualization/_pyvista_impl.py Adds plotter parameter to draw_mesh_pyvista to enable multi-mesh overlay on a shared PyVista Plotter; the module-level pv import is safe since this module is only imported lazily after pyvista availability is confirmed.
physicsnemo/mesh/visualization/draw_mesh.py No functional changes visible; forwards plotter via ax parameter to pyvista backend, enabling DomainMesh.draw() overlay pattern.
physicsnemo/mesh/sampling/init.py Adds find_nearest_cells and match_points to public exports; both functions were already implemented in sample_data.py.
test/mesh/test_domain_mesh_transforms.py Comprehensive new test file covering apply, translate, rotate, scale, transform, clean, strip_caches, subdivide, data operations, validation, chaining, and domain-level global_data transformation.

Reviews (1): Last reviewed commit: "formatting" | Re-trigger Greptile

Comment thread physicsnemo/mesh/domain_mesh.py Outdated
… and improve formatting of mesh data representation, enhancing clarity and consistency in the tutorial outputs.
This commit introduces a new test to ensure that passing a PyVista Plotter to the mesh draw method with the matplotlib backend raises the appropriate ValueError. This enhances the robustness of the visualization module by validating error handling for unsupported backends.
This commit adds validation checks to ensure that the 'ax' parameter in the draw_mesh_matplotlib function is a valid matplotlib Axes object, and the 'plotter' parameter in the draw_mesh_pyvista function is a valid PyVista Plotter object. Appropriate ValueErrors are raised for invalid types, improving robustness in backend handling.
…a backends

This commit enhances the docstrings for the draw_mesh_matplotlib and draw_mesh_pyvista functions, clarifying the purpose of the 'ax' and 'plotter' parameters, respectively. The updates specify that these parameters can be used to overlay multiple meshes on the same axes or scene, improving the usability and understanding of the functions.
@peterdsharpe
Copy link
Copy Markdown
Collaborator Author

/blossom-ci

Copy link
Copy Markdown
Collaborator

@coreyjadams coreyjadams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice notebook! The rest of the pr is great, pretty self explanatory. I have one small question I noticed but I suspect it's easy.

DomainMesh is really a killer app in the new release!

Comment thread physicsnemo/mesh/domain_mesh.py Outdated
- Introduced `_open_tetrahedron_faces` function to create boundary meshes for a closed unit tetrahedron.
- Added `TestProperties` class to verify boundary count and sorted boundary names.
- Implemented `TestIsBoundaryWatertight` class to test various scenarios for boundary watertightness, including handling of float noise and explicit tolerance settings.
- Ensured that domains with no boundaries return false for watertightness and that closed tetrahedrons are correctly identified as watertight.
…ucture

- Added execution counts and outputs to code cells for better tracking of execution flow.
- Removed redundant output definitions to streamline the notebook.
- Improved the organization of code cells for better readability and understanding of the DomainMesh example.
- Clarified the tolerance parameter description to specify that the L2 distance comparison is inclusive.
- Added notes regarding the one-way nearest-neighbor lookup and duplicate detection within a single point cloud.
- Updated the return statement to use nonzero indices for matched source points, improving clarity in the output.
…tplotlib >= 3.7

- Updated edgecolors assignment to use a transparent RGBA list instead of the string "none" to prevent crashes during shading operations on empty arrays.
- Ensured that the new implementation maintains the intended visual output while improving stability.
- Updated the import logic to accept `BasePlotter` as a common ancestor for various plotters, ensuring compatibility with both `pv.Plotter` and Qt-backed plotters.
- Added comments to clarify the fallback mechanism for older versions of pyvista.
…parameter, allowing users to choose whether to retain point and cell data during the merge process.

- Improved documentation for `merge_boundaries`, clarifying the behavior based on the `preserve_data` flag and detailing the conditions under which data is preserved or stripped.
…d visualization

- Updated the `draw` method to accept `cell_scalars`, `cmap`, `vmin`, `vmax`, and alpha parameters for points, cells, and edges, allowing for more customizable rendering options.
- Improved documentation to clarify parameter usage and provide examples for better user guidance.
- Adjusted default behavior for `show_edges` to enhance readability of dense interior meshes.
…ization

- Renamed test methods for clarity, changing `test_auto_tolerance_handles_float_noise` to `test_default_tolerance_handles_float_noise` and `test_explicit_tolerance_overrides_auto` to `test_explicit_tolerance_passthrough`.
- Introduced `TestMergeBoundaries` class to validate boundary merging functionality, including error handling for zero boundaries and data preservation during merges.
- Added visualization tests in `TestDraw` to ensure proper rendering of boundaries and functionality of the `draw` method with existing axes.
- Enhanced documentation within tests to clarify expected behaviors and outcomes.
@peterdsharpe
Copy link
Copy Markdown
Collaborator Author

/blossom-ci

@peterdsharpe peterdsharpe enabled auto-merge April 21, 2026 02:44
@peterdsharpe peterdsharpe added this pull request to the merge queue Apr 21, 2026
Merged via the queue into NVIDIA:main with commit 5932156 Apr 21, 2026
4 checks passed
@peterdsharpe peterdsharpe deleted the psharpe/domainmesh-improvements-and-docs branch April 21, 2026 13:32
@peterdsharpe peterdsharpe mentioned this pull request Apr 21, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants