discretize.TreeMesh¶

class
discretize.
TreeMesh
(*args, **kwargs)[source]¶ Bases:
discretize._extensions.tree_ext._TreeMesh
,discretize.base.base_tensor_mesh.BaseTensorMesh
,discretize.operators.inner_products.InnerProducts
,discretize.base.mesh_io.TreeMeshIO
TreeMesh is a class for adaptive QuadTree (2D) and OcTree (3D) meshes.
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: Xaxis_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: Yaxis_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: Zh (a tuple of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a tuple (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 1 and 3origin (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*)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
 Attributes
area
area has been deprecated. See face_areas for documentation
areaFx
areaFx has been deprecated. See face_x_areas for documentation
areaFy
areaFy has been deprecated. See face_y_areas for documentation
areaFz
areaFz has been deprecated. See face_z_areas for documentation
average_cell_to_face
Construct the averaging operator on cell centers to cell faces.
average_cell_to_face_x
Construct the averaging operator on cell centers to cell xfaces.
average_cell_to_face_y
Construct the averaging operator on cell centers to cell yfaces.
average_cell_to_face_z
Construct the averaging operator on cell centers to cell zfaces.
average_cell_vector_to_face
Construct the averaging operator on cell centers to cell faces.
average_edge_to_cell
Construct the averaging operator on cell edges to cell centers.
average_edge_to_cell_vector
Construct the averaging operator on cell edges to cell centers.
average_edge_x_to_cell
Construct the averaging operator on cell edges in the x direction to cell centers.
average_edge_y_to_cell
Construct the averaging operator on cell edges in the y direction to cell centers.
average_edge_z_to_cell
Construct the averaging operator on cell edges in the z direction to cell centers.
average_face_to_cell
Construct the averaging operator on cell faces to cell centers.
average_face_to_cell_vector
Construct the averaging operator on cell faces to cell centers.
average_face_x_to_cell
Construct the averaging operator on cell faces in the x direction to cell centers.
average_face_y_to_cell
Construct the averaging operator on cell faces in the y direction to cell centers.
average_face_z_to_cell
Construct the averaging operator on cell faces in the z direction to cell centers.
average_node_to_cell
Construct the averaging operator on cell nodes to cell centers.
average_node_to_edge
Construct the averaging operator on cell nodes to cell edges, keeping each dimension separate.
average_node_to_edge_x
Averaging operator on cell nodes to xedges
average_node_to_edge_y
Averaging operator on cell nodes to yedges
average_node_to_edge_z
Averaging operator on cell nodes to zedges
average_node_to_face
Construct the averaging operator on cell nodes to cell edges, keeping each dimension separate.
average_node_to_face_x
Averaging operator on cell nodes to xfaces
average_node_to_face_y
Averaging operator on cell nodes to yfaces
average_node_to_face_z
Averaging operator on cell nodes to zfaces
axis_u
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: Xaxis_v
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: Yaxis_w
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: ZcellBoundaryInd
cellBoundaryInd has been deprecated. See cell_boundary_indices for documentation
cellGrad
cellGrad has been deprecated. See cell_gradient for documentation
cellGradStencil
cellGradStencil has been deprecated. See cell_gradient_stencil for documentation
cellGradx
cellGradx has been deprecated. See cell_gradient_x for documentation
cellGrady
cellGrady has been deprecated. See cell_gradient_y for documentation
cellGradz
cellGradz has been deprecated. See cell_gradient_z for documentation
cell_boundary_indices
Returns a tuple of arrays of indexes for boundary cells in each direction
cell_centers
Returns a numpy arrayof shape (n_cells, dim) with the center locations of all cells in order.
cell_centers_x
Cellcentered grid vector (1D) in the x direction.
cell_centers_y
Cellcentered grid vector (1D) in the y direction.
cell_centers_z
Cellcentered grid vector (1D) in the z direction.
cell_gradient
Cell centered Gradient operator built off of the faceDiv operator.
cell_gradient_x
Cell centered Gradient operator in xdirection (Gradx)
cell_gradient_y
Cell centered Gradient operator in ydirection (Grady)
cell_gradient_z
Cell centered Gradient operator in zdirection (Gradz)
cell_nodes
The index of nodes for each cell.
cell_volumes
Returns a numpy array of length n_cells with the volumes (areas in 2D) of all cells in order.
dim
The dimension of the mesh (1, 2, or 3).
edge
edge has been deprecated. See edge_lengths for documentation
edgeCurl
edgeCurl has been deprecated. See edge_curl for documentation
edgeEx
edgeEx has been deprecated. See edge_x_lengths for documentation
edgeEy
edgeEy has been deprecated. See edge_y_lengths for documentation
edgeEz
edgeEz has been deprecated. See edge_z_lengths for documentation
edge_curl
Construct the 3D curl operator.
edge_lengths
Returns a numpy array of length n_edges with the length of all edges ordered by x, then y, then z.
edge_nodes
The index of nodes for every edge.
edge_tangents
Edge Tangents
edges_x
Returns a numpy array of shape (n_edges_x, dim) with the centers of all nonhanging edges along the first dimension in order.
edges_y
Returns a numpy array of shape (n_edges_y, dim) with the centers of all nonhanging edges along the second dimension in order.
edges_z
Returns a numpy array of shape (n_edges_z, dim) with the centers of all nonhanging edges along the third dimension in order.
faceBoundaryInd
faceBoundaryInd has been deprecated. See face_boundary_indices for documentation
faceDiv
faceDiv has been deprecated. See face_divergence for documentation
faceDivx
faceDivx has been deprecated. See face_x_divergence for documentation
faceDivy
faceDivy has been deprecated. See face_y_divergence for documentation
faceDivz
faceDivz has been deprecated. See face_z_divergence for documentation
face_areas
Returns a numpy array of length n_faces with the area (length in 2D) of all faces ordered by x, then y, then z.
face_boundary_indices
Returns a tuple of arrays of indexes for boundary faces in each direction
face_divergence
Construct divergence operator (facestg to cellcentres).
face_normals
Face Normals
 face_x_divergence
 face_y_divergence
 face_z_divergence
faces_x
Returns a numpy array of shape (n_faces_x, dim) with the centers of all nonhanging faces along the first dimension in order.
faces_y
Returns a numpy array of shape (n_faces_y, dim) with the centers of all nonhanging faces along the second dimension in order.
faces_z
Returns a numpy array of shape (n_faces_z, dim) with the centers of all nonhanging faces along the third dimension in order.
fill
How filled is the mesh compared to a TensorMesh? As a fraction: [0, 1].
h
h (a tuple of
Array
): h is a list containing the cell widths of the tensor mesh in each dimension., a tuple (each item is a list or numpy array of <class ‘float’> with shape (*)) with length between 1 and 3h_gridded
Returns an (n_cells, dim) numpy array with the widths of all cells in order
hanging_edges_x
Returns a numpy array of shape (n_hanging_edges_x, dim) with the centers of all hanging edges along the first dimension in order.
hanging_edges_y
Returns a numpy array of shape (n_hanging_edges_y, dim) with the centers of all hanging edges along the second dimension in order.
hanging_edges_z
Returns a numpy array of shape (n_hanging_edges_z, dim) with the centers of all hanging edges along the third dimension in order.
hanging_faces_x
Returns a numpy array of shape (n_hanging_faces_x, dim) with the centers of all hanging faces along the first dimension in order.
hanging_faces_y
Returns a numpy array of shape (n_hanging_faces_y, dim) with the centers of all hanging faces along the second dimension in order.
hanging_faces_z
Returns a numpy array of shape (n_hanging_faces_z, dim) with the centers of all hanging faces along the third dimension in order.
hanging_nodes
Returns a numpy array of shape (n_nodes, dim) with the locations of all hanging nodes 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
maxLevel
maxLevel has been deprecated. See max_used_level for documentation
max_level
The maximum possible level for a cell on this mesh
max_used_level
The maximum level used, which may be less than max_level.
n_cells
Number of cells
n_edges
Total number of nonhanging edges amongst all dimensions
n_edges_per_direction
The number of edges in each direction
n_edges_x
Number of nonhanging edges oriented along the first dimension
n_edges_y
Number of nonhanging edges oriented along the second dimension
n_edges_z
Number of nonhanging edges oriented along the third dimension
n_faces
Total number of nonhanging faces amongst all dimensions
n_faces_per_direction
The number of faces in each direction
n_faces_x
Number of nonhanging faces oriented along the first dimension
n_faces_y
Number of nonhanging faces oriented along the second dimension
n_faces_z
Number of nonhanging faces oriented along the third dimension
n_hanging_edges
Total number of hanging edges amongst all dimensions
n_hanging_edges_x
Number of hanging edges oriented along the first dimension
n_hanging_edges_y
Number of hanging edges oriented along the second dimension
n_hanging_edges_z
Number of hanging edges oriented along the third dimension
n_hanging_faces
Total number of hanging faces amongst all dimensions
n_hanging_faces_x
Number of hanging faces oriented along the first dimension
n_hanging_faces_y
Number of hanging faces oriented along the second dimension
n_hanging_faces_z
Number of hanging faces oriented along the third dimension
n_hanging_nodes
Number of hanging nodes
n_nodes
Number of nonhanging nodes
n_total_edges
Total number of nonhanging and hanging edges amongst all dimensions
n_total_edges_x
Number of nonhanging and hanging edges oriented along the first dimension
n_total_edges_y
Number of nonhanging and hanging edges oriented along the second dimension
n_total_edges_z
Number of nonhanging and hanging edges oriented along the third dimension
n_total_faces
Total number of hanging and nonhanging faces amongst all dimensions
n_total_faces_x
Number of nonhanging and hanging faces oriented along the first dimension
n_total_faces_y
Number of nonhanging and hanging faces oriented along the second dimension
n_total_faces_z
Number of nonhanging and hanging faces oriented along the third dimension
n_total_nodes
Number of nonhanging and hanging nodes
nodalGrad
nodalGrad has been deprecated. See nodal_gradient for documentation
nodalLaplacian
nodalLaplacian has been deprecated. See nodal_laplacian for documentation
nodal_gradient
Construct gradient operator (nodes to edges).
 nodal_laplacian
nodes
Returns a numpy array of shape (n_nodes, dim) with the locations of all nonhanging nodes in order.
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
origin
origin (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*)permuteCC
permuteCC has been deprecated. See permute_cells for documentation
permuteE
permuteE has been deprecated. See permute_edges for documentation
permuteF
permuteF has been deprecated. See permute_faces for documentation
permute_cells
Permutation matrix reordering of cells sorted by x, then y, then z
permute_edges
Permutation matrix reordering of edges sorted by x, then y, then z
permute_faces
Permutation matrix reordering of faces sorted by x, then y, then z
reference_is_rotated
True if the axes are rotated from the traditional <X,Y,Z> system
reference_system
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: cartesianrotation_matrix
Builds a rotation matrix to transform coordinates from their coordinate system into a conventional cartesian system.
 stencil_cell_gradient
stencil_cell_gradient_x
Cell gradient stencil matrix to total (including hanging) x faces
stencil_cell_gradient_y
Cell gradient stencil matrix to total (including hanging) y faces
stencil_cell_gradient_z
Cell gradient stencil matrix to total (including hanging) z faces
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
vntE
Total number of hanging and nonhanging edges in a [nx,ny,nz] form
vntF
Total number of hanging and nonhanging faces in a [nx,ny,nz] form
vol
vol has been deprecated. See cell_volumes for documentation
 x0
Methods
Average matrix for cell center to total (including hanging) x faces
Average matrix for cell center to total (including hanging) y faces
Average matrix for cell center to total (including hanging) z faces
cell_levels_by_index
(indices)Fast function to return a list of levels for the given cell indices
copy
()Make a copy of the current mesh
deserialize
(serial)Creates HasProperties instance from serialized dictionary
equal
(other)Determine if two HasProperties instances are equivalent
finalize
(self)Finalize the TreeMesh Called after finished cronstruction of the mesh.
from_omf
(element)Convert an OMF element to it’s proper
discretize
type.getEdgeInnerProduct
(*args, **kwargs)getEdgeInnerProduct has been deprecated.
getEdgeInnerProductDeriv
(*args, **kwargs)getEdgeInnerProductDeriv has been deprecated.
getFaceInnerProduct
(*args, **kwargs)getFaceInnerProduct has been deprecated.
getFaceInnerProductDeriv
(*args, **kwargs)getFaceInnerProductDeriv has been deprecated.
getInterpolationMat
(*args, **kwargs)getInterpolationMat has been deprecated.
getTensor
(*args, **kwargs)getTensor has been deprecated.
get_boundary_cells
(self[, active_ind, direction])Returns the indices of boundary cells in a given direction given an active index array.
get_cells_along_line
(self, x0, x1)Finds the cells along a line segment defined by two points
get_edge_inner_product
([model, …])Generate the edge inner product matrix
get_edge_inner_product_deriv
(model[, …]) Parameters
get_face_inner_product
([model, …])Generate the face inner product matrix
get_face_inner_product_deriv
(model[, …]) Parameters
get_interpolation_matrix
(locs[, …])Produces interpolation matrix
get_overlapping_cells
(self, rectangle)get_tensor
(key)Returns a tensor list.
insert_cells
(self, points, levels[, finalize])Insert cells into the TreeMesh that contain given points
isInside
(*args, **kwargs)isInside has been deprecated.
is_inside
(pts[, location_type])Determines if a set of points are inside a mesh.
number
(self)Number the cells, nodes, faces, and edges of the TreeMesh
plotGrid
(*args, **kwargs)plotGrid has been deprecated.
plotImage
(*args, **kwargs)plotImage has been deprecated.
plotSlice
(*args, **kwargs)plotSlice has been deprecated.
plot_3d_slicer
(v[, xslice, yslice, zslice, …])Plot slices of a 3D volume, interactively (scroll wheel).
plot_grid
([ax, nodes, faces, centers, …])Plot the nodal, cellcentered and staggered grids.
plot_image
(v[, v_type, grid, view, ax, …])Plots fields on the given mesh.
plot_slice
(v[, v_type, normal, ind, …])Plots slice of fields on the given 3D mesh.
point2index
(locs)Finds cells that contain the given points.
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.
readModelUBC
(*args, **kwargs)readModelUBC has been deprecated.
readUBC
(file_name[, directory])read_UBC
(meshFile[, directory])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
read_model_UBC
(file_name)Read UBC OcTree model and get vector :param string file_name: path to the UBC GIF model file to read :rtype: numpy.ndarray :return: OcTree model
refine
(self, function[, finalize])Refine a TreeMesh using a user supplied function.
refine_ball
(self, points, radii, levels[, …])Refines the TreeMesh around points with the given radii
refine_box
(self, x0s, x1s, levels[, finalize])Refines the TreeMesh within the axis aligned boxes to the desired level
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
Serializes a HasProperties instance to dictionary
toVTK
([models])Convert this mesh object to it’s proper VTK or
pyvista
data object with the given model dictionary as the cell data of that dataset.to_omf
([models])Convert this mesh object to it’s proper
omf
data object with the given model dictionary as the cell data of that dataset.to_vtk
([models])Convert this mesh object to it’s proper VTK or
pyvista
data object with the given model dictionary as the cell data of that dataset.validate
()Call all registered class validator methods
writeModelUBC
(*args, **kwargs)writeModelUBC has been deprecated.
writeUBC
(*args, **kwargs)writeUBC has been deprecated.
writeVTK
(file_name[, models, directory])Makes and saves a VTK object from this mesh and given models
write_UBC
(file_name[, models, directory])Write UBC ocTree mesh and model files from a octree mesh and model.
write_model_UBC
(file_name, model[, directory])Writes a model associated with a TreeMesh to a UBCGIF format model file.
write_vtk
(file_name[, models, directory])Makes and saves a VTK object from this mesh and given models
Attributes¶

TreeMesh.
area
¶ area has been deprecated. See face_areas for documentation

TreeMesh.
areaFx
¶ areaFx has been deprecated. See face_x_areas for documentation

TreeMesh.
areaFy
¶ areaFy has been deprecated. See face_y_areas for documentation

TreeMesh.
areaFz
¶ areaFz has been deprecated. See face_z_areas for documentation

TreeMesh.
average_cell_to_face
¶ Construct the averaging operator on cell centers to cell faces.

TreeMesh.
average_cell_to_face_x
¶ Construct the averaging operator on cell centers to cell xfaces.

TreeMesh.
average_cell_to_face_y
¶ Construct the averaging operator on cell centers to cell yfaces.

TreeMesh.
average_cell_to_face_z
¶ Construct the averaging operator on cell centers to cell zfaces.

TreeMesh.
average_cell_vector_to_face
¶ Construct the averaging operator on cell centers to cell faces.

TreeMesh.
average_edge_to_cell
¶ Construct the averaging operator on cell edges to cell centers.

TreeMesh.
average_edge_to_cell_vector
¶ Construct the averaging operator on cell edges to cell centers.

TreeMesh.
average_edge_x_to_cell
¶ Construct the averaging operator on cell edges in the x direction to cell centers.

TreeMesh.
average_edge_y_to_cell
¶ Construct the averaging operator on cell edges in the y direction to cell centers.

TreeMesh.
average_edge_z_to_cell
¶ Construct the averaging operator on cell edges in the z direction to cell centers.

TreeMesh.
average_face_to_cell
¶ Construct the averaging operator on cell faces to cell centers.

TreeMesh.
average_face_to_cell_vector
¶ Construct the averaging operator on cell faces to cell centers.

TreeMesh.
average_face_x_to_cell
¶ Construct the averaging operator on cell faces in the x direction to cell centers.

TreeMesh.
average_face_y_to_cell
¶ Construct the averaging operator on cell faces in the y direction to cell centers.

TreeMesh.
average_face_z_to_cell
¶ Construct the averaging operator on cell faces in the z direction to cell centers.

TreeMesh.
average_node_to_cell
¶ Construct the averaging operator on cell nodes to cell centers.

TreeMesh.
average_node_to_edge
¶ Construct the averaging operator on cell nodes to cell edges, keeping each dimension separate.

TreeMesh.
average_node_to_edge_x
¶ Averaging operator on cell nodes to xedges

TreeMesh.
average_node_to_edge_y
¶ Averaging operator on cell nodes to yedges

TreeMesh.
average_node_to_edge_z
¶ Averaging operator on cell nodes to zedges

TreeMesh.
average_node_to_face
¶ Construct the averaging operator on cell nodes to cell edges, keeping each dimension separate.

TreeMesh.
average_node_to_face_x
¶ Averaging operator on cell nodes to xfaces

TreeMesh.
average_node_to_face_y
¶ Averaging operator on cell nodes to yfaces

TreeMesh.
average_node_to_face_z
¶ Averaging operator on cell nodes to zfaces

TreeMesh.
axis_u
¶ 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

TreeMesh.
axis_v
¶ 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

TreeMesh.
axis_w
¶ 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

TreeMesh.
cellBoundaryInd
¶ cellBoundaryInd has been deprecated. See cell_boundary_indices for documentation

TreeMesh.
cellGrad
¶ cellGrad has been deprecated. See cell_gradient for documentation

TreeMesh.
cellGradStencil
¶ cellGradStencil has been deprecated. See cell_gradient_stencil for documentation

TreeMesh.
cellGradx
¶ cellGradx has been deprecated. See cell_gradient_x for documentation

TreeMesh.
cellGrady
¶ cellGrady has been deprecated. See cell_gradient_y for documentation

TreeMesh.
cellGradz
¶ cellGradz has been deprecated. See cell_gradient_z for documentation

TreeMesh.
cell_boundary_indices
¶ Returns a tuple of arrays of indexes for boundary cells in each direction xdown, xup, ydown, yup, zdown, zup

TreeMesh.
cell_centers
¶ Returns a numpy arrayof shape (n_cells, dim) with the center locations of all cells in order.

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

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

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

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

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

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

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

TreeMesh.
cell_nodes
¶ The index of nodes for each cell.
 Returns
 numpy.ndarray of ints
Index array of shape (n_cells, 4) if 2D, or (n_cells, 6) if 3D
Notes
These indices will also point to hanging nodes.

TreeMesh.
cell_volumes
¶ Returns a numpy array of length n_cells with the volumes (areas in 2D) of all cells in order.

TreeMesh.
dim
¶ The dimension of the mesh (1, 2, or 3).
 Returns
 int
dimension of the mesh

TreeMesh.
edge
¶ edge has been deprecated. See edge_lengths for documentation

TreeMesh.
edgeCurl
¶ edgeCurl has been deprecated. See edge_curl for documentation

TreeMesh.
edgeEx
¶ edgeEx has been deprecated. See edge_x_lengths for documentation

TreeMesh.
edgeEy
¶ edgeEy has been deprecated. See edge_y_lengths for documentation

TreeMesh.
edgeEz
¶ edgeEz has been deprecated. See edge_z_lengths for documentation

TreeMesh.
edge_curl
¶ Construct the 3D curl operator.

TreeMesh.
edge_lengths
¶ Returns a numpy array of length n_edges with the length of all edges ordered by x, then y, then z.

TreeMesh.
edge_nodes
¶ The index of nodes for every edge.
The index of the nodes at each end of every (including hanging) edge.
 Returns
 tuple of numpy.ndarray of ints
One numpy array for each edge type (x, y, (z)) for this mesh.
Notes
These arrays will also index into the hanging nodes.

TreeMesh.
edge_tangents
¶ Edge Tangents
 Returns
 numpy.ndarray
normals, (n_edges, dim)

TreeMesh.
edges_x
¶ Returns a numpy array of shape (n_edges_x, dim) with the centers of all nonhanging edges along the first dimension in order.

TreeMesh.
edges_y
¶ Returns a numpy array of shape (n_edges_y, dim) with the centers of all nonhanging edges along the second dimension in order.

TreeMesh.
edges_z
¶ Returns a numpy array of shape (n_edges_z, dim) with the centers of all nonhanging edges along the third dimension in order.

TreeMesh.
faceBoundaryInd
¶ faceBoundaryInd has been deprecated. See face_boundary_indices for documentation

TreeMesh.
faceDiv
¶ faceDiv has been deprecated. See face_divergence for documentation

TreeMesh.
faceDivx
¶ faceDivx has been deprecated. See face_x_divergence for documentation

TreeMesh.
faceDivy
¶ faceDivy has been deprecated. See face_y_divergence for documentation

TreeMesh.
faceDivz
¶ faceDivz has been deprecated. See face_z_divergence for documentation

TreeMesh.
face_areas
¶ Returns a numpy array of length n_faces with the area (length in 2D) of all faces ordered by x, then y, then z.

TreeMesh.
face_boundary_indices
¶ Returns a tuple of arrays of indexes for boundary faces in each direction xdown, xup, ydown, yup, zdown, zup

TreeMesh.
face_divergence
¶ Construct divergence operator (facestg to cellcentres).

TreeMesh.
face_normals
¶ Face Normals
 Returns
 numpy.ndarray
normals, (n_faces, dim)

TreeMesh.
face_x_divergence
¶

TreeMesh.
face_y_divergence
¶

TreeMesh.
face_z_divergence
¶

TreeMesh.
faces_x
¶ Returns a numpy array of shape (n_faces_x, dim) with the centers of all nonhanging faces along the first dimension in order.

TreeMesh.
faces_y
¶ Returns a numpy array of shape (n_faces_y, dim) with the centers of all nonhanging faces along the second dimension in order.

TreeMesh.
faces_z
¶ Returns a numpy array of shape (n_faces_z, dim) with the centers of all nonhanging faces along the third dimension in order.

TreeMesh.
fill
¶ How filled is the mesh compared to a TensorMesh? As a fraction: [0, 1].

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

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

TreeMesh.
hanging_edges_x
¶ Returns a numpy array of shape (n_hanging_edges_x, dim) with the centers of all hanging edges along the first dimension in order.

TreeMesh.
hanging_edges_y
¶ Returns a numpy array of shape (n_hanging_edges_y, dim) with the centers of all hanging edges along the second dimension in order.

TreeMesh.
hanging_edges_z
¶ Returns a numpy array of shape (n_hanging_edges_z, dim) with the centers of all hanging edges along the third dimension in order.

TreeMesh.
hanging_faces_x
¶ Returns a numpy array of shape (n_hanging_faces_x, dim) with the centers of all hanging faces along the first dimension in order.

TreeMesh.
hanging_faces_y
¶ Returns a numpy array of shape (n_hanging_faces_y, dim) with the centers of all hanging faces along the second dimension in order.

TreeMesh.
hanging_faces_z
¶ Returns a numpy array of shape (n_hanging_faces_z, dim) with the centers of all hanging faces along the third dimension in order.

TreeMesh.
hanging_nodes
¶ Returns a numpy array of shape (n_nodes, dim) with the locations of all hanging nodes in order.

TreeMesh.
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].

TreeMesh.
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].

