# discretize.base.BaseTensorMesh¶

class discretize.base.BaseTensorMesh(h, origin=None, **kwargs)

Base class for tensor-product style meshes

This class contains properites and methods that are common to cartesian and cylindrical meshes defined by tensor-produts of vectors describing cell spacings.

Do not use this class directly, instead, inherit it if you plan to develop a tensor-style mesh (e.g. a spherical mesh) or use the discretize.TensorMesh() class to create a cartesian tensor mesh.

Attributes
axis_u

Deprecated since version 0.7.0.

axis_v

Deprecated since version 0.7.0.

axis_w

Deprecated since version 0.7.0.

boundary_edges

Boundary edge locations

boundary_face_outward_normals

Outward directed normal vectors for the boundary faces

boundary_faces

Boundary face locations

boundary_nodes

Boundary node locations

cell_centers

Cell-centered grid.

cell_centers_x

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

cell_centers_y

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

cell_centers_z

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

dim

The dimension of the mesh (1, 2, or 3).

edge_tangents

Edge Tangents

edges

Edge grid

edges_x

Edge staggered grid in the x direction.

edges_y

Edge staggered grid in the y direction.

edges_z

Edge staggered grid in the z direction.

face_normals

Face Normals

faces

Face grid

faces_x

Face staggered grid in the x direction.

faces_y

Face staggered grid in the y direction.

faces_z

Face staggered grid in the z direction.

h
h_gridded

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

hx

Width of cells in the x direction

hy

Width of cells in the y direction

hz

Width of cells in the z direction

n_cells

Total number of cells in the mesh.

n_edges

Total number of edges.

n_edges_per_direction

The number of edges in each direction

n_edges_x

Number of x-edges

n_edges_y

Number of y-edges

n_edges_z

Number of z-edges

n_faces

Total number of faces.

n_faces_per_direction

The number of faces in each direction

n_faces_x

Number of x-faces

n_faces_y

Number of y-faces

n_faces_z

Number of z-faces

n_nodes

Total number of nodes

nodes

Nodal grid.

nodes_x

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

nodes_y

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

nodes_z

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

normals

normals has been deprecated. See face_normals for documentation

orientation
origin

Origin of the mesh

reference_is_rotated

True if the axes are rotated from the traditional <X,Y,Z> system

reference_system

The type of coordinate reference frame.

rotation_matrix

Builds a rotation matrix to transform coordinates from their coordinate system into a conventional cartesian system.

shape_cells

The number of cells in each direction

tangents

tangents has been deprecated. See edge_tangents for documentation

vectorCCx

vectorCCx has been deprecated. See cell_centers_x for documentation

vectorCCy

vectorCCy has been deprecated. See cell_centers_y for documentation

vectorCCz

vectorCCz has been deprecated. See cell_centers_z for documentation

vectorNx

vectorNx has been deprecated. See nodes_x for documentation

vectorNy

vectorNy has been deprecated. See nodes_y for documentation

vectorNz

vectorNz has been deprecated. See nodes_z for documentation

x0

Methods

 Make a copy of the current mesh getInterpolationMat(*args, **kwargs) getInterpolationMat has been deprecated. getTensor(*args, **kwargs) getTensor has been deprecated. get_interpolation_matrix(loc[, …]) Produces linear interpolation matrix get_tensor(key) Returns a tensor list. isInside(*args, **kwargs) isInside has been deprecated. is_inside(pts[, location_type]) Determines if a set of points are inside a mesh. projectEdgeVector(*args, **kwargs) projectEdgeVector has been deprecated. projectFaceVector(*args, **kwargs) projectFaceVector has been deprecated. project_edge_vector(edge_vector) Project vectors onto the edges of the mesh project_face_vector(face_vector) Project vectors onto the faces of the mesh. save([file_name, verbose]) Save the mesh to json :param str file: file_name for saving the casing properties :param str directory: working directory for saving the file Every object will be valid upon initialization
 deserialize equals serialize to_dict

## Attributes¶

BaseTensorMesh.axis_u

Deprecated since version 0.7.0: axis_u will be removed in discretize 1.0.0, it is replaced by mesh.orientation for better mesh orientation validation.

BaseTensorMesh.axis_v

Deprecated since version 0.7.0: axis_v will be removed in discretize 1.0.0, it is replaced by mesh.orientation for better mesh orientation validation.

BaseTensorMesh.axis_w

Deprecated since version 0.7.0: axis_w will be removed in discretize 1.0.0, it is replaced by mesh.orientation for better mesh orientation validation.

BaseTensorMesh.boundary_edges

Boundary edge locations

Returns
np.ndarray of float

location array of shape (mesh.n_boundary_edges, dim)

BaseTensorMesh.boundary_face_outward_normals

Outward directed normal vectors for the boundary faces

Returns
np.ndarray of float

Array of vectors of shape (mesh.n_boundary_faces, dim)

BaseTensorMesh.boundary_faces

Boundary face locations

Returns
np.ndarray of float

location array of shape (mesh.n_boundary_faces, dim)

BaseTensorMesh.boundary_nodes

Boundary node locations

Returns
np.ndarray of float

