Documented utilities.

This commit is contained in:
Rowan Cockett
2013-10-03 15:31:08 -07:00
parent fb69446cfb
commit 65f129e7a8
6 changed files with 61 additions and 30 deletions
+14 -11
View File
@@ -3,16 +3,18 @@ import numpy as np
def getIndecesBlock(p0,p1,ccMesh):
"""
Creates a vector containing the block indexes in the cell centerd mesh.
Returns a tuple
Creates a vector containing the block indexes in the cell centerd mesh.
Returns a tuple
The block is defined by the points
p0 : describe the position of the left upper front corner, and
p1 : describe the position of the right bottom back corner.
The block is defined by the points
ccMesh represents the cell-centered mesh
p0, describe the position of the left upper front corner, and
The points p0 and p1 must live in the the same dimensional space as the mesh.
p1, describe the position of the right bottom back corner.
ccMesh represents the cell-centered mesh
The points p0 and p1 must live in the the same dimensional space as the mesh.
"""
# Validation: p0 and p1 live in the same dimensional space
@@ -64,9 +66,9 @@ def getIndecesBlock(p0,p1,ccMesh):
def defineBlockConductivity(p0,p1,ccMesh,condVals):
"""
Build a block with the conductivity specified by condVal. Returns an array.
condVals[0] conductivity of the block
condVals[1] conductivity of the ground
Build a block with the conductivity specified by condVal. Returns an array.
condVals[0] conductivity of the block
condVals[1] conductivity of the ground
"""
sigma = np.zeros(ccMesh.shape[0]) + condVals[1]
ind = getIndecesBlock(p0,p1,ccMesh)
@@ -80,7 +82,8 @@ def defineTwoLayeredConductivity(depth,ccMesh,condVals):
Define a two layered model. Depth of the first layer must be specified.
CondVals vector with the conductivity values of the layers. Eg:
Convention to number the layers:
Convention to number the layers::
<----------------------------|------------------------------------>
0 depth zf
1st layer 2nd layer
+4 -1
View File
@@ -1,4 +1,7 @@
import matutils
import sputils
import lomutils
import ModelBuilder
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
+11 -16
View File
@@ -31,19 +31,18 @@ def volTetra(xyz, A, B, C, D):
"""
Returns the volume for tetrahedras volume specified by the indexes A to D.
:param numpy.array xyz: X,Y,Z vertex vector
:param numpy.array A,B,C,D: vert index of the tetrahedra
:rtype: numpy.array
:return: V, volume of the tetrahedra
Input:
xyz - X,Y,Z vertex vector
A,B,C,D - vert index of the tetrahedra
Algorithm http://en.wikipedia.org/wiki/Tetrahedron#Volume
Output:
V - volume
.. math::
Algorithm: http://en.wikipedia.org/wiki/Tetrahedron#Volume
V = {1 \over 3} A h
V = 1/3 A * h
V = 1/6 | ( a - d ) o ( ( b - d ) X ( c - d ) ) |
V = {1 \over 6} | ( a - d ) \cdot ( ( b - d ) ( c - d ) ) |
"""
@@ -69,7 +68,7 @@ def indexCube(nodes, gridSize, n=None):
Output:
index - index in the order asked e.g. 'ABCD' --> (A,B,C,D)
TWO DIMENSIONS:
TWO DIMENSIONS::
node(i,j) node(i,j+1)
A -------------- B
@@ -81,7 +80,7 @@ def indexCube(nodes, gridSize, n=None):
node(i+1,j) node(i+1,j+1)
THREE DIMENSIONS:
THREE DIMENSIONS::
node(i,j,k+1) node(i,j+1,k+1)
E --------------- F
@@ -97,10 +96,6 @@ def indexCube(nodes, gridSize, n=None):
D -------------- C
node(i+1,j,k) node(i+1,j+1,k)
@author Rowan Cockett
Last modified on: 2013/07/26
"""
assert type(nodes) == str, "Nodes must be a str variable: e.g. 'ABCD'"
@@ -211,7 +206,7 @@ def faceInfo(xyz, A, B, C, D, average=True, normalizeNormals=True):
#
# So also could be viewed as the average parallelogram.
#
# WARNING: This does not compute correctly for concave quadrilaterals
# TODO: This does not compute correctly for concave quadrilaterals
area = (length(nA)+length(nB)+length(nC)+length(nD))/4
return N, area
+2 -2
View File
@@ -4,7 +4,7 @@ import numpy as np
def mkvc(x, numDims=1):
"""Creates a vector with the number of dimension specified
e.g.:
e.g.::
a = np.array([1, 2, 3])
@@ -43,7 +43,7 @@ def ndgrid(*args, **kwargs):
The inputs can be a list or separate arguments.
e.g.
e.g.::
a = np.array([1, 2, 3])
b = np.array([1, 2])
+21
View File
@@ -0,0 +1,21 @@
.. _api_Utils:
Utilities
*********
.. automodule:: SimPEG.utils.matutils
:members:
:undoc-members:
.. automodule:: SimPEG.utils.sputils
:members:
:undoc-members:
.. automodule:: SimPEG.utils.lomutils
:members:
:undoc-members:
.. automodule:: SimPEG.utils.ModelBuilder
:members:
:undoc-members:
+9
View File
@@ -55,6 +55,15 @@ Testing SimPEG
api_Tests
Utility Codes
=============
.. toctree::
:maxdepth: 2
api_Utils
Project Index & Search
======================