Base API

Base Rectangular Mesh

class discretize.BaseMesh.BaseRectangularMesh(n, x0=None)[source]

Bases: discretize.BaseMesh.BaseMesh

Required Properties:

  • x0 (Array): origin of the mesh (dim, ), a list or numpy array of <class ‘float’> with shape (*)
nCx

Number of cells in the x direction

Return type:int
Returns:nCx
nCy

Number of cells in the y direction

Return type:int
Returns:nCy or None if dim < 2
nCz

Number of cells in the z direction

Return type:int
Returns:nCz or None if dim < 3
vnC

Total number of cells in each direction

Return type:numpy.array
Returns:[nCx, nCy, nCz]
nNx

Number of nodes in the x-direction

Return type:int
Returns:nNx
nNy

Number of nodes in the y-direction

Return type:int
Returns:nNy or None if dim < 2
nNz

Number of nodes in the z-direction

Return type:int
Returns:nNz or None if dim < 3
vnN

Total number of nodes in each direction

Return type:numpy.array
Returns:[nNx, nNy, nNz]
vnEx

Number of x-edges in each direction

Return type:numpy.array
Returns:vnEx
vnEy

Number of y-edges in each direction

Return type:numpy.array
Returns:vnEy or None if dim < 2
vnEz

Number of z-edges in each direction

Return type:numpy.array
Returns:vnEz or None if dim < 3
vnFx

Number of x-faces in each direction

Return type:numpy.array
Returns:vnFx
vnFy

Number of y-faces in each direction

Return type:numpy.array
Returns:vnFy or None if dim < 2
vnFz

Number of z-faces in each direction

Return type:numpy.array
Returns:vnFz or None if dim < 3
nC

Total number of cells

Return type:int
Returns:nC
nN

Total number of nodes

Return type:int
Returns:nN
nEx

Number of x-edges

Return type:int
Returns:nEx
nEy

Number of y-edges

Return type:int
Returns:nEy
nEz

Number of z-edges

Return type:int
Returns:nEz
nFx

Number of x-faces

Return type:int
Returns:nFx
nFy

Number of y-faces

Return type:int
Returns:nFy
nFz

Number of z-faces

Return type:int
Returns:nFz
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')

Base Tensor Mesh

class discretize.TensorMesh.BaseTensorMesh(h=None, x0=None, **kwargs)[source]

Bases: discretize.BaseMesh.BaseMesh

Required Properties:

  • 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
  • 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

Cell-centered grid vector (1D) in the x direction.

vectorCCy

Cell-centered grid vector (1D) in the y direction.

vectorCCz

Cell-centered grid vector (1D) in the z direction.

gridCC

Cell-centered 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'    -> x-component of field defined on faces
'Fy'    -> y-component of field defined on faces
'Fz'    -> z-component of field defined on faces
'Ex'    -> x-component of field defined on edges
'Ey'    -> y-component of field defined on edges
'Ez'    -> z-component 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:

scipy.sparse.csr_matrix

Returns:

M, the interpolation matrix

locType can be:

'Ex'    -> x-component of field defined on edges
'Ey'    -> y-component of field defined on edges
'Ez'    -> z-component of field defined on edges
'Fx'    -> x-component of field defined on faces
'Fy'    -> y-component of field defined on faces
'Fz'    -> z-component of field defined on faces
'N'     -> scalar field defined on nodes
'CC'    -> scalar field defined on cell centers
'CCVx'  -> x-component of vector field defined on cell centers
'CCVy'  -> y-component of vector field defined on cell centers
'CCVz'  -> z-component of vector field defined on cell centers