location array of shape (mesh.n_boundary_nodes, dim)

BaseTensorMesh.cell_centers

Cell-centered grid.

BaseTensorMesh.cell_centers_x

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

BaseTensorMesh.cell_centers_y

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

BaseTensorMesh.cell_centers_z

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

BaseTensorMesh.dim

The dimension of the mesh (1, 2, or 3).

Returns
int

dimension of the mesh

BaseTensorMesh.edge_tangents

Edge Tangents

Returns
numpy.ndarray

normals, (n_edges, dim)

BaseTensorMesh.edges

Edge grid

BaseTensorMesh.edges_x

Edge staggered grid in the x direction.

BaseTensorMesh.edges_y

Edge staggered grid in the y direction.

BaseTensorMesh.edges_z

Edge staggered grid in the z direction.

BaseTensorMesh.face_normals

Face Normals

Returns
numpy.ndarray

normals, (n_faces, dim)

BaseTensorMesh.faces

Face grid

BaseTensorMesh.faces_x

Face staggered grid in the x direction.

BaseTensorMesh.faces_y

Face staggered grid in the y direction.

BaseTensorMesh.faces_z

Face staggered grid in the z direction.

BaseTensorMesh.h
BaseTensorMesh.h_gridded

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

BaseTensorMesh.hx

Width of cells in the x direction

Returns
numpy.ndarray

Deprecated since version 0.5.0: hx will be removed in discretize 1.0.0 to reduce namespace clutter, please use mesh.h[0].

BaseTensorMesh.hy

Width of cells in the y direction

Returns
numpy.ndarray or None

Deprecated since version 0.5.0: hy will be removed in discretize 1.0.0 to reduce namespace clutter, please use mesh.h[1].

BaseTensorMesh.hz

Width of cells in the z direction

Returns
numpy.ndarray or None

Deprecated since version 0.5.0: hz will be removed in discretize 1.0.0 to reduce namespace clutter, please use mesh.h[2].

BaseTensorMesh.n_cells

Total number of cells in the mesh.

Returns
int

number of cells in the mesh

Notes

Also accessible as nC.

Examples

>>> import discretize
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> mesh.plot_grid(centers=True, show_it=True)
>>> print(mesh.n_cells)

BaseTensorMesh.n_edges

Total number of edges.

Returns
int

sum([n_edges_x, n_edges_y, n_edges_z])

Notes

Also accessible as nE.

BaseTensorMesh.n_edges_per_direction

The number of edges in each direction

Returns
n_edges_per_directiontuple

[n_edges_x, n_edges_y, n_edges_z], (dim, )

Notes

Also accessible as vnE.

Examples

>>> import discretize
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> M = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> M.plot_grid(edges=True, show_it=True)

BaseTensorMesh.n_edges_x

Number of x-edges

Returns
int

Notes

Also accessible as nEx.

BaseTensorMesh.n_edges_y

Number of y-edges

Returns
int

Notes

Also accessible as nEy.

BaseTensorMesh.n_edges_z

Number of z-edges

Returns
int

Notes

Also accessible as nEz.

BaseTensorMesh.n_faces

Total number of faces.

Returns
int

sum([n_faces_x, n_faces_y, n_faces_z])

Notes

Also accessible as nF.

BaseTensorMesh.n_faces_per_direction

The number of faces in each direction

Returns
n_faces_per_directiontuple

[n_faces_x, n_faces_y, n_faces_z], (dim, )

Notes

Also accessible as vnF.

Examples

>>> import discretize
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> M = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> M.plot_grid(faces=True, show_it=True)

BaseTensorMesh.n_faces_x

Number of x-faces

Returns
int

Notes

Also accessible as nFx.

BaseTensorMesh.n_faces_y

Number of y-faces

Returns
int

Notes

Also accessible as nFy.

BaseTensorMesh.n_faces_z

Number of z-faces

Returns
int

Notes

Also accessible as nFz.

BaseTensorMesh.n_nodes

Total number of nodes

Returns
int

number of nodes in the mesh

Notes

Also accessible as nN.

Examples

>>> import discretize
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> mesh.plot_grid(nodes=True, show_it=True)
>>> print(mesh.n_nodes)

BaseTensorMesh.nodes

Nodal grid.

BaseTensorMesh.nodes_x

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

BaseTensorMesh.nodes_y

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

BaseTensorMesh.nodes_z

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

BaseTensorMesh.normals

normals has been deprecated. See face_normals for documentation

BaseTensorMesh.orientation
BaseTensorMesh.origin

Origin of the mesh

BaseTensorMesh.reference_is_rotated

True if the axes are rotated from the traditional <X,Y,Z> system with vectors of $$(1,0,0)$$, $$(0,1,0)$$, and $$(0,0,1)$$

BaseTensorMesh.reference_system

The type of coordinate reference frame. Can take on the values

BaseTensorMesh.rotation_matrix

Builds a rotation matrix to transform coordinates from their coordinate system into a conventional cartesian system. This is built off of the three axis_u, axis_v, and axis_w properties; these mapping coordinates use the letters U, V, and W (the three letters preceding X, Y, and Z in the alphabet) to define the projection of the X, Y, and Z durections. These UVW vectors describe the placement and transformation of the mesh’s coordinate sytem assuming at most 3 directions.

