-
Notifications
You must be signed in to change notification settings - Fork 17
Solver.poisson support pre-integrated vfuncs #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -146,21 +146,21 @@ def compute_geodesic_f( | |||||||
|
|
||||||||
| 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) | ||||||||
|
|
||||||||
| if scalar_input: | ||||||||
| # gradf: (n_elements, 3) | ||||||||
| gradnorm = gradf / np.sqrt((gradf**2).sum(1))[:, np.newaxis] | ||||||||
| gradnorm = np.nan_to_num(gradnorm) | ||||||||
| divf = compute_divergence(geom, gradnorm) | ||||||||
| vf = fem.poisson(divf) | ||||||||
| vf = fem.poisson(divf, integrate=False) | ||||||||
| vf -= vf.min() | ||||||||
| else: | ||||||||
| # gradf: (n_elements, n_functions, 3) — norm along last axis | ||||||||
| gradnorm = gradf / np.sqrt((gradf**2).sum(-1))[:, :, np.newaxis] | ||||||||
| gradnorm = np.nan_to_num(gradnorm) | ||||||||
| divf = compute_divergence(geom, gradnorm) # (n_vertices, n_functions) | ||||||||
| vf = fem.poisson(divf) # (n_vertices, n_functions) | ||||||||
| vf = fem.poisson(divf, integrate=False) # (n_vertices, n_functions) | ||||||||
| vf -= vf.min(axis=0) | ||||||||
| return vf | ||||||||
|
|
||||||||
|
|
@@ -200,21 +200,21 @@ def tria_compute_geodesic_f( | |||||||
| fem = Solver(tria, lump=True, use_cholmod=use_cholmod) | ||||||||
| # 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]) | ||||||||
|
Comment on lines
201
to
+203
|
||||||||
|
|
||||||||
| if scalar_input: | ||||||||
| # gradf: (n_triangles, 3) | ||||||||
| gradnorm = gradf / np.sqrt((gradf**2).sum(1))[:, np.newaxis] | ||||||||
| gradnorm = np.nan_to_num(gradnorm) | ||||||||
| divf = tria_compute_divergence(tria, gradnorm) | ||||||||
| vf = fem.poisson(divf) | ||||||||
| vf = fem.poisson(divf, integrate=False) | ||||||||
| vf -= vf.min() | ||||||||
| else: | ||||||||
| # gradf: (n_triangles, n_functions, 3) — norm along last axis | ||||||||
| gradnorm = gradf / np.sqrt((gradf**2).sum(-1))[:, :, np.newaxis] | ||||||||
| gradnorm = np.nan_to_num(gradnorm) | ||||||||
| divf = tria_compute_divergence(tria, gradnorm) # (n_vertices, n_functions) | ||||||||
| vf = fem.poisson(divf) # (n_vertices, n_functions) | ||||||||
| vf = fem.poisson(divf, integrate=False) # (n_vertices, n_functions) | ||||||||
| vf -= vf.min(axis=0) | ||||||||
| return vf | ||||||||
|
|
||||||||
|
|
@@ -503,20 +503,20 @@ def tria_compute_rotated_f( | |||||||
| gradf = tria_compute_gradient(tria, vfunc) | ||||||||
| 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) | ||||||||
|
||||||||
| # 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -784,6 +784,7 @@ def poisson( | |
| h: float | np.ndarray = 0.0, | ||
| dtup: tuple = (), | ||
| ntup: tuple = (), | ||
| integrate: bool = True, | ||
| ) -> np.ndarray: | ||
| """Solver for the Poisson equation with boundary conditions. | ||
|
|
||
|
|
@@ -808,6 +809,11 @@ def poisson( | |
| Neumann boundary condition as a tuple containing the index and | ||
| data arrays of same length. The default, an empty tuple, | ||
| corresponds to Neumann on all boundaries. | ||
| 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``. | ||
|
Comment on lines
+812
to
+816
|
||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -904,8 +910,9 @@ def poisson( | |
| (dim, n_rhs), dtype=dtype | ||
| ) | ||
| # 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 | ||
|
Comment on lines
912
to
+915
|
||
| if len(didx) > 0: | ||
| b = b - self.stiffness * dvec | ||
| # remove Dirichlet Nodes | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s now commented-out dead code (
# fem.mass = sparse.eye(...)). Sinceintegrate=Falseis the intended mechanism, consider removing the commented assignment and leaving a short explanatory comment (e.g., thatcompute_divergencealready returns an integrated divergence so Poisson should not re-applyB).