Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
fixing points in iterative laplacian2 (#210)
Browse files Browse the repository at this point in the history
* fixing points in iterative laplacian2

* update change log

Co-authored-by: Keith Roberts <[email protected]>
  • Loading branch information
Keith Roberts and Keith Roberts authored Apr 18, 2021
1 parent 2b0d924 commit e0dae18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Smoothed sets (e.g., intersections, differences, and unions)
- Conversion of velocity data from feet-second to meters-second
- Support for fixed points in iterative Laplacian mesh smoother.
### Improved
- Simplified pybind11 build system.

Expand All @@ -833,6 +834,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Visuzlization of signed distance functions
### Fixed
- Support for Python 3.9
### Improved
- Fixed points in iterative Laplacian smooth

## [3.4.0]-2021-02-14
### Added
Expand Down
19 changes: 18 additions & 1 deletion SeismicMesh/geometry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def laplacian2_fixed_point(vertices, entities):
return vertices_new, entities


def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1, pfix=None):
"""Move vertices to the average position of their connected neighbors
with the goal to hopefully improve geometric entity quality.
Expand All @@ -559,6 +559,10 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
:type max_iter: `int`, optional
:param tol: iterations will cease when movement < tol
:type tol: `float`, optional
:param verbose: display progress to the screen
:type verbose: `float`, optional
:param pfix: coordinates that you don't wish to move
:type pfix: array-like
:return vertices: updated vertices of mesh
:rtype: numpy.ndarray[`float` x dim]
Expand All @@ -568,6 +572,12 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
if vertices.ndim != 2:
raise NotImplementedError("Laplacian smoothing only works in 2D for now")

def _closest_node(node, nodes):
nodes = np.asarray(nodes)
deltas = nodes - node
dist_2 = np.einsum("ij,ij->i", deltas, deltas)
return np.argmin(dist_2)

eps = np.finfo(float).eps

n = len(vertices)
Expand All @@ -580,6 +590,13 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
)
bnd = get_boundary_vertices(entities)
edge = get_edges(entities)
if pfix is not None:
ifix = []
for fix in pfix:
ifix.append(_closest_node(fix, vertices))
ifix = np.asarray(ifix)
bnd = np.concatenate((bnd, ifix))

W = np.sum(S, 1)
if np.any(W == 0):
print("Invalid mesh. Disjoint vertices found. Returning", flush=True)
Expand Down

0 comments on commit e0dae18

Please sign in to comment.