Why would you want to use these UVW mapping vectors the this rotation_matrix property? They allow us to define the relationship between local and global coordinate systems and provide a tool for switching between the two while still maintaing the connectivity of the mesh’s cells. For a visual example of this, please see the figure in the docs for the InterfaceVTK.

BaseTensorMesh.shape_cells

The number of cells in each direction

Returns
tuple of ints

Notes

Also accessible as vnC.

BaseTensorMesh.tangents

tangents has been deprecated. See edge_tangents for documentation

BaseTensorMesh.vectorCCx

vectorCCx has been deprecated. See cell_centers_x for documentation

BaseTensorMesh.vectorCCy

vectorCCy has been deprecated. See cell_centers_y for documentation

BaseTensorMesh.vectorCCz

vectorCCz has been deprecated. See cell_centers_z for documentation

BaseTensorMesh.vectorNx

vectorNx has been deprecated. See nodes_x for documentation

BaseTensorMesh.vectorNy

vectorNy has been deprecated. See nodes_y for documentation

BaseTensorMesh.vectorNz

vectorNz has been deprecated. See nodes_z for documentation

BaseTensorMesh.x0

## Methods¶

BaseTensorMesh.copy()

Make a copy of the current mesh

classmethod BaseTensorMesh.deserialize(items, **kwargs)
BaseTensorMesh.equals(other)
BaseTensorMesh.getInterpolationMat(*args, **kwargs)

getInterpolationMat has been deprecated. See get_interpolation_matrix for documentation

BaseTensorMesh.getTensor(*args, **kwargs)

getTensor has been deprecated. See get_tensor for documentation

BaseTensorMesh.get_interpolation_matrix(loc, location_type='cell_centers', zeros_outside=False, **kwargs)[source]

Produces linear interpolation matrix

Parameters
locnumpy.ndarray

Location of points to interpolate to

location_typestr

What to interpolate (see below)

location_type can be:

'Ex', 'edges_x'           -> x-component of field defined on x edges
'Ey', 'edges_y'           -> y-component of field defined on y edges
'Ez', 'edges_z'           -> z-component of field defined on z edges
'Fx', 'faces_x'           -> x-component of field defined on x faces
'Fy', 'faces_y'           -> y-component of field defined on y faces
'Fz', 'faces_z'           -> z-component of field defined on z faces
'N', 'nodes'              -> scalar field defined on nodes
'CC', 'cell_centers'      -> scalar field defined on cell centers
'CCVx', 'cell_centers_x'  -> x-component of vector field defined on cell centers
'CCVy', 'cell_centers_y'  -> y-component of vector field defined on cell centers
'CCVz', 'cell_centers_z'  -> z-component of vector field defined on cell centers

Returns
scipy.sparse.csr_matrix

M, the interpolation matrix

BaseTensorMesh.get_tensor(key)[source]

Returns a tensor list.

Parameters
keystr

Which tensor (see below)

key can be:

'CC', 'cell_centers' -> location of cell centers
'N', 'nodes'         -> location of nodes
'Fx', 'faces_x'      -> location of faces with an x normal
'Fy', 'faces_y'      -> location of faces with an y normal
'Fz', 'faces_z'      -> location of faces with an z normal
'Ex', 'edges_x'      -> location of edges with an x tangent
'Ey', 'edges_y'      -> location of edges with an y tangent
'Ez', 'edges_z'      -> location of edges with an z tangent

Returns
list

list of the tensors that make up the mesh.

BaseTensorMesh.isInside(*args, **kwargs)

isInside has been deprecated. See is_inside for documentation

BaseTensorMesh.is_inside(pts, location_type='nodes', **kwargs)[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

BaseTensorMesh.projectEdgeVector(*args, **kwargs)

projectEdgeVector has been deprecated. See project_edge_vector for documentation

BaseTensorMesh.projectFaceVector(*args, **kwargs)

projectFaceVector has been deprecated. See project_face_vector for documentation

BaseTensorMesh.project_edge_vector(edge_vector)

Project vectors onto the edges of the mesh

Given a vector, edge_vector, in cartesian coordinates, this will project it onto the mesh using the tangents

Parameters
edge_vectornumpy.ndarray

edge vector with shape (n_edges, dim)

Returns
numpy.ndarray

projected edge vector, (n_edges, )

BaseTensorMesh.project_face_vector(face_vector)

Project vectors onto the faces of the mesh.

Given a vector, face_vector, in cartesian coordinates, this will project it onto the mesh using the normals

Parameters
face_vectornumpy.ndarray

face vector with shape (n_faces, dim)

Returns
numpy.ndarray

projected face vector, (n_faces, )

BaseTensorMesh.save(file_name='mesh.json', verbose=False, **kwargs)

Save the mesh to json :param str file: file_name for saving the casing properties :param str directory: working directory for saving the file

BaseTensorMesh.serialize()
BaseTensorMesh.to_dict()
BaseTensorMesh.validate()

Every object will be valid upon initialization