TreeMesh.
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].

TreeMesh.
maxLevel
¶ maxLevel has been deprecated. See max_used_level for documentation

TreeMesh.
max_level
¶ The maximum possible level for a cell on this mesh

TreeMesh.
max_used_level
¶ The maximum level used, which may be less than max_level.

TreeMesh.
n_cells
¶ Number of cells

TreeMesh.
n_edges
¶ Total number of nonhanging edges amongst all dimensions

TreeMesh.
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)
(Source code, png, pdf)

TreeMesh.
n_edges_x
¶ Number of nonhanging edges oriented along the first dimension

TreeMesh.
n_edges_y
¶ Number of nonhanging edges oriented along the second dimension

TreeMesh.
n_edges_z
¶ Number of nonhanging edges oriented along the third dimension

TreeMesh.
n_faces
¶ Total number of nonhanging faces amongst all dimensions

TreeMesh.
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)
(Source code, png, pdf)

TreeMesh.
n_faces_x
¶ Number of nonhanging faces oriented along the first dimension

TreeMesh.
n_faces_y
¶ Number of nonhanging faces oriented along the second dimension

TreeMesh.
n_faces_z
¶ Number of nonhanging faces oriented along the third dimension

TreeMesh.
n_hanging_edges
¶ Total number of hanging edges amongst all dimensions

