From b66c63759d8cd76a79c5a83698612897aa5f29a5 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Fri, 30 Aug 2013 22:17:05 -0700 Subject: [PATCH] Moved modelBuilder into utils added some documentation --- SimPEG/BaseMesh.py | 41 +++++++++++-------- SimPEG/TensorMesh.py | 21 ++++++---- .../{parameters.py => utils/ModelBuilder.py} | 8 ++-- SimPEG/utils/__init__.py | 3 +- SimPEG/utils/{utils.py => matutils.py} | 0 5 files changed, 43 insertions(+), 30 deletions(-) rename SimPEG/{parameters.py => utils/ModelBuilder.py} (97%) rename SimPEG/utils/{utils.py => matutils.py} (100%) diff --git a/SimPEG/BaseMesh.py b/SimPEG/BaseMesh.py index c5a7121a..fd799dea 100644 --- a/SimPEG/BaseMesh.py +++ b/SimPEG/BaseMesh.py @@ -59,22 +59,22 @@ class BaseMesh(object): For example, you have a face variable, and you want the x component of it reshaped to a 3D matrix. - Mesh.r can fulfil your dreams... + Mesh.r can fulfil your dreams:: - mesh.r(V, 'F', 'Fx', 'M') - | | | { How: 'M' or ['V'] for a matrix (ndgrid style) or a vector (n x dim) } - | | { What you want: ['CC'], 'N', 'F', 'Fx', 'Fy', 'Fz', 'E', 'Ex', 'Ey', or 'Ez' } - | { What is it: ['CC'], 'N', 'F', 'Fx', 'Fy', 'Fz', 'E', 'Ex', 'Ey', or 'Ez' } - { The input: as a list or ndarray } + mesh.r(V, 'F', 'Fx', 'M') + | | | { How: 'M' or ['V'] for a matrix (ndgrid style) or a vector (n x dim) } + | | { What you want: ['CC'], 'N', 'F', 'Fx', 'Fy', 'Fz', 'E', 'Ex', 'Ey', or 'Ez' } + | { What is it: ['CC'], 'N', 'F', 'Fx', 'Fy', 'Fz', 'E', 'Ex', 'Ey', or 'Ez' } + { The input: as a list or ndarray } - For example: + For example:: - Xex, Yex, Zex = r(mesh.gridEx, 'Ex', 'Ex', 'M') # Separates each component of the Ex grid into 3 matrices + Xex, Yex, Zex = r(mesh.gridEx, 'Ex', 'Ex', 'M') # Separates each component of the Ex grid into 3 matrices - XedgeVector = r(edgeVector, 'E', 'Ex', 'V') # Given an edge vector, this will return just the part on the x edges as a vector + XedgeVector = r(edgeVector, 'E', 'Ex', 'V') # Given an edge vector, this will return just the part on the x edges as a vector - eX, eY, eZ = r(edgeVector, 'E', 'E', 'V') # Separates each component of the edgeVector into 3 vectors + eX, eY, eZ = r(edgeVector, 'E', 'E', 'V') # Separates each component of the edgeVector into 3 vectors """ assert (type(x) == list or type(x) == np.ndarray), "x must be either a list or a ndarray" @@ -341,18 +341,25 @@ class BaseMesh(object): tangents = property(**tangents()) def projectFaceVector(self, fV): - """Given a vector, fV, in cartesian coordinates, this will project it onto the mesh using the normals""" + """ + Given a vector, fV, in cartesian coordinates, this will project it onto the mesh using the normals + + :param numpy.array fV: face vector with shape (nF, dim) + :rtype: numpy.array with shape (nF, ) + :return: projected face vector + """ 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""" + """ + Given a vector, eV, in cartesian coordinates, this will project it onto the mesh using the tangents + + :param numpy.array eV: edge vector with shape (nE, dim) + :rtype: numpy.array with shape (nE, ) + :return: projected edge vector + """ 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/TensorMesh.py b/SimPEG/TensorMesh.py index ebea0b86..36c532bc 100644 --- a/SimPEG/TensorMesh.py +++ b/SimPEG/TensorMesh.py @@ -8,18 +8,21 @@ from utils import ndgrid, mkvc class TensorMesh(BaseMesh, TensorView, DiffOperators, InnerProducts): """ - TensorMesh is a mesh class that deals with tensor product meshes. +TensorMesh is a mesh class that deals with tensor product meshes. - Any Mesh that has a constant width along the entire axis - such that it can defined by a single width vector, called 'h'. +Any Mesh that has a constant width along the entire axis +such that it can defined by a single width vector, called 'h'. - e.g. +:: - hx = np.array([1,1,1]) - hy = np.array([1,2]) - hz = np.array([1,1,1,1]) + hx = np.array([1,1,1]) + hy = np.array([1,2]) + hz = np.array([1,1,1,1]) - mesh = TensorMesh([hx, hy, hz]) + mesh = TensorMesh([hx, hy, hz]) + +.. math:: + x^2 = 5 """ _meshType = 'TENSOR' @@ -61,7 +64,7 @@ class TensorMesh(BaseMesh, TensorView, DiffOperators, InnerProducts): outStr = outStr + ' {0:d}*{1:.2f},'.format(n,h) return outStr[:-1] - + if self.dim == 1: outStr = outStr + '\n x0: {0:.2f}'.format(self.x0[0]) outStr = outStr + '\n nCx: {0:d}'.format(self.nCx) diff --git a/SimPEG/parameters.py b/SimPEG/utils/ModelBuilder.py similarity index 97% rename from SimPEG/parameters.py rename to SimPEG/utils/ModelBuilder.py index 842c96e9..3b1f977f 100644 --- a/SimPEG/parameters.py +++ b/SimPEG/utils/ModelBuilder.py @@ -1,6 +1,4 @@ import numpy as np -import TensorMesh as tm -import TensorView as tv def getIndecesBlock(p0,p1,ccMesh): @@ -129,6 +127,10 @@ def scalarConductivity(ccMesh,pFunction): if __name__ == '__main__': + import sys + sys.path.append('../') + from TensorMesh import TensorMesh + # Define the mesh testDim = 3 @@ -148,7 +150,7 @@ if __name__ == '__main__': else: h = [h1, h2, h3] - M = tm.TensorMesh(h, x0) + M = TensorMesh(h, x0) ccMesh = M.gridCC diff --git a/SimPEG/utils/__init__.py b/SimPEG/utils/__init__.py index a2463636..bb46a4e9 100644 --- a/SimPEG/utils/__init__.py +++ b/SimPEG/utils/__init__.py @@ -1,3 +1,4 @@ -from utils import getSubArray, mkvc, ndgrid, ind2sub, sub2ind +from matutils import getSubArray, mkvc, ndgrid, ind2sub, sub2ind from sputils import spzeros, kron3, speye, sdiag from lomutils import volTetra, faceInfo, inv2X2BlockDiagonal, inv3X3BlockDiagonal, indexCube, exampleLomGird +import ModelBuilder diff --git a/SimPEG/utils/utils.py b/SimPEG/utils/matutils.py similarity index 100% rename from SimPEG/utils/utils.py rename to SimPEG/utils/matutils.py