mirror of
https://github.com/wassname/simpeg.git
synced 2026-06-29 09:40:10 +08:00
Added points2nodes method to meshutils
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from matutils import *
|
||||
from meshutils import exampleLrmGrid, meshTensors
|
||||
from meshutils import exampleLrmGrid, meshTensors, points2nodes
|
||||
from lrmutils import volTetra, faceInfo, indexCube
|
||||
from interputils import interpmat
|
||||
from ipythonutils import easyAnimate as animate
|
||||
|
||||
@@ -53,6 +53,27 @@ def meshTensors(*args):
|
||||
|
||||
return list(tensors) if len(tensors) > 1 else tensors[0]
|
||||
|
||||
def points2nodes(mesh, pts):
|
||||
"""
|
||||
Move a list of the nearest nodes to a set of points
|
||||
|
||||
:param simpeg.Mesh.TensorMesh mesh: The mesh
|
||||
:param numpy.ndarray pts: Points to move}
|
||||
:rtype: numpy.ndarray
|
||||
:return: nodeInds
|
||||
"""
|
||||
|
||||
pts = np.atleast_2d(pts)
|
||||
|
||||
assert mesh._meshType == 'TENSOR'
|
||||
assert pts.shape[1] == mesh.dim
|
||||
|
||||
nodeInds = np.empty(pts.shape[0], dtype=int)
|
||||
|
||||
for i, pt in enumerate(pts):
|
||||
nodeInds[i] = ((np.tile(pt, (mesh.nN,1)) - mesh.gridN)**2).sum(axis=1).argmin()
|
||||
|
||||
return nodeInds
|
||||
if __name__ == '__main__':
|
||||
from SimPEG import mesh
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
Reference in New Issue
Block a user