TreeMesh.
n_hanging_edges_x
¶ Number of hanging edges oriented along the first dimension

TreeMesh.
n_hanging_edges_y
¶ Number of hanging edges oriented along the second dimension

TreeMesh.
n_hanging_edges_z
¶ Number of hanging edges oriented along the third dimension

TreeMesh.
n_hanging_faces
¶ Total number of hanging faces amongst all dimensions

TreeMesh.
n_hanging_faces_x
¶ Number of hanging faces oriented along the first dimension

TreeMesh.
n_hanging_faces_y
¶ Number of hanging faces oriented along the second dimension

TreeMesh.
n_hanging_faces_z
¶ Number of hanging faces oriented along the third dimension

TreeMesh.
n_hanging_nodes
¶ Number of hanging nodes

TreeMesh.
n_nodes
¶ Number of nonhanging nodes

TreeMesh.
n_total_edges
¶ Total number of nonhanging and hanging edges amongst all dimensions

TreeMesh.
n_total_edges_x
¶ Number of nonhanging and hanging edges oriented along the first dimension

TreeMesh.
n_total_edges_y
¶ Number of nonhanging and hanging edges oriented along the second dimension

TreeMesh.
n_total_edges_z
¶ Number of nonhanging and hanging edges oriented along the third dimension

