Solver.poisson support pre-integrated vfuncs#115
Solver.poisson support pre-integrated vfuncs#115magnesium2400 wants to merge 1 commit intoDeep-MI:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #115 +/- ##
==========================================
- Coverage 50.04% 50.01% -0.04%
==========================================
Files 15 15
Lines 3153 3151 -2
Branches 414 415 +1
==========================================
- Hits 1578 1576 -2
Misses 1426 1426
Partials 149 149
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds an option to Solver.poisson to skip mass-matrix integration when the RHS is already pre-integrated, and updates differential-geometry helpers to use that option instead of mutating Solver.mass.
Changes:
- Add
integrate: bool = TruetoSolver.poissonto optionally bypassB*hintegration. - Update
diffgeo.compute_geodesic_f,tria_compute_geodesic_f, andtria_compute_rotated_fto callpoisson(..., integrate=False)instead of replacingfem.masswith the identity. - Document the new flag in the
poissondocstring.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
lapy/solver.py |
Introduces integrate flag and conditional mass-matrix application when building the RHS. |
lapy/diffgeo.py |
Switches geodesic/rotated-function routines to use integrate=False rather than altering solver state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| integrate: bool, default=True | ||
| Whether to integrate the right hand side over the surface using | ||
| the mass matrix. If True, the right hand side is effectively | ||
| replaced by ``B h``. If False, the right hand side is used as is, | ||
| which corresponds to ``A x = h``. |
There was a problem hiding this comment.
The new parameter doc header uses integrate: bool but the rest of the docstring follows NumPy style (name : type). Also, integrate=False changes the equation being solved and skips mass-matrix scaling for the Neumann term as well (since b = h - nvec is no longer multiplied by B). Please adjust the docstring (including the earlier text that implies A x = B h) and clarify the expected ntup convention when integrate=False.
| # compute right hand side | ||
| mass = self.mass.astype(dtype, copy=False) | ||
| b = mass * (h - nvec) | ||
| b = h - nvec | ||
| if integrate: | ||
| b = self.mass.astype(dtype, copy=False) * b |
There was a problem hiding this comment.
The new integrate flag introduces a second execution path for RHS construction. Please add unit tests covering integrate=False (including at least one case with Dirichlet/Neumann terms if supported) and asserting it matches the previous workaround (e.g., setting mass to identity or pre-multiplying h appropriately), so behavior stays stable across refactors.
| gradf = compute_gradient(geom, vfunc) | ||
| fem = Solver(geom, lump=True, use_cholmod=use_cholmod) | ||
| fem.mass = sparse.eye(fem.stiffness.shape[0], dtype=fem.stiffness.dtype) | ||
| # fem.mass = sparse.eye(fem.stiffness.shape[0], dtype=fem.stiffness.dtype) |
There was a problem hiding this comment.
There’s now commented-out dead code (# fem.mass = sparse.eye(...)). Since integrate=False is the intended mechanism, consider removing the commented assignment and leaving a short explanatory comment (e.g., that compute_divergence already returns an integrated divergence so Poisson should not re-apply B).
| # fem.mass = sparse.eye(fem.stiffness.shape[0], dtype=fem.stiffness.dtype) | |
| # compute_divergence already returns an integrated divergence, so Poisson | |
| # should solve with integrate=False and must not re-apply the mass matrix. |
| # div is the integrated divergence (so it is already B*div); | ||
| # pass identity instead of B here | ||
| fem.mass = sparse.eye(fem.stiffness.shape[0]) | ||
| # fem.mass = sparse.eye(fem.stiffness.shape[0]) |
There was a problem hiding this comment.
The comment here still describes the old workaround (“pass identity instead of B here”) and keeps the identity assignment commented out. Please update the comment to reflect the new approach (integrate=False) and remove the commented-out fem.mass = sparse.eye(...) line to avoid confusing future readers.
| tn = tria.tria_normals() | ||
| fem = Solver(tria, lump=True, use_cholmod=use_cholmod) | ||
| fem.mass = sparse.eye(fem.stiffness.shape[0], dtype=vfunc.dtype) | ||
| # fem.mass = sparse.eye(fem.stiffness.shape[0], dtype=vfunc.dtype) |
There was a problem hiding this comment.
There’s leftover commented-out code (# fem.mass = sparse.eye(...)) from the pre-integrate workaround. Since this function now calls poisson(..., integrate=False), please remove the commented assignment and (if needed) replace it with a brief note explaining why integration is disabled here.
| # fem.mass = sparse.eye(fem.stiffness.shape[0], dtype=vfunc.dtype) | |
| # The divergence has already been assembled, so disable integration in the | |
| # Poisson solve instead of using the old mass-matrix workaround. |
Solver.poissonalways multiplies the input vfunchbyself.massto generate an integrated mapdiffgeo.compute_geodesic_fetc.Test_TriaMesh_Geodesics.ipynbstill look good whenvf = fem.poisson(Bi * divx)is replaced byvf = fem.poisson(divx, integrate=False)