mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-09 11:34:26 +08:00
Merge branch 'develop' of https://github.com/simpeg/simpeg into cylClean
Conflicts: SimPEG/Mesh/TensorMesh.py also lower top on one test.
This commit is contained in:
+33
-10
@@ -325,7 +325,7 @@ class TensorMesh(BaseTensorMesh, TensorView, DiffOperators, InnerProducts):
|
||||
|
||||
# --------------- Methods ---------------------
|
||||
|
||||
def isInside(self, pts):
|
||||
def isInside(self, pts, locType='N'):
|
||||
"""
|
||||
Determines if a set of points are inside a mesh.
|
||||
|
||||
@@ -334,15 +334,23 @@ class TensorMesh(BaseTensorMesh, TensorView, DiffOperators, InnerProducts):
|
||||
:return inside, numpy array of booleans
|
||||
"""
|
||||
|
||||
pts = np.atleast_2d(pts)
|
||||
inside = (pts[:,0] >= self.vectorNx.min()) & (pts[:,0] <= self.vectorNx.max())
|
||||
tensors = self.getTensor(locType)
|
||||
if type(pts) == list:
|
||||
pts = np.array(pts)
|
||||
assert type(pts) == np.ndarray, "must be a numpy array"
|
||||
if self.dim > 1:
|
||||
inside = inside & ((pts[:,1] >= self.vectorNy.min()) & (pts[:,1] <= self.vectorNy.max()))
|
||||
if self.dim > 2:
|
||||
inside = inside & ((pts[:,2] >= self.vectorNz.min()) & (pts[:,2] <= self.vectorNz.max()))
|
||||
assert pts.shape[1] == self.dim, "must be a column vector of shape (nPts, mesh.dim)"
|
||||
elif len(pts.shape) == 1:
|
||||
pts = pts[:,np.newaxis]
|
||||
else:
|
||||
assert pts.shape[1] == self.dim, "must be a column vector of shape (nPts, mesh.dim)"
|
||||
|
||||
inside = np.ones(pts.shape[0],dtype=bool)
|
||||
for i, tensor in enumerate(tensors):
|
||||
inside = inside & (pts[:,i] >= tensor.min()) & (pts[:,i] <= tensor.max())
|
||||
return inside
|
||||
|
||||
def getInterpolationMat(self, loc, locType):
|
||||
def getInterpolationMat(self, loc, locType, zerosOutside=False):
|
||||
""" Produces interpolation matrix
|
||||
|
||||
:param numpy.ndarray loc: Location of points to interpolate to
|
||||
@@ -362,8 +370,21 @@ class TensorMesh(BaseTensorMesh, TensorView, DiffOperators, InnerProducts):
|
||||
'CC' -> scalar field defined on cell centers
|
||||
"""
|
||||
|
||||
loc = np.atleast_2d(loc)
|
||||
assert np.all(self.isInside(loc)), "Points outside of mesh"
|
||||
if type(loc) == list:
|
||||
loc = np.array(loc)
|
||||
assert type(loc) == np.ndarray, "must be a numpy array"
|
||||
if self.dim > 1:
|
||||
assert loc.shape[1] == self.dim, "must be a column vector of shape (nPts, mesh.dim)"
|
||||
elif len(loc.shape) == 1:
|
||||
loc = loc[:,np.newaxis]
|
||||
else:
|
||||
assert loc.shape[1] == self.dim, "must be a column vector of shape (nPts, mesh.dim)"
|
||||
|
||||
if zerosOutside is False:
|
||||
assert np.all(self.isInside(loc)), "Points outside of mesh"
|
||||
else:
|
||||
indZeros = np.logical_not(self.isInside(loc))
|
||||
loc[indZeros, :] = np.array([v.mean() for v in self.getTensor('CC')])
|
||||
|
||||
ind = 0 if 'x' in locType else 1 if 'y' in locType else 2 if 'z' in locType else -1
|
||||
if locType in ['Fx','Fy','Fz','Ex','Ey','Ez'] and self.dim >= ind:
|
||||
@@ -375,7 +396,9 @@ class TensorMesh(BaseTensorMesh, TensorView, DiffOperators, InnerProducts):
|
||||
Q = Utils.interpmat(loc, *self.getTensor(locType))
|
||||
else:
|
||||
raise NotImplementedError('getInterpolationMat: locType=='+locType+' and mesh.dim=='+str(self.dim))
|
||||
return Q
|
||||
if zerosOutside:
|
||||
Q[indZeros, :] = 0
|
||||
return Q.tocsr()
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Welcome to tensor mesh!')
|
||||
|
||||
+2
-10
@@ -243,7 +243,7 @@ class TensorView(object):
|
||||
ax=None, clim=None, showIt=False,
|
||||
gridOpts={'color':'k'}
|
||||
):
|
||||
viewOpts = ['real','imag','abs','vec','|vec|']
|
||||
viewOpts = ['real','imag','abs','vec']
|
||||
normalOpts = ['X', 'Y', 'Z']
|
||||
vTypeOpts = ['CC','F','E']
|
||||
|
||||
@@ -258,11 +258,6 @@ class TensorView(object):
|
||||
if ind is None: ind = int(szSliceDim/2)
|
||||
assert type(ind) in [int, long], 'ind must be an integer'
|
||||
|
||||
normalizeVector = False
|
||||
if view == '|vec|':
|
||||
view = 'vec'
|
||||
normalizeVector = True
|
||||
|
||||
if ax is None:
|
||||
fig = plt.figure(1)
|
||||
fig.clf()
|
||||
@@ -313,10 +308,7 @@ class TensorView(object):
|
||||
if clim is None:
|
||||
clim = [v.min(),v.max()]
|
||||
out += (ax.pcolormesh(tM.vectorNx, tM.vectorNy, 0.5*(U+V).T, vmin=clim[0], vmax=clim[1]),)
|
||||
if normalizeVector:
|
||||
length = np.sqrt(U**2+V**2)
|
||||
U, V = U/length, V/length
|
||||
out += (quiver( tM.gridCC[:,0], tM.gridCC[:,1], U, V),)
|
||||
out += (plt.streamplot(tM.vectorCCx, tM.vectorCCy, U.T, V.T),)
|
||||
|
||||
if grid:
|
||||
xXGrid = np.c_[tM.vectorNx,tM.vectorNx,np.nan*np.ones(tM.nNx)].flatten()
|
||||
|
||||
Reference in New Issue
Block a user