Unify mesh integration and add grouped moment quadrature#1770
Unify mesh integration and add grouped moment quadrature#1770peterdsharpe wants to merge 4 commits into
Conversation
physicsnemo/mesh/calculus/integration.py makes integrate() the single public entry point for ordinary P0 cell and P1 point field integration, keeping the location-specific implementations private. A shared nan_policy now gives integrate() and integrate_flux() explicit omit or propagate behavior instead of hard-coded NaN reduction. The same module adds integrate_moment() for measure-weighted outer-product moments. It supports aligned group axes, named cell fields, configurable accumulation precision, validation, and a batched matrix-product implementation that avoids materializing one outer product per cell. physicsnemo/mesh/calculus/__init__.py removes the redundant point and cell integration exports and exposes integrate_moment alongside integrate and integrate_flux. physicsnemo/mesh/mesh.py forwards nan_policy through the existing integrate and integrate_flux convenience methods while leaving the more specialized moment operation functional-only. test/mesh/calculus/test_integration.py routes ordinary quadrature coverage through integrate() and adds tests for NaN policies, grouped moment shapes, named fields, reduced-precision accumulation, FP64 preservation, gradients, validation, and flux forwarding. The result is a smaller and more consistent public API plus a reusable numerical reduction for mesh statistics, weak forms, and learned or classical integral operators.
Greptile SummaryThis PR unifies the mesh integration API by making
Important Files Changed
|
Keep integrate_cell_data and integrate_point_data available as warning-emitting wrappers around the unified integrate API, preserving the released import paths during a deprecation cycle. Re-export the aliases, document the migration in CHANGELOG.md, and cover compatibility warnings plus invalid integrate_moment nan policies.
|
/ok to test 844c030 |
|
/ok to test 0b9621d |
| accumulation_dtype: torch.dtype | None, | ||
| nan_policy: NanPolicy, | ||
| ) -> torch.Tensor: | ||
| """Core weighted grouped moment used by Mesh and streamed operators.""" |
There was a problem hiding this comment.
Can we add docstrings for parameters?
|
|
||
|
|
||
| class TestIntegrateCellData: | ||
| class TestIntegrateCellFields: |
There was a problem hiding this comment.
Could you have parameterized cell vs. point using pytest parameterize?
| return result_flat.reshape(result_shape) | ||
|
|
||
|
|
||
| def integrate_moment( |
There was a problem hiding this comment.
Does it make sense to expose it as Mesh.integrate_moment() as well? I believe currently Mesh.integrate() and Mesh.integrate_flux() exist, but not the moment one.
Summary
This makes
integrate()the main entry point for both cell-centered (P0) and point-centered (P1) field integration. The existingintegrate_cell_data()andintegrate_point_data()functions remain available as deprecated compatibility wrappers, so current imports keep working while users migrate.It adds an explicit
nan_policytointegrate(),integrate_flux(), and the newintegrate_moment(); the existingMeshmethods forward the policy where applicable. The default,"omit", preserves the current masked-data behavior, while"propagate"keeps NaNs visible in the result.integrate_moment()computes measure-weighted outer-product moments with support for named cell fields, aligned group dimensions, configurable accumulation precision, and gradients without materializing an outer product for every cell.Testing
Tests cover compatibility warnings, both NaN policies, grouped moment shapes, dtype handling, validation, gradients, and
Meshmethod forwarding.