TreeMesh.
n_total_faces
¶ Total number of hanging and nonhanging faces amongst all dimensions

TreeMesh.
n_total_faces_x
¶ Number of nonhanging and hanging faces oriented along the first dimension

TreeMesh.
n_total_faces_y
¶ Number of nonhanging and hanging faces oriented along the second dimension

TreeMesh.
n_total_faces_z
¶ Number of nonhanging and hanging faces oriented along the third dimension

TreeMesh.
n_total_nodes
¶ Number of nonhanging and hanging nodes

TreeMesh.
nodalGrad
¶ nodalGrad has been deprecated. See nodal_gradient for documentation

TreeMesh.
nodalLaplacian
¶ nodalLaplacian has been deprecated. See nodal_laplacian for documentation

TreeMesh.
nodal_gradient
¶ Construct gradient operator (nodes to edges).

TreeMesh.
nodal_laplacian
¶

TreeMesh.
nodes
¶ Returns a numpy array of shape (n_nodes, dim) with the locations of all nonhanging nodes in order.

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

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

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

TreeMesh.
normals
¶ normals has been deprecated. See face_normals for documentation

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

TreeMesh.
permuteCC
¶ permuteCC has been deprecated. See permute_cells for documentation

TreeMesh.
permuteE
¶ permuteE has been deprecated. See permute_edges for documentation

