Added points2nodes method to meshutils

This commit is contained in:
Dave Marchant
2014-03-17 12:47:36 -07:00
parent bc91872215
commit e30dfb447d
2 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -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
+21
View File
@@ -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