Tensor Mesh¶

class
discretize.
TensorMesh
(h=None, x0=None, **kwargs)[source]¶ Bases:
discretize.TensorMesh.BaseTensorMesh
,discretize.BaseMesh.BaseRectangularMesh
,discretize.View.TensorView
,discretize.DiffOperators.DiffOperators
,discretize.InnerProducts.InnerProducts
,discretize.MeshIO.TensorMeshIO
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’.
hx = np.array([1, 1, 1]) hy = np.array([1, 2]) hz = np.array([1, 1, 1, 1]) mesh = Mesh.TensorMesh([hx, hy, hz])
Example of a padded tensor mesh using
discretize.utils.meshutils.meshTensor()
:import discretize M = discretize.TensorMesh([ [(10, 10, 1.3), (10, 40), (10, 10, 1.3)], [(10, 10, 1.3), (10, 20)] ]) M.plotGrid()
(Source code, png, hires.png, pdf)
For a quick tensor mesh on a (10x12x15) unit cube:
mesh = discretize.TensorMesh([10, 12, 15])
Required Properties:
 axis_u (
Vector3
): Vector orientation of udirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: X  axis_v (
Vector3
): Vector orientation of vdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Y  axis_w (
Vector3
): Vector orientation of wdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Z  h (a list of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a list (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 0 and 3  reference_system (
String
): The type of coordinate reference frame. Can take on the values cartesian, cylindrical, or spherical. Abbreviations of these are allowed., a unicode string, Default: cartesian  x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

vol
¶ Construct cell volumes of the 3D model as 1d array.

areaFx
¶ Area of the xfaces

areaFy
¶ Area of the yfaces

areaFz
¶ Area of the zfaces

area
¶ Construct face areas of the 3D model as 1d array.

edgeEx
¶ xedge lengths

edgeEy
¶ yedge lengths

edgeEz
¶ zedge lengths

edge
¶ Construct edge legnths of the 3D model as 1d array.

faceBoundaryInd
¶ Find indices of boundary faces in each direction

cellBoundaryInd
¶ Find indices of boundary faces in each direction
 axis_u (
Cylindrical Mesh¶

class
discretize.
CylMesh
(h=None, x0=None, **kwargs)[source]¶ Bases:
discretize.TensorMesh.BaseTensorMesh
,discretize.BaseMesh.BaseRectangularMesh
,discretize.InnerProducts.InnerProducts
,discretize.View.CylView
,discretize.DiffOperators.DiffOperators
CylMesh is a mesh class for cylindrical problems
Note
for a cylindrically symmetric mesh use [hx, 1, hz]
cs, nc, npad = 20., 30, 8 hx = utils.meshTensor([(cs,npad+10,0.7), (cs,nc), (cs,npad,1.3)]) hz = utils.meshTensor([(cs,npad ,1.3), (cs,nc), (cs,npad,1.3)]) mesh = Mesh.CylMesh([hx,1,hz], [0.,0,hz.sum()/2.])
Required Properties:
 axis_u (
Vector3
): Vector orientation of udirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: X  axis_v (
Vector3
): Vector orientation of vdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Y  axis_w (
Vector3
): Vector orientation of wdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Z  cartesianOrigin (
Array
): Cartesian origin of the mesh, a list or numpy array of <class ‘float’> with shape (*)  h (a list of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a list (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 0 and 3  reference_system (
String
): The type of coordinate reference frame. Can take on the values cartesian, cylindrical, or spherical. Abbreviations of these are allowed., a unicode string, Default: cartesian  x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

cartesianOrigin
¶ cartesianOrigin (
Array
): Cartesian origin of the mesh, a list or numpy array of <class ‘float’> with shape (*)

isSymmetric
¶ Is the mesh cylindrically symmetric?
Return type: bool Returns: True if the mesh is cylindrically symmetric, False otherwise

vnFx
¶ Number of xfaces in each direction
Return type: numpy.ndarray Returns: vnFx, (dim, )

vnEy
¶ Number of yedges in each direction
Return type: numpy.ndarray Returns: vnEy or None if dim < 2, (dim, )

vnEz
¶ Number of zedges in each direction
Return type: numpy.ndarray Returns: vnEz or None if nCy > 1, (dim, )

vectorCCx
¶ Cellcentered grid vector (1D) in the x direction.

vectorCCy
¶ Cellcentered grid vector (1D) in the y direction.

vectorNx
¶ Nodal grid vector (1D) in the x direction.

vectorNy
¶ Nodal grid vector (1D) in the y direction.

edgeEx
¶ xedge lengths  these are the radial edges. Radial edges only exist for a 3D cyl mesh.
Return type: numpy.ndarray Returns: vector of radial edge lengths

edgeEy
¶ yedge lengths  these are the azimuthal edges. Azimuthal edges exist for all cylindrical meshes. These are arclengths (:math:` heta r`)
Return type: numpy.ndarray Returns: vector of the azimuthal edges

edgeEz
¶ zedge lengths  these are the vertical edges. Vertical edges only exist for a 3D cyl mesh.
Return type: numpy.ndarray Returns: vector of the vertical edges

edge
¶ Edge lengths
Return type: numpy.ndarray Returns: vector of edge lengths \((r, heta, z)\)

areaFx
¶ Area of the xfaces (radial faces). Radial faces exist on all cylindrical meshes
\[A_x = r heta h_z\]Return type: numpy.ndarray Returns: area of xfaces

areaFy
¶ Area of yfaces (Azimuthal faces). Azimuthal faces exist only on 3D cylindrical meshes.
\[A_y = h_x h_z\]Return type: numpy.ndarray Returns: area of yfaces

areaFz
¶ Area of zfaces.
\[A_z = \frac{ heta}{2} (r_2^2  r_1^2)z\]Return type: numpy.ndarray Returns: area of the zfaces

area
¶ Face areas
For a 3D cyl mesh: [radial, azimuthal, vertical], while a cylindrically symmetric mesh doesn’t have yFaces, so it returns [radial, vertical]
Return type: numpy.ndarray Returns: face areas

vol
¶ Volume of each cell
Return type: numpy.ndarray Returns: cell volumes

gridN
¶ Nodal grid in cylindrical coordinates \((r, heta, z)\). Nodes do not exist in a cylindrically symmetric mesh.
Return type: numpy.ndarray Returns: grid locations of nodes

gridFx
¶ Grid of xfaces (radialfaces) in cylindrical coordinates \((r, heta, z)\).
Return type: numpy.ndarray Returns: grid locations of radial faces

gridEy
¶ Grid of yedges (azimuthalfaces) in cylindrical coordinates \((r, heta, z)\).
Return type: numpy.ndarray Returns: grid locations of azimuthal faces

gridEz
¶ Grid of zfaces (verticalfaces) in cylindrical coordinates \((r, heta, z)\).
Return type: numpy.ndarray Returns: grid locations of radial faces

faceDiv
¶ Construct divergence operator (faces to cellcentres).

faceDivx
¶ Construct divergence operator in the x component (faces to cellcentres).

faceDivy
¶ Construct divergence operator in the y component (faces to cellcentres).

faceDivz
¶ Construct divergence operator in the z component (faces to cellcentres).

cellGradx
¶

cellGrad
¶ The cell centered Gradient, takes you to cell faces.

nodalGrad
¶ Construct gradient operator (nodes to edges).

nodalLaplacian
¶ Construct laplacian operator (nodes to edges).

edgeCurl
¶ The edgeCurl (edges to faces)
Return type: scipy.sparse.csr_matrix Returns: edge curl operator

aveEx2CC
¶ averaging operator of xedges (radial) to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from xedges to cell centers

aveEy2CC
¶ averaging operator of yedges (azimuthal) to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from yedges to cell centers

aveEz2CC
¶ averaging operator of zedges to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from zedges to cell centers

aveE2CC
¶ averaging operator of edges to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from edges to cell centers

aveE2CCV
¶ averaging operator of edges to a cell centered vector
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from edges to cell centered vectors

aveFx2CC
¶ averaging operator of xfaces (radial) to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from xfaces to cell centers

aveFy2CC
¶ averaging operator of yfaces (azimuthal) to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from yfaces to cell centers

aveFz2CC
¶ averaging operator of zfaces (vertical) to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from zfaces to cell centers

aveF2CC
¶ averaging operator of faces to cell centers
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from faces to cell centers

aveF2CCV
¶ averaging operator of xfaces (radial) to cell centered vectors
Return type: scipy.sparse.csr_matrix Returns: matrix that averages from faces to cell centered vectors

getInterpolationMat
(loc, locType='CC', zerosOutside=False)[source]¶ Produces interpolation matrix
Parameters:  loc (numpy.ndarray) – Location of points to interpolate to
 locType (str) – What to interpolate (see below)
Return type: Returns: M, the interpolation matrix
locType can be:
'Ex' > xcomponent of field defined on edges 'Ey' > ycomponent of field defined on edges 'Ez' > zcomponent of field defined on edges 'Fx' > xcomponent of field defined on faces 'Fy' > ycomponent of field defined on faces 'Fz' > zcomponent of field defined on faces 'N' > scalar field defined on nodes 'CC' > scalar field defined on cell centers 'CCVx' > xcomponent of vector field defined on cell centers 'CCVy' > ycomponent of vector field defined on cell centers 'CCVz' > zcomponent of vector field defined on cell centers

cartesianGrid
(locType='CC', theta_shift=None)[source]¶ Takes a grid location (‘CC’, ‘N’, ‘Ex’, ‘Ey’, ‘Ez’, ‘Fx’, ‘Fy’, ‘Fz’) and returns that grid in cartesian coordinates
Parameters: locType (str) – grid location Return type: numpy.ndarray Returns: cartesian coordinates for the cylindrical grid

getInterpolationMatCartMesh
(Mrect, locType='CC', locTypeTo=None)[source]¶ Takes a cartesian mesh and returns a projection to translate onto the cartesian grid.
Parameters:  Mrect (discretize.BaseMesh.BaseMesh) – the mesh to interpolate on to
 locType (str) – grid location (‘CC’, ‘N’, ‘Ex’, ‘Ey’, ‘Ez’, ‘Fx’, ‘Fy’, ‘Fz’)
 locTypeTo (str) – grid location to interpolate to. If None, the same grid type as locType will be assumed
 axis_u (
Tree Mesh¶

class
discretize.
TreeMesh
(h, x0=None, **kwargs)[source]¶ Bases:
discretize.tree_ext._TreeMesh
,discretize.TensorMesh.BaseTensorMesh
,discretize.InnerProducts.InnerProducts
,discretize.MeshIO.TreeMeshIO
Required Properties:
 axis_u (
Vector3
): Vector orientation of udirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: X  axis_v (
Vector3
): Vector orientation of vdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Y  axis_w (
Vector3
): Vector orientation of wdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Z  h (a list of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a list (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 0 and 3  reference_system (
String
): The type of coordinate reference frame. Can take on the values cartesian, cylindrical, or spherical. Abbreviations of these are allowed., a unicode string, Default: cartesian  x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

vntF
¶

vntE
¶

cellGradStencil
¶

cellGrad
¶ Cell centered Gradient operator built off of the faceDiv operator. Grad =  (Mf)^{1} * Div * diag (volume)

cellGradx
¶ Cell centered Gradient operator in xdirection (Gradx) Grad = sp.vstack((Gradx, Grady, Gradz))

cellGrady
¶ Cell centered Gradient operator in ydirection (Gradx) Grad = sp.vstack((Gradx, Grady, Gradz))

cellGradz
¶ Cell centered Gradient operator in zdirection (Gradz) Grad = sp.vstack((Gradx, Grady, Gradz))

faceDivx
¶

faceDivy
¶

faceDivz
¶

permuteCC
¶

permuteF
¶

permuteE
¶
 axis_u (
Curvilinear Mesh¶

class
discretize.
CurvilinearMesh
(nodes=None, **kwargs)[source]¶ Bases:
discretize.BaseMesh.BaseRectangularMesh
,discretize.DiffOperators.DiffOperators
,discretize.InnerProducts.InnerProducts
,discretize.View.CurviView
CurvilinearMesh is a mesh class that deals with curvilinear meshes.
Example of a curvilinear mesh:
import discretize X, Y = discretize.utils.exampleLrmGrid([3,3],'rotate') M = discretize.CurvilinearMesh([X, Y]) M.plotGrid(showIt=True)
(Source code, png, hires.png, pdf)
Required Properties:
 axis_u (
Vector3
): Vector orientation of udirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: X  axis_v (
Vector3
): Vector orientation of vdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Y  axis_w (
Vector3
): Vector orientation of wdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Z  nodes (a list of
Array
): List of arrays describing the node locations, a list (each item is a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*, *, *) or (*, *)) with length between 2 and 3  reference_system (
String
): The type of coordinate reference frame. Can take on the values cartesian, cylindrical, or spherical. Abbreviations of these are allowed., a unicode string, Default: cartesian  x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

nodes
¶ nodes (a list of
Array
): List of arrays describing the node locations, a list (each item is a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*, *, *) or (*, *)) with length between 2 and 3

gridCC
¶ Cellcentered grid

gridN
¶ Nodal grid.

gridFx
¶ Face staggered grid in the x direction.

gridFy
¶ Face staggered grid in the y direction.

gridFz
¶ Face staggered grid in the y direction.

gridEx
¶ Edge staggered grid in the x direction.

gridEy
¶ Edge staggered grid in the y direction.

gridEz
¶ Edge staggered grid in the z direction.

vol
¶ Construct cell volumes of the 3D model as 1d array

area
¶

normals
¶ Face normals: calling this will average the computed normals so that there is one per face. This is especially relevant in 3D, as there are up to 4 different normals for each face that will be different.
To reshape the normals into a matrix and get the y component:
NyX, NyY, NyZ = M.r(M.normals, 'F', 'Fy', 'M')

edge
¶ Edge lengths

tangents
¶ Edge tangents
 axis_u (
Base Rectangular Mesh¶

class
discretize.BaseMesh.
BaseRectangularMesh
(n, x0=None, **kwargs)[source]¶ Bases:
discretize.BaseMesh.BaseMesh
Required Properties:
 axis_u (
Vector3
): Vector orientation of udirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: X  axis_v (
Vector3
): Vector orientation of vdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Y  axis_w (
Vector3
): Vector orientation of wdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Z  reference_system (
String
): The type of coordinate reference frame. Can take on the values cartesian, cylindrical, or spherical. Abbreviations of these are allowed., a unicode string, Default: cartesian  x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

vnC
¶ Total number of cells in each direction
Return type: numpy.ndarray Returns: [nCx, nCy, nCz]

vnN
¶ Total number of nodes in each direction
Return type: numpy.ndarray Returns: [nNx, nNy, nNz]

vnEx
¶ Number of xedges in each direction
Return type: numpy.ndarray Returns: vnEx

vnEy
¶ Number of yedges in each direction
Return type: numpy.ndarray Returns: vnEy or None if dim < 2

vnEz
¶ Number of zedges in each direction
Return type: numpy.ndarray Returns: vnEz or None if dim < 3

vnFx
¶ Number of xfaces in each direction
Return type: numpy.ndarray Returns: vnFx

vnFy
¶ Number of yfaces in each direction
Return type: numpy.ndarray Returns: vnFy or None if dim < 2

vnFz
¶ Number of zfaces in each direction
Return type: numpy.ndarray Returns: vnFz or None if dim < 3

r
(x, xType='CC', outType='CC', format='V')[source]¶ r is a quick reshape command that will do the best it can at giving you what you want.
For example, you have a face variable, and you want the x component of it reshaped to a 3D matrix.
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 }
For example:
..code:
# Separates each component of the Ex grid into 3 matrices Xex, Yex, Zex = r(mesh.gridEx, 'Ex', 'Ex', 'M') # Given an edge vector, return just the x edges as a vector XedgeVector = r(edgeVector, 'E', 'Ex', 'V') # Separates each component of the edgeVector into 3 vectors eX, eY, eZ = r(edgeVector, 'E', 'E', 'V')
 axis_u (
Base Tensor Mesh¶

class
discretize.TensorMesh.
BaseTensorMesh
(h=None, x0=None, **kwargs)[source]¶ Bases:
discretize.BaseMesh.BaseMesh
Required Properties:
 axis_u (
Vector3
): Vector orientation of udirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: X  axis_v (
Vector3
): Vector orientation of vdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Y  axis_w (
Vector3
): Vector orientation of wdirection. For more details see the docs for therotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default: Z  h (a list of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a list (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 0 and 3  reference_system (
String
): The type of coordinate reference frame. Can take on the values cartesian, cylindrical, or spherical. Abbreviations of these are allowed., a unicode string, Default: cartesian  x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)

h
¶ h (a list of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a list (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 0 and 3

hx
¶ Width of cells in the x direction

hy
¶ Width of cells in the y direction

hz
¶ Width of cells in the z direction

vectorNx
¶ Nodal grid vector (1D) in the x direction.

vectorNy
¶ Nodal grid vector (1D) in the y direction.

vectorNz
¶ Nodal grid vector (1D) in the z direction.

vectorCCx
¶ Cellcentered grid vector (1D) in the x direction.

vectorCCy
¶ Cellcentered grid vector (1D) in the y direction.

vectorCCz
¶ Cellcentered grid vector (1D) in the z direction.

gridCC
¶ Cellcentered grid.

gridN
¶ Nodal grid.

h_gridded
¶ Returns an (nC, dim) numpy array with the widths of all cells in order

gridFx
¶ Face staggered grid in the x direction.

gridFy
¶ Face staggered grid in the y direction.

gridFz
¶ Face staggered grid in the z direction.

gridEx
¶ Edge staggered grid in the x direction.

gridEy
¶ Edge staggered grid in the y direction.

gridEz
¶ Edge staggered grid in the z direction.

getTensor
(key)[source]¶ Returns a tensor list.
Parameters: key (str) – What tensor (see below) Return type: list Returns: list of the tensors that make up the mesh. key can be:
'CC' > scalar field defined on cell centers 'N' > scalar field defined on nodes 'Fx' > xcomponent of field defined on faces 'Fy' > ycomponent of field defined on faces 'Fz' > zcomponent of field defined on faces 'Ex' > xcomponent of field defined on edges 'Ey' > ycomponent of field defined on edges 'Ez' > zcomponent of field defined on edges

isInside
(pts, locType='N')[source]¶ Determines if a set of points are inside a mesh.
Parameters: pts (numpy.ndarray) – Location of points to test Return type: numpy.ndarray Returns: inside, numpy array of booleans

getInterpolationMat
(loc, locType='CC', zerosOutside=False)[source]¶ Produces interpolation matrix
Parameters:  loc (numpy.ndarray) – Location of points to interpolate to
 locType (str) – What to interpolate (see below)
Return type: Returns: M, the interpolation matrix
locType can be:
'Ex' > xcomponent of field defined on edges 'Ey' > ycomponent of field defined on edges 'Ez' > zcomponent of field defined on edges 'Fx' > xcomponent of field defined on faces 'Fy' > ycomponent of field defined on faces 'Fz' > zcomponent of field defined on faces 'N' > scalar field defined on nodes 'CC' > scalar field defined on cell centers 'CCVx' > xcomponent of vector field defined on cell centers 'CCVy' > ycomponent of vector field defined on cell centers 'CCVz' > zcomponent of vector field defined on cell centers
 axis_u (
Mesh IO¶

discretize.MeshIO.
load_mesh
(filename)[source]¶ Open a json file and load the mesh into the target class
As long as there are no namespace conflicts, the target __class__ will be stored on the properties.HasProperties registry and may be fetched from there.
Parameters: filename (str) – name of file to read in

class
discretize.MeshIO.
TensorMeshIO
[source]¶ Bases:
object

classmethod
readUBC
(TensorMesh, fileName, directory='')[source]¶ Wrapper to Read UBC GIF 2D and 3D tensor mesh and generate same dimension TensorMesh.
Input: :param str fileName: path to the UBC GIF mesh file or just its name if directory is specified :param str directory: directory where the UBC GIF file lives
Output: :rtype: TensorMesh :return: The tensor mesh for the fileName.

readModelUBC
(mesh, fileName, directory='')[source]¶  Read UBC 2D or 3D Tensor mesh model
 and generate Tensor mesh model
Input: :param str fileName: path to the UBC GIF mesh file to read or just its name if directory is specified :param str directory: directory where the UBC GIF file lives
Output: :rtype: numpy.ndarray :return: model with TensorMesh ordered

writeModelUBC
(mesh, fileName, model, directory='')[source]¶ Writes a model associated with a TensorMesh to a UBCGIF format model file.
Input: :param str fileName: File to write to or just its name if directory is specified :param str directory: directory where the UBC GIF file lives :param numpy.ndarray model: The model

writeUBC
(mesh, fileName, models=None, directory='', comment_lines='')[source]¶ Writes a TensorMesh to a UBCGIF format mesh file.
Input: :param str fileName: File to write to :param str directory: directory where to save model :param dict models: A dictionary of the models :param str comment_lines: comment lines preceded with ‘!’ to add

classmethod

class
discretize.MeshIO.
TreeMeshIO
[source]¶ Bases:
object

classmethod
readUBC
(TreeMesh, meshFile)[source]¶ Read UBC 3D OcTree mesh file Input: :param str meshFile: path to the UBC GIF OcTree mesh file to read :rtype: discretize.TreeMesh :return: The octree mesh

classmethod
Mesh Viewing¶

class
discretize.View.
TensorView
[source]¶ Bases:
object
Provides viewing functions for TensorMesh
This class is inherited by TensorMesh

plotImage
(v)[source]¶ Plots scalar fields on the given mesh.
Input:
Parameters: v (numpy.ndarray) – vector Optional Inputs:
Parameters:  vType (str) – type of vector (‘CC’, ‘N’, ‘F’, ‘Fx’, ‘Fy’, ‘Fz’, ‘E’, ‘Ex’, ‘Ey’, ‘Ez’)
 ax (matplotlib.axes.Axes) – axis to plot to
 showIt (bool) – call plt.show()
3D Inputs:
Parameters: import discretize import numpy as np M = discretize.TensorMesh([20, 20]) v = np.sin(M.gridCC[:, 0]*2*np.pi)*np.sin(M.gridCC[:, 1]*2*np.pi) M.plotImage(v, showIt=True)
(Source code, png, hires.png, pdf)
import discretize import numpy as np M = discretize.TensorMesh([20, 20, 20]) v = np.sin(M.gridCC[:, 0]*2*np.pi)*np.sin(M.gridCC[:, 1]*2*np.pi)*np.sin(M.gridCC[:, 2]*2*np.pi) M.plotImage(v, annotationColor='k', showIt=True)
(Source code, png, hires.png, pdf)

plotSlice
(v, vType='CC', normal='Z', ind=None, grid=False, view='real', ax=None, clim=None, showIt=False, pcolorOpts=None, streamOpts=None, gridOpts=None, range_x=None, range_y=None, sample_grid=None, stream_threshold=None, stream_thickness=None)[source]¶ Plots a slice of a 3D mesh.
(Source code, png, hires.png, pdf)

plotGrid
(ax=None, nodes=False, faces=False, centers=False, edges=False, lines=True, showIt=False, **kwargs)[source]¶ Plot the nodal, cellcentered and staggered grids for 1,2 and 3 dimensions.
Parameters: import discretize import numpy as np h1 = np.linspace(.1, .5, 3) h2 = np.linspace(.1, .5, 5) mesh = discretize.TensorMesh([h1, h2]) mesh.plotGrid(nodes=True, faces=True, centers=True, lines=True, showIt=True)
(Source code, png, hires.png, pdf)
import discretize import numpy as np h1 = np.linspace(.1, .5, 3) h2 = np.linspace(.1, .5, 5) h3 = np.linspace(.1, .5, 3) mesh = discretize.TensorMesh([h1, h2, h3]) mesh.plotGrid(nodes=True, faces=True, centers=True, lines=True, showIt=True)
(Source code, png, hires.png, pdf)

plot_3d_slicer
(v, xslice=None, yslice=None, zslice=None, vType='CC', view='real', axis='xy', transparent=None, clim=None, aspect='auto', grid=[2, 2, 1], pcolorOpts=None)[source]¶ Plot slices of a 3D volume, interactively (scroll wheel).
If called from a notebook, make sure to set
%matplotlib notebookSee the class discretize.View.Slicer for more information.
It returns nothing. However, if you need the different figure handles you can get it via
fig = plt.gcf()and subsequently its children via
fig.get_children()and recursively deeper, e.g.,
fig.get_children()[0].get_children().


class
discretize.View.
CurviView
[source]¶ Bases:
object
Provides viewing functions for CurvilinearMesh
This class is inherited by CurvilinearMesh

plotGrid
(ax=None, nodes=False, faces=False, centers=False, edges=False, lines=True, showIt=False, **kwargs)[source]¶ Plot the nodal, cellcentered and staggered grids for 1, 2 and 3 dimensions.
import discretize X, Y = discretize.utils.exampleLrmGrid([3, 3], 'rotate') M = discretize.CurvilinearMesh([X, Y]) M.plotGrid(showIt=True)
(Source code, png, hires.png, pdf)


class
discretize.View.
Slicer
(mesh, v, xslice=None, yslice=None, zslice=None, vType='CC', view='real', axis='xy', transparent=None, clim=None, aspect='auto', grid=[2, 2, 1], pcolorOpts=None)[source]¶ Bases:
object
Plot slices of a 3D volume, interactively (scroll wheel).
If called from a notebook, make sure to set
%matplotlib notebookThe straight forward usage for the Slicer is through, e.g., a TensorMeshmesh, by accessing its mesh.plot_3d_slicer.
If you, however, call this class directly, you have first to initiate a figure, and afterwards connect it:
>>> # You have to initialize a figure >>> fig = plt.figure() >>> # Then you have to get the tracker from the Slicer >>> tracker = discretize.View.Slicer(mesh, Lpout) >>> # Finally you have to connect the tracker to the figure >>> fig.canvas.mpl_connect('scroll_event', tracker.onscroll) >>> plt.show()
Parameters
 v : array
 Data array of length self.nC.
 xslice, yslice, zslice : floats, optional
 Initial slice locations (in meter); defaults to the middle of the volume.
 vType: str
 Type of visualization. Default is ‘CC’. One of [‘CC’, ‘Fx’, ‘Fy’, ‘Fz’, ‘Ex’, ‘Ey’, ‘Ez’].
 view : str
 Which component to show. Defaults to ‘real’. One of [‘real’, ‘imag’, ‘abs’].
 axis : ‘xy’ (default) or ‘yx’
 ‘xy’: horizontal axis is x, vertical axis is y. Reversed otherwise.
 transparent : ‘slider’ or list of floats or pairs of floats, optional
 Values to be removed. E.g. air, water. If single value, only exact matches are removed. Pairs are treated as ranges. E.g. [0.3, [1, 4], [np.infty, 10]] removes all values equal to 0.3, all values between 1 and 4, and all values smaller than 10. If ‘slider’ is provided it will plot an interactive slider to choose the shown range.
 clim : None or list of [min, max]
 For pcolormesh (vmin, vmax).
 aspect : ‘auto’, ‘equal’, or num
Aspect ratio of subplots. Defaults to ‘auto’.
A list of two values can be provided. The first will be for the XYplot, the second for the XZ and YZplots, e.g. [‘equal’, 2] to have the vertical dimension exaggerated by a factor of 2.
 WARNING: For anything else than ‘auto’, unexpected things might happen
 when zooming, and the subplotarrangement won’t look pretty.
 grid : list of 3 int
 Number of cells occupied by x, y, and z dimension on plt.subplot2grid.
 pcolorOpts : dictionary
 Passed to pcolormesh.