TreeMesh.
permuteF
¶ permuteF has been deprecated. See permute_faces for documentation

TreeMesh.
permute_cells
¶ Permutation matrix reordering of cells sorted by x, then y, then z

TreeMesh.
permute_edges
¶ Permutation matrix reordering of edges sorted by x, then y, then z

TreeMesh.
permute_faces
¶ Permutation matrix reordering of faces sorted by x, then y, then z

TreeMesh.
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)\)

TreeMesh.
reference_system
¶ 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

TreeMesh.
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 realationship 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
.

TreeMesh.
stencil_cell_gradient
¶

TreeMesh.
stencil_cell_gradient_x
¶ Cell gradient stencil matrix to total (including hanging) x faces

TreeMesh.
stencil_cell_gradient_y
¶ Cell gradient stencil matrix to total (including hanging) y faces

TreeMesh.
stencil_cell_gradient_z
¶ Cell gradient stencil matrix to total (including hanging) z faces

TreeMesh.
tangents
¶ tangents has been deprecated. See edge_tangents for documentation

TreeMesh.
vectorCCx
¶ vectorCCx has been deprecated. See cell_centers_x for documentation

TreeMesh.
vectorCCy
¶ vectorCCy has been deprecated. See cell_centers_y for documentation

TreeMesh.
vectorCCz
¶ vectorCCz has been deprecated. See cell_centers_z for documentation

TreeMesh.
vectorNx
¶ vectorNx has been deprecated. See nodes_x for documentation

TreeMesh.
vectorNy
¶ vectorNy has been deprecated. See nodes_y for documentation

TreeMesh.
vectorNz
¶ vectorNz has been deprecated. See nodes_z for documentation

TreeMesh.
vntE
¶ Total number of hanging and nonhanging edges in a [nx,ny,nz] form

TreeMesh.
vntF
¶ Total number of hanging and nonhanging faces in a [nx,ny,nz] form

TreeMesh.
vol
¶ vol has been deprecated. See cell_volumes for documentation

TreeMesh.
x0
¶
Methods¶

TreeMesh.
average_cell_to_total_face_x
(self)¶ Average matrix for cell center to total (including hanging) x faces

TreeMesh.
average_cell_to_total_face_y
(self)¶ Average matrix for cell center to total (including hanging) y faces

TreeMesh.
average_cell_to_total_face_z
(self)¶ Average matrix for cell center to total (including hanging) z faces

TreeMesh.
cell_levels_by_index
(indices)[source]¶ Fast function to return a list of levels for the given cell indices
 Parameters
 index: array_like of length (N)
Cell indexes to query
 Returns
 numpy.array of length (N)
Levels for the cells.

TreeMesh.
copy
()¶ Make a copy of the current mesh

classmethod
TreeMesh.
deserialize
(serial)[source]¶ Creates HasProperties instance from serialized dictionary
This uses the Property deserializers to deserialize all JSONcompatible dictionary values into their corresponding Property values on a new instance of a HasProperties class. Extra keys in the dictionary that do not correspond to Properties will be ignored.
Parameters:
value  Dictionary to deserialize new instance from.
trusted  If True (and if the input dictionary has
'__class__'
keyword and this class is in the registry), the new HasProperties class will come from the dictionary. If False (the default), only the HasProperties class this method is called on will be constructed.strict  Requires
'__class__'
, if present on the input dictionary, to match the deserialized instance’s class. Also disallows unused properties in the input dictionary. Default is False.assert_valid  Require deserialized instance to be valid. Default is False.
Any other keyword arguments will be passed through to the Property deserializers.

TreeMesh.
equal
(other)¶ Determine if two HasProperties instances are equivalent
Equivalence is determined by checking if all Property values on two instances are equal, using
Property.equal
.

TreeMesh.
finalize
(self)¶ Finalize the TreeMesh Called after finished cronstruction of the mesh. Can only be called once. After finalize is called, all other attributes and functions are valid.

static
TreeMesh.
from_omf
(element)¶ Convert an OMF element to it’s proper
discretize
type. Automatically determines the output type. Returns both the mesh and a dictionary of model arrays.

TreeMesh.
getEdgeInnerProduct
(*args, **kwargs)¶ getEdgeInnerProduct has been deprecated. See get_edge_inner_product for documentation

TreeMesh.
getEdgeInnerProductDeriv
(*args, **kwargs)¶ getEdgeInnerProductDeriv has been deprecated. See get_edge_inner_product_deriv for documentation

TreeMesh.
getFaceInnerProduct
(*args, **kwargs)¶ getFaceInnerProduct has been deprecated. See get_face_inner_product for documentation

TreeMesh.
getFaceInnerProductDeriv
(*args, **kwargs)¶ getFaceInnerProductDeriv has been deprecated. See get_face_inner_product_deriv for documentation

TreeMesh.
getInterpolationMat
(*args, **kwargs)¶ getInterpolationMat has been deprecated. See get_interpolation_matrix for documentation

TreeMesh.
getTensor
(*args, **kwargs)¶ getTensor has been deprecated. See get_tensor for documentation

TreeMesh.
get_boundary_cells
(self, active_ind=None, direction='zu')¶ Returns the indices of boundary cells in a given direction given an active index array.
 Parameters
 active_indarray_like of bool, optional
If not None, then this must show which cells are active
 direction: str, optional
must be one of (‘zu’, ‘zd’, ‘xu’, ‘xd’, ‘yu’, ‘yd’)
 Returns
 numpy.array
Array of indices for the boundary cells in the requested direction

TreeMesh.
get_cells_along_line
(self, x0, x1)¶ Finds the cells along a line segment defined by two points
 Parameters
 x0,x1array_like of length (dim)
Begining and ending point of the line segment.
 Returns
 list of ints
Indexes for cells that contain the a line defined by the two input points, ordered in the direction of the line.

TreeMesh.
get_edge_inner_product
(model=None, invert_model=False, invert_matrix=False, do_fast=True, **kwargs)¶ Generate the edge inner product matrix
 Parameters
 modelnumpy.ndarray
material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
 invert_modelbool
inverts the material property
 invert_matrixbool
inverts the matrix
 do_fastbool
do a faster implementation if available.
 Returns
 scipy.sparse.csr_matrix
M, the inner product matrix (nE, nE)

TreeMesh.
get_edge_inner_product_deriv
(model, do_fast=True, invert_model=False, invert_matrix=False, **kwargs)¶  Parameters
 modelnumpy.ndarray
material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
 do_fastbool
do a faster implementation if available.
 invert_modelbool
inverts the material property
 invert_matrixbool
inverts the matrix
 Returns
 scipy.sparse.csr_matrix
dMdm, the derivative of the inner product matrix (nE, nC*nA)

TreeMesh.
get_face_inner_product
(model=None, invert_model=False, invert_matrix=False, do_fast=True, **kwargs)¶ Generate the face inner product matrix
 Parameters
 modelnumpy.ndarray
material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
 invert_modelbool
inverts the material property
 invert_matrixbool
inverts the matrix
 do_fastbool
do a faster implementation if available.
 Returns
 scipy.sparse.csr_matrix
M, the inner product matrix (nF, nF)

