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

Commit e0dae18

Browse files
Keith RobertsKeith Roberts
Keith Roberts
and
Keith Roberts
authored
fixing points in iterative laplacian2 (#210)
* fixing points in iterative laplacian2 * update change log Co-authored-by: Keith Roberts <krober@usp.edu>
1 parent 2b0d924 commit e0dae18

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
823823
### Added
824824
- Smoothed sets (e.g., intersections, differences, and unions)
825825
- Conversion of velocity data from feet-second to meters-second
826+
- Support for fixed points in iterative Laplacian mesh smoother.
826827
### Improved
827828
- Simplified pybind11 build system.
828829

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

837840
## [3.4.0]-2021-02-14
838841
### Added

SeismicMesh/geometry/utils.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def laplacian2_fixed_point(vertices, entities):
547547
return vertices_new, entities
548548

549549

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

575+
def _closest_node(node, nodes):
576+
nodes = np.asarray(nodes)
577+
deltas = nodes - node
578+
dist_2 = np.einsum("ij,ij->i", deltas, deltas)
579+
return np.argmin(dist_2)
580+
571581
eps = np.finfo(float).eps
572582

573583
n = len(vertices)
@@ -580,6 +590,13 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
580590
)
581591
bnd = get_boundary_vertices(entities)
582592
edge = get_edges(entities)
593+
if pfix is not None:
594+
ifix = []
595+
for fix in pfix:
596+
ifix.append(_closest_node(fix, vertices))
597+
ifix = np.asarray(ifix)
598+
bnd = np.concatenate((bnd, ifix))
599+
583600
W = np.sum(S, 1)
584601
if np.any(W == 0):
585602
print("Invalid mesh. Disjoint vertices found. Returning", flush=True)

0 commit comments

Comments
 (0)