From a510755926ceb8a9ec89fa946932bbc7ecfd9399 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Tue, 6 Aug 2013 15:07:32 -0700 Subject: [PATCH] Moved projectFace/EdgeVector to the base mesh class, along with some default normal and tangents. --- SimPEG/BaseMesh.py | 45 +++++++++++++++++++++++++++++++ SimPEG/LogicallyOrthogonalMesh.py | 12 --------- SimPEG/TensorMesh.py | 7 ----- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/SimPEG/BaseMesh.py b/SimPEG/BaseMesh.py index 9d8982e6..c5a7121a 100644 --- a/SimPEG/BaseMesh.py +++ b/SimPEG/BaseMesh.py @@ -308,6 +308,51 @@ class BaseMesh(object): return locals() nF = property(**nF()) + def normals(): + doc = "Face Normals" + + def fget(self): + if self.dim == 2: + nX = np.c_[np.ones(self.nF[0]), np.zeros(self.nF[0])] + nY = np.c_[np.zeros(self.nF[1]), np.ones(self.nF[1])] + return np.r_[nX, nY] + elif self.dim == 3: + nX = np.c_[np.ones(self.nF[0]), np.zeros(self.nF[0]), np.zeros(self.nF[0])] + nY = np.c_[np.zeros(self.nF[1]), np.ones(self.nF[1]), np.zeros(self.nF[1])] + nZ = np.c_[np.zeros(self.nF[2]), np.zeros(self.nF[2]), np.ones(self.nF[2])] + return np.r_[nX, nY, nZ] + return locals() + normals = property(**normals()) + + def tangents(): + doc = "Edge Tangents" + + def fget(self): + if self.dim == 2: + tX = np.c_[np.ones(self.nE[0]), np.zeros(self.nE[0])] + tY = np.c_[np.zeros(self.nE[1]), np.ones(self.nE[1])] + return np.r_[tX, tY] + elif self.dim == 3: + tX = np.c_[np.ones(self.nE[0]), np.zeros(self.nE[0]), np.zeros(self.nE[0])] + tY = np.c_[np.zeros(self.nE[1]), np.ones(self.nE[1]), np.zeros(self.nE[1])] + tZ = np.c_[np.zeros(self.nE[2]), np.zeros(self.nE[2]), np.ones(self.nE[2])] + return np.r_[tX, tY, tZ] + return locals() + tangents = property(**tangents()) + + def projectFaceVector(self, fV): + """Given a vector, fV, in cartesian coordinates, this will project it onto the mesh using the normals""" + assert type(fV) == np.ndarray, 'fV must be an ndarray' + assert len(fV.shape) == 2 and fV.shape[0] == np.sum(self.nF) and fV.shape[1] == self.dim, 'fV must be an ndarray of shape (nF x dim)' + return np.sum(fV*self.normals, 1) + + def projectEdgeVector(self, eV): + """Given a vector, eV, in cartesian coordinates, this will project it onto the mesh using the tangents""" + assert type(eV) == np.ndarray, 'eV must be an ndarray' + assert len(eV.shape) == 2 and eV.shape[0] == np.sum(self.nE) and eV.shape[1] == self.dim, 'eV must be an ndarray of shape (nE x dim)' + return np.sum(eV*self.tangents, 1) + + if __name__ == '__main__': m = BaseMesh([3, 2, 4]) print m.n diff --git a/SimPEG/LogicallyOrthogonalMesh.py b/SimPEG/LogicallyOrthogonalMesh.py index 71788230..cfa8b7ed 100644 --- a/SimPEG/LogicallyOrthogonalMesh.py +++ b/SimPEG/LogicallyOrthogonalMesh.py @@ -319,18 +319,6 @@ NyX, NyY, NyZ = M.r(M.normals, 'F', 'Fy', 'M') _tangents = None tangents = property(**tangents()) - def projectFaceVector(self, fV): - """Given a vector, fV, in cartesian coordinates, this will project it onto the mesh using the normals""" - assert type(fV) == np.ndarray, 'fV must be an ndarray' - assert len(fV.shape) == 2 and fV.shape[0] == np.sum(self.nF) and fV.shape[1] == self.dim, 'fV must be an ndarray of shape (nF x dim)' - return mkvc(np.sum(fV*self.normals, 1), 2) - - def projectEdgeVector(self, eV): - """Given a vector, eV, in cartesian coordinates, this will project it onto the mesh using the tangents""" - assert type(eV) == np.ndarray, 'eV must be an ndarray' - assert len(eV.shape) == 2 and eV.shape[0] == np.sum(self.nE) and eV.shape[1] == self.dim, 'eV must be an ndarray of shape (nE x dim)' - return mkvc(np.sum(eV*self.tangents, 1), 2) - if __name__ == '__main__': nc = 5 h1 = np.cumsum(np.r_[0, np.ones(nc)/(nc)]) diff --git a/SimPEG/TensorMesh.py b/SimPEG/TensorMesh.py index 5218aec1..67581e10 100644 --- a/SimPEG/TensorMesh.py +++ b/SimPEG/TensorMesh.py @@ -184,13 +184,6 @@ class TensorMesh(BaseMesh, TensorView, DiffOperators, InnerProducts): _gridEz = None # Store grid by default gridEz = property(**gridEz()) - def getBoundaryIndex(self, gridType): - """Needed for faces edges and cells""" - pass - - def getCellNumbering(self): - pass - # --------------- Geometries --------------------- def vol(): doc = "Construct cell volumes of the 3D model as 1d array."