TreeMesh.
get_face_inner_product_deriv
(model, do_fast=True, invert_model=False, invert_matrix=False, **kwargs)¶  Parameters
 modelnumpy.ndarray
material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
 do_fast :
bool do a faster implementation if available.
 invert_modelbool
inverts the material property
 invert_matrixbool
inverts the matrix
 Returns
 scipy.sparse.csr_matrix
dMdmu(u), the derivative of the inner product matrix for a certain u

TreeMesh.
get_interpolation_matrix
(locs, location_type='CC', zeros_outside=False, **kwargs)[source]¶ Produces interpolation matrix
 Parameters
 locnumpy.ndarray
Location of points to interpolate to
 location_type: str
What to interpolate
location_type 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
 Returns
 scipy.sparse.csr_matrix
M, the interpolation matrix

TreeMesh.
get_overlapping_cells
(self, rectangle)¶

TreeMesh.
get_tensor
(key)¶ 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.

TreeMesh.
insert_cells
(self, points, levels, finalize=True)¶ Insert cells into the TreeMesh that contain given points
Insert cell(s) into the TreeMesh that contain the given point(s) at the assigned level(s).
 Parameters
 pointsarray_like with shape (N, dim)
 levelsarray_like of integers with shape (N)
 finalizebool, optional
Whether to finalize after inserting point(s)
Examples
>>> from discretize import TreeMesh >>> mesh = TreeMesh([32,32]) >>> mesh.insert_cells([0.5, 0.5], mesh.max_level) >>> print(mesh)  QuadTreeMesh  origin: 0.00, 0.00 hx: 32*0.03, hy: 32*0.03, n_cells: 40 Fill: 3.91%

TreeMesh.
isInside
(*args, **kwargs)¶ isInside has been deprecated. See is_inside for documentation

TreeMesh.
is_inside
(pts, location_type='nodes', **kwargs)¶ Determines if a set of points are inside a mesh.
 Parameters
pts (numpy.ndarray) – Location of points to test
 Return type
 Returns
inside, numpy array of booleans

TreeMesh.
number
(self)¶ Number the cells, nodes, faces, and edges of the TreeMesh

TreeMesh.
plotGrid
(*args, **kwargs)¶ plotGrid has been deprecated. See plot_grid for documentation

TreeMesh.
plotImage
(*args, **kwargs)¶ plotImage has been deprecated. See plot_image for documentation

TreeMesh.
plotSlice
(*args, **kwargs)¶ plotSlice has been deprecated. See plot_slice for documentation

TreeMesh.
plot_3d_slicer
(v, xslice=None, yslice=None, zslice=None, v_type='CC', view='real', axis='xy', transparent=None, clim=None, xlim=None, ylim=None, zlim=None, aspect='auto', grid=[2, 2, 1], pcolor_opts=None, fig=None, **kwargs)¶ Plot slices of a 3D volume, interactively (scroll wheel).
If called from a notebook, make sure to set
%matplotlib notebook
See 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().
One can also provide an existing figure instance, which can be useful for interactive widgets in Notebooks. The provided figure is cleared first.

TreeMesh.
plot_grid
(ax=None, nodes=False, faces=False, centers=False, edges=False, lines=True, show_it=False, **kwargs)¶ Plot the nodal, cellcentered and staggered grids.
 Parameters
 axmatplotlib.axes.Axes or None, optional
The axes to draw on. None produces a new Axes.
 nodes, faces, centers, edges, linesbool, optional
Whether to plot the corresponding item
 show_itbool, optional
whether to call plt.show()
 colorColor or str, optional
If lines=True, the color of the lines, defaults to first color.
 linewidthfloat, optional
If lines=True, the linewidth for the lines.
 Returns
 matplotlib.axes.Axes
Axes handle for the plot
 Other Parameters
 edges_x, edges_y, edges_z, faces_x, faces_y, faces_zbool, optional
When plotting a
TreeMesh
, these are also options to plot the individual component items. cell_linebool, optional
When plotting a
TreeMesh
, you can also plot a line through the cell centers in order. slice{‘both’, ‘theta’, ‘z’}
When plotting a
CylindricalMesh
, which dimension to slice over.
Notes
Excess arguments are passed on to plot
Examples
Plotting a 2D TensorMesh grid
>>> from matplotlib import pyplot as plt >>> import discretize >>> import numpy as np >>> h1 = np.linspace(.1, .5, 3) >>> h2 = np.linspace(.1, .5, 5) >>> mesh = discretize.TensorMesh([h1, h2]) >>> mesh.plot_grid(nodes=True, faces=True, centers=True, lines=True) >>> plt.show()
(Source code, png, pdf)
Plotting a 3D TensorMesh grid
>>> from matplotlib import pyplot as plt >>> 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.plot_grid(nodes=True, faces=True, centers=True, lines=True) >>> plt.show()
Plotting a 2D CurvilinearMesh
>>> from matplotlib import pyplot as plt >>> import discretize >>> X, Y = discretize.utils.exampleLrmGrid([10, 10], 'rotate') >>> M = discretize.CurvilinearMesh([X, Y]) >>> M.plot_grid() >>> plt.show()
Plotting a 3D CurvilinearMesh
>>> from matplotlib import pyplot as plt >>> import discretize >>> X, Y, Z = discretize.utils.exampleLrmGrid([5, 5, 5], 'rotate') >>> M = discretize.CurvilinearMesh([X, Y, Z]) >>> M.plot_grid() >>> plt.show()
Plotting a 2D TreeMesh
>>> from matplotlib import pyplot as plt >>> import discretize >>> M = discretize.TreeMesh([32, 32]) >>> M.insert_cells([[0.25, 0.25]], [4]) >>> M.plot_grid() >>> plt.show()
Plotting a 3D TreeMesh
>>> from matplotlib import pyplot as plt >>> import discretize >>> M = discretize.TreeMesh([32, 32, 32]) >>> M.insert_cells([[0.3, 0.75, 0.22]], [4]) >>> M.plot_grid() >>> plt.show()

TreeMesh.
plot_image
(v, v_type='CC', grid=False, view='real', ax=None, clim=None, show_it=False, pcolor_opts=None, stream_opts=None, grid_opts=None, range_x=None, range_y=None, sample_grid=None, stream_thickness=None, stream_threshold=None, **kwargs)¶ Plots fields on the given mesh.
 Parameters
 vnumpy.ndarray
values to plot
 v_type{‘CC’,’CCV’, ‘N’, ‘F’, ‘Fx’, ‘Fy’, ‘Fz’, ‘E’, ‘Ex’, ‘Ey’, ‘Ez’}
Where the values of v are defined.
 view{‘real’, ‘imag’, ‘abs’, ‘vec’}
How to view the array.
 axmatplotlib.axes.Axes, optional
The axes to draw on. None produces a new Axes.
 climtuple of float, optional
length 2 tuple of (vmin, vmax) for the color limits
 range_x, range_ytuple of float, optional
length 2 tuple of (min, max) for the bounds of the plot axes.
 pcolor_optsdict, optional
Arguments passed on to
pcolormesh
 gridbool, optional
Whether to plot the edges of the mesh cells.
 grid_optsdict, optional
If
grid
is true, arguments passed on toplot
for grid sample_gridtuple of numpy.ndarray, optional
If
view
== ‘vec’, mesh cell widths (hx, hy) to interpolate onto for vector plotting stream_optsdict, optional
If
view
== ‘vec’, arguments passed on tostreamplot
 stream_thicknessfloat, optional
If
view
== ‘vec’, linewidth forstreamplot
 stream_thresholdfloat, optional
If
view
== ‘vec’, only plots vectors with magnitude above this threshold show_itbool, optional
Whether to call plt.show()
 numberingbool, optional
For 3D TensorMesh only, show the numbering of the slices
 annotation_colorColor or str, optional
For 3D TensorMesh only, color of the annotation
Examples
2D
TensorMesh
plotting>>> from matplotlib import pyplot as plt >>> 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.plot_image(v) >>> plt.show()
(Source code, png, pdf)
3D
TensorMesh
plotting>>> 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.plot_image(v, annotation_color='k') >>> plt.show()

TreeMesh.
plot_slice
(v, v_type='CC', normal='Z', ind=None, slice_loc=None, grid=False, view='real', ax=None, clim=None, show_it=False, pcolor_opts=None, stream_opts=None, grid_opts=None, range_x=None, range_y=None, sample_grid=None, stream_threshold=None, stream_thickness=None, **kwargs)¶ Plots slice of fields on the given 3D mesh.
 Parameters
 vnumpy.ndarray
values to plot
 v_type{‘CC’,’CCV’, ‘N’, ‘F’, ‘Fx’, ‘Fy’, ‘Fz’, ‘E’, ‘Ex’, ‘Ey’, ‘Ez’}, or tuple of these options
Where the values of v are defined.
 normal{‘Z’, ‘X’, ‘Y’}
Normal direction of slicing plane.
 indNone, optional
index along dimension of slice. Defaults to the center index.
 slice_locNone, optional
Value along dimension of slice. Defaults to the center of the mesh.
 view{‘real’, ‘imag’, ‘abs’, ‘vec’}
How to view the array.
 axmatplotlib.axes.Axes, optional
The axes to draw on. None produces a new Axes. Must be None if
v_type
is a tuple. climtuple of float, optional
length 2 tuple of (vmin, vmax) for the color limits
 range_x, range_ytuple of float, optional
length 2 tuple of (min, max) for the bounds of the plot axes.
 pcolor_optsdict, optional
Arguments passed on to
pcolormesh
 gridbool, optional
Whether to plot the edges of the mesh cells.
 grid_optsdict, optional
If
grid
is true, arguments passed on toplot
for the edges sample_gridtuple of numpy.ndarray, optional
If
view
== ‘vec’, mesh cell widths (hx, hy) to interpolate onto for vector plotting stream_optsdict, optional
If
view
== ‘vec’, arguments passed on tostreamplot
 stream_thicknessfloat, optional
If
view
== ‘vec’, linewidth forstreamplot
 stream_thresholdfloat, optional
If
view
== ‘vec’, only plots vectors with magnitude above this threshold show_itbool, optional
Whether to call plt.show()
Examples
Plot a slice of a 3D TensorMesh solution to a Laplace’s equaiton.
First build the mesh:
>>> from matplotlib import pyplot as plt >>> import discretize >>> from pymatsolver import Solver >>> hx = [(5, 2, 1.3), (2, 4), (5, 2, 1.3)] >>> hy = [(2, 2, 1.3), (2, 6), (2, 2, 1.3)] >>> hz = [(2, 2, 1.3), (2, 6), (2, 2, 1.3)] >>> M = discretize.TensorMesh([hx, hy, hz])
then build the necessary parts of the PDE:
>>> q = np.zeros(M.vnC) >>> q[[4, 4], [4, 4], [2, 6]]=[1, 1] >>> q = discretize.utils.mkvc(q) >>> A = M.face_divergence * M.cell_gradient >>> b = Solver(A) * (q)
and finaly, plot the vector values of the result, which are defined on faces
>>> M.plot_slice(M.cell_gradient*b, 'F', view='vec', grid=True, pcolor_opts={'alpha':0.8}) >>> plt.show()
(Source code, png, pdf)
We can use the slice_loc kwarg to tell `plot_slice where to slice the mesh. Let’s create a mesh with a random model and plot slice of it. The slice_loc kwarg automatically determines the indices for slicing the mesh along a plane with the given normal.
>>> M = discretize.TensorMesh([32, 32, 32]) >>> v = discretize.utils.random_model(M.vnC, seed=789).reshape(1, order='F') >>> x_slice, y_slice, z_slice = 0.75, 0.25, 0.9 >>> plt.figure(figsize=(7.5, 3)) >>> ax = plt.subplot(131) >>> M.plot_slice(v, normal='X', slice_loc=x_slice, ax=ax) >>> ax = plt.subplot(132) >>> M.plot_slice(v, normal='Y', slice_loc=y_slice, ax=ax) >>> ax = plt.subplot(133) >>> M.plot_slice(v, normal='Z', slice_loc=z_slice, ax=ax) >>> plt.tight_layout() >>> plt.show()
This also works for TreeMesh. We create a mesh here that is refined within three boxes, along with a base level of refinement.
>>> TM = discretize.TreeMesh([32, 32, 32]) >>> TM.refine(3, finalize=False) >>> BSW = [[0.25, 0.25, 0.25], [0.15, 0.15, 0.15], [0.1, 0.1, 0.1]] >>> TNE = [[0.75, 0.75, 0.75], [0.85, 0.85, 0.85], [0.9, 0.9, 0.9]] >>> levels = [6, 5, 4] >>> TM.refine_box(BSW, TNE, levels) >>> v_TM = discretize.utils.volume_average(M, TM, v) >>> plt.figure(figsize=(7.5, 3)) >>> ax = plt.subplot(131) >>> TM.plot_slice(v_TM, normal='X', slice_loc=x_slice, ax=ax) >>> ax = plt.subplot(132) >>> TM.plot_slice(v_TM, normal='Y', slice_loc=y_slice, ax=ax) >>> ax = plt.subplot(133) >>> TM.plot_slice(v_TM, normal='Z', slice_loc=z_slice, ax=ax) >>> plt.tight_layout() >>> plt.show()

TreeMesh.
point2index
(locs)[source]¶ Finds cells that contain the given points. Returns an array of index values of the cells that contain the given points
 Parameters
 locs: array_like of shape (N, dim)
points to search for the location of
 Returns
 numpy.array of integers of length(N)
Cell indices that contain the points

TreeMesh.
projectEdgeVector
(*args, **kwargs)¶ projectEdgeVector has been deprecated. See project_edge_vector for documentation

TreeMesh.
projectFaceVector
(*args, **kwargs)¶ projectFaceVector has been deprecated. See project_face_vector for documentation

TreeMesh.
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, )

TreeMesh.
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, )

TreeMesh.
readModelUBC
(*args, **kwargs)¶ readModelUBC has been deprecated. See read_model_UBC for documentation

classmethod
TreeMesh.
readUBC
(file_name, directory='')¶

classmethod
TreeMesh.
read_UBC
(meshFile, directory='')¶ 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

TreeMesh.
read_model_UBC
(file_name)¶ Read UBC OcTree model and get vector :param string file_name: path to the UBC GIF model file to read :rtype: numpy.ndarray :return: OcTree model

TreeMesh.
refine
(self, function, finalize=True)¶ Refine a TreeMesh using a user supplied function.
Refines the TreeMesh using a function that is recursively called on each cell of the mesh. It must accept an object of type discretize.TreeMesh.Cell and return an integer like object defining the desired level. The function can also simply be an integer, which will then cause all cells to be at least that level.
 Parameters
 functioncallable  int
a function describing the desired level, or an integer to refine all cells to at least that level.
 finalizebool, optional
Whether to finalize the mesh
See also
discretize.TreeMesh.TreeCell
a description of the TreeCell object
Examples
>>> from discretize import TreeMesh >>> mesh = TreeMesh([32,32]) >>> def func(cell): >>> r = np.linalg.norm(cell.center0.5) >>> return mesh.max_level if r<0.2 else mesh.max_level1 >>> mesh.refine(func) >>> mesh  QuadTreeMesh  origin: 0.00, 0.00 hx: 32*0.03, hy: 32*0.03, n_cells: 352 Fill: 34.38%

TreeMesh.
refine_ball
(self, points, radii, levels, finalize=True)¶ Refines the TreeMesh around points with the given radii
Refines the TreeMesh by determining if a cell intersects the given ball(s) to the prescribed level(s).
 Parameters
 pointsarray_like with shape (N, dim)
The centers of the balls
 radiiarray_like with shape (N)
The radii of the balls
 levelsarray_like of integers with shape (N)
The level to refine intersecting cells to
 finalizebool, optional
Whether to finalize after refining
Examples
We create a simple mesh and refine the TreeMesh such that all cells that intersect the spherical balls are at the given levels.
>>> import discretize >>> import matplotlib.pyplot as plt >>> import matplotlib.patches as patches >>> tree_mesh = discretize.TreeMesh([32, 32]) >>> tree_mesh.max_level 5
Next we define the center and radius of the two spheres, as well as the level we want to refine them to, and refine the mesh.
>>> centers = [[0.1, 0.3], [0.6, 0.8]] >>> radii = [0.2, 0.3] >>> levels = [4, 5] >>> tree_mesh.refine_ball(centers, radii, levels)
Now lets look at the mesh, and overlay the balls on it to ensure it refined where we wanted it to.
>>> ax = tree_mesh.plot_grid() >>> circ = patches.Circle(centers[0], radii[0], facecolor='none', edgecolor='r', linewidth=3) >>> ax.add_patch(circ) >>> circ = patches.Circle(centers[1], radii[1], facecolor='none', edgecolor='k', linewidth=3) >>> ax.add_patch(circ) >>> plt.show()
(Source code, png, pdf)

TreeMesh.
refine_box
(self, x0s, x1s, levels, finalize=True)¶ Refines the TreeMesh within the axis aligned boxes to the desired level
Refines the TreeMesh by determining if a cell intersects the given axis aligned box(es) to the prescribed level(s).
 Parameters
 x0sarray_like with shape (N, dim)
The minimum location of the boxes
 x1sarray_like with shape (N, dim)
The maximum location of the boxes
 levelsarray_like of integers with shape (N)
The level to refine intersecting cells to
 finalizebool, optional
Whether to finalize after refining
Examples
We create a simple mesh and refine the TreeMesh such that all cells that intersect the boxes are at the given levels.
>>> import discretize >>> import matplotlib.pyplot as plt >>> import matplotlib.patches as patches >>> tree_mesh = discretize.TreeMesh([32, 32]) >>> tree_mesh.max_level 5
Next we define the origins and furthest corners of the two rectangles, as well as the level we want to refine them to, and refine the mesh.
>>> x0s = [[0.1, 0.1], [0.8, 0.8]] >>> x1s = [[0.3, 0.2], [0.9, 1.0]] >>> levels = [4, 5] >>> tree_mesh.refine_box(x0s, x1s, levels)
Now lets look at the mesh, and overlay the boxes on it to ensure it refined where we wanted it to.
>>> ax = tree_mesh.plot_grid() >>> rect = patches.Rectangle([0.1, 0.1], 0.2, 0.1, facecolor='none', edgecolor='r', linewidth=3) >>> ax.add_patch(rect) >>> rect = patches.Rectangle([0.8, 0.8], 0.1, 0.2, facecolor='none', edgecolor='k', linewidth=3) >>> ax.add_patch(rect) >>> plt.show()
(Source code, png, pdf)

TreeMesh.
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

TreeMesh.
serialize
()[source]¶ Serializes a HasProperties instance to dictionary
This uses the Property serializers to serialize all Property values to a JSONcompatible dictionary. Properties that are undefined are not included. If the HasProperties instance contains a reference to itself, a
properties.SelfReferenceError
will be raised.Parameters:
include_class  If True (the default), the name of the class will also be saved to the serialized dictionary under key
'__class__'
save_dynamic  If True, dynamic properties are written to the serialized dict (default: False).
Any other keyword arguments will be passed through to the Property serializers.

TreeMesh.
toVTK
(models=None)¶ Convert this mesh object to it’s proper VTK or
pyvista
data object with the given model dictionary as the cell data of that dataset. Parameters
 modelsdict(numpy.ndarray)
Name(‘s) and array(‘s). Match number of cells

TreeMesh.
to_omf
(models=None)¶ Convert this mesh object to it’s proper
omf
data object with the given model dictionary as the cell data of that dataset. Parameters
 modelsdict(numpy.ndarray)
Name(‘s) and array(‘s). Match number of cells

TreeMesh.
to_vtk
(models=None)¶ Convert this mesh object to it’s proper VTK or
pyvista
data object with the given model dictionary as the cell data of that dataset. Parameters
 modelsdict(numpy.ndarray)
Name(‘s) and array(‘s). Match number of cells

TreeMesh.
validate
()¶ Call all registered class validator methods
These are all methods decorated with
@properties.validator
. Validator methods are expected to raise a ValidationError if they fail.

TreeMesh.
writeModelUBC
(*args, **kwargs)¶ writeModelUBC has been deprecated. See write_model_UBC for documentation

TreeMesh.
writeUBC
(*args, **kwargs)¶ writeUBC has been deprecated. See write_UBC for documentation

TreeMesh.
writeVTK
(file_name, models=None, directory='')¶ Makes and saves a VTK object from this mesh and given models
 Parameters
 file_namestr
path to the output vtk file or just its name if directory is specified
 modelsdict
dictionary of numpy.array  Name(‘s) and array(‘s). Match number of cells
 directorystr
directory where the UBC GIF file lives

TreeMesh.
write_UBC
(file_name, models=None, directory='')¶ Write UBC ocTree mesh and model files from a octree mesh and model. :param string file_name: File to write to :param dict models: Models in a dict, where each key is the file_name :param str directory: directory where to save model(s)

TreeMesh.
write_model_UBC
(file_name, model, directory='')¶ Writes a model associated with a TreeMesh to a UBCGIF format model file.
Input: :param str file_name: 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

TreeMesh.
write_vtk
(file_name, models=None, directory='')¶ Makes and saves a VTK object from this mesh and given models
 Parameters
 file_namestr
path to the output vtk file or just its name if directory is specified
 modelsdict
dictionary of numpy.array  Name(‘s) and array(‘s). Match number of cells
 directorystr
directory where the UBC GIF file lives