# discretize.TreeMesh¶

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

Bases: discretize.tree_ext._TreeMesh, discretize.base.base_tensor_mesh.BaseTensorMesh, discretize.InnerProducts.InnerProducts, discretize.MeshIO.TreeMeshIO

TreeMesh is a class for adaptive QuadTree (2D) and OcTree (3D) meshes.

Required Properties:

• axis_u (Vector3): Vector orientation of u-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of <class ‘float’> with shape (3), Default: X
• axis_v (Vector3): Vector orientation of v-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of <class ‘float’> with shape (3), Default: Y
• axis_w (Vector3): Vector orientation of w-direction. For more details see the docs for the rotation_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’>, <class ‘int’> with shape (*)
Attributes: area Returns a numpy array of length nF with the area (length in 2D) of all faces ordered by x, then y, then z. aveCC2F Construct the averaging operator on cell centers to cell faces. aveCC2Fx Construct the averaging operator on cell centers to cell x-faces. aveCC2Fy Construct the averaging operator on cell centers to cell y-faces. aveCC2Fz Construct the averaging operator on cell centers to cell z-faces. aveCCV2F Construct the averaging operator on cell centers to cell faces. aveE2CC Construct the averaging operator on cell edges to cell centers. aveE2CCV Construct the averaging operator on cell edges to cell centers. aveEx2CC Construct the averaging operator on cell edges in the x direction to cell centers. aveEy2CC Construct the averaging operator on cell edges in the y direction to cell centers. aveEz2CC Construct the averaging operator on cell edges in the z direction to cell centers. aveF2CC Construct the averaging operator on cell faces to cell centers. aveF2CCV Construct the averaging operator on cell faces to cell centers. aveFx2CC Construct the averaging operator on cell faces in the x direction to cell centers. aveFy2CC Construct the averaging operator on cell faces in the y direction to cell centers. aveFz2CC Construct the averaging operator on cell faces in the z direction to cell centers. aveN2CC Construct the averaging operator on cell nodes to cell centers. aveN2E Construct the averaging operator on cell nodes to cell edges, keeping each dimension separate. aveN2Ex Averaging operator on cell nodes to x-edges aveN2Ey Averaging operator on cell nodes to y-edges aveN2Ez Averaging operator on cell nodes to z-edges aveN2F Construct the averaging operator on cell nodes to cell edges, keeping each dimension separate. aveN2Fx Averaging operator on cell nodes to x-faces aveN2Fy Averaging operator on cell nodes to y-faces aveN2Fz Averaging operator on cell nodes to z-faces axis_u axis_u (Vector3): Vector orientation of u-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of with shape (3), Default: X axis_v axis_v (Vector3): Vector orientation of v-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of with shape (3), Default: Y axis_w axis_w (Vector3): Vector orientation of w-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of with shape (3), Default: Z cellBoundaryInd Returns a tuple of arrays of indexes for boundary cells in each direction cellGrad Cell centered Gradient operator built off of the faceDiv operator. cellGradStencil cellGradx Cell centered Gradient operator in x-direction (Gradx) cellGrady Cell centered Gradient operator in y-direction (Grady) cellGradz Cell centered Gradient operator in z-direction (Gradz) dim The dimension of the mesh (1, 2, or 3). edge Returns a numpy array of length nE with the length of all edges ordered by x, then y, then z. edgeCurl Construct the 3D curl operator. faceBoundaryInd Returns a tuple of arrays of indexes for boundary faces in each direction faceDiv Construct divergence operator (face-stg to cell-centres). faceDivx faceDivy faceDivz fill How filled is the mesh compared to a TensorMesh? As a fraction: [0, 1]. gridCC Returns a numpy arrayof shape (nC, dim) with the center locations of all cells in order. gridEx Returns a numpy array of shape (nEx, dim) with the centers of all non-hanging edges along the first dimension in order. gridEy Returns a numpy array of shape (nEy, dim) with the centers of all non-hanging edges along the second dimension in order. gridEz Returns a numpy array of shape (nEz, dim) with the centers of all non-hanging edges along the third dimension in order. gridFx Returns a numpy array of shape (nFx, dim) with the centers of all non-hanging faces along the first dimension in order. gridFy Returns a numpy array of shape (nFy, dim) with the centers of all non-hanging faces along the second dimension in order. gridFz Returns a numpy array of shape (nFz, dim) with the centers of all non-hanging faces along the third dimension in order. gridN Returns a numpy array of shape (nN, dim) with the locations of all non-hanging nodes in order. gridhEx Returns a numpy array of shape (nhEx, dim) with the centers of all hanging edges along the first dimension in order. gridhEy Returns a numpy array of shape (nhEy, dim) with the centers of all hanging edges along the second dimension in order. gridhEz Returns a numpy array of shape (nhEz, dim) with the centers of all hanging edges along the third dimension in order. gridhFx Returns a numpy array of shape (nhFx, dim) with the centers of all hanging faces along the first dimension in order. gridhFy Returns a numpy array of shape (nhFy, dim) with the centers of all hanging faces along the second dimension in order. gridhFz Returns a numpy array of shape (nhFz, dim) with the centers of all hanging faces along the third dimension in order. gridhN Returns a numpy array of shape (nN, dim) with the locations of all hanging nodes in order. 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 with shape (*)) with length between 0 and 3 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 maxLevel The maximum level used, which may be less than levels or max_level. max_level The maximum possible level for a cell on this mesh nC Number of cells nE Total number of non-hanging edges amongst all dimensions nEx Number of non-hanging edges oriented along the first dimension nEy Number of non-hanging edges oriented along the second dimension nEz Number of non-hanging edges oriented along the third dimension nF Total number of non-hanging faces amongst all dimensions nFx Number of non-hanging faces oriented along the first dimension nFy Number of non-hanging faces oriented along the second dimension nFz Number of non-hanging faces oriented along the third dimension nN Number of non-hanging nodes nhE Total number of hanging edges amongst all dimensions nhEx Number of hanging edges oriented along the first dimension nhEy Number of hanging edges oriented along the second dimension nhEz Number of hanging edges oriented along the third dimension nhF Total number of hanging faces amongst all dimensions nhFx Number of hanging faces oriented along the first dimension nhFy Number of hanging faces oriented along the second dimension nhFz Number of hanging faces oriented along the third dimension nhN Number of hanging nodes nodalGrad Construct gradient operator (nodes to edges). nodalLaplacian normals Face Normals ntE Total number of non-hanging and hanging edges amongst all dimensions ntEx Number of non-hanging and hanging edges oriented along the first dimension ntEy Number of non-hanging and hanging edges oriented along the second dimension ntEz Number of non-hanging and hanging edges oriented along the third dimension ntF Total number of hanging and non-hanging faces amongst all dimensions ntFx Number of non-hanging and hanging faces oriented along the first dimension ntFy Number of non-hanging and hanging faces oriented along the second dimension ntFz Number of non-hanging and hanging faces oriented along the third dimension ntN Number of non-hanging and hanging nodes permuteCC Permutation matrix re-ordering of cells sorted by x, then y, then z permuteE Permutation matrix re-ordering of edges sorted by x, then y, then z permuteF Permutation matrix re-ordering of faces sorted by x, then y, then z reference_is_rotated True if the axes are rotated from the traditional 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: cartesian rotation_matrix Builds a rotation matrix to transform coordinates from their coordinate system into a conventional cartesian system. tangents Edge Tangents 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. 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. vnE Total number of edges in each direction vnF Total number of faces in each direction vntE Total number of hanging and non-hanging edges in a [nx,ny,nz] form vntF Total number of hanging and non-hanging faces in a [nx,ny,nz] form vol Returns a numpy array of length nC with the volumes (areas in 2D) of all cells in order. x0 x0 (Array): origin of the mesh (dim, ), a list or numpy array of , with shape (*)

Methods

## Attributes¶

TreeMesh.area

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

TreeMesh.aveCC2F

Construct the averaging operator on cell centers to cell faces.

TreeMesh.aveCC2Fx

Construct the averaging operator on cell centers to cell x-faces.

TreeMesh.aveCC2Fy

Construct the averaging operator on cell centers to cell y-faces.

TreeMesh.aveCC2Fz

Construct the averaging operator on cell centers to cell z-faces.

TreeMesh.aveCCV2F

Construct the averaging operator on cell centers to cell faces.

TreeMesh.aveE2CC

Construct the averaging operator on cell edges to cell centers.

TreeMesh.aveE2CCV

Construct the averaging operator on cell edges to cell centers.

TreeMesh.aveEx2CC

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

TreeMesh.aveEy2CC

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

TreeMesh.aveEz2CC

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

TreeMesh.aveF2CC

Construct the averaging operator on cell faces to cell centers.

TreeMesh.aveF2CCV

Construct the averaging operator on cell faces to cell centers.

TreeMesh.aveFx2CC

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

TreeMesh.aveFy2CC

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

TreeMesh.aveFz2CC

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

TreeMesh.aveN2CC

Construct the averaging operator on cell nodes to cell centers.

TreeMesh.aveN2E

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

TreeMesh.aveN2Ex

Averaging operator on cell nodes to x-edges

TreeMesh.aveN2Ey

Averaging operator on cell nodes to y-edges

TreeMesh.aveN2Ez

Averaging operator on cell nodes to z-edges

TreeMesh.aveN2F

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

TreeMesh.aveN2Fx

Averaging operator on cell nodes to x-faces

TreeMesh.aveN2Fy

Averaging operator on cell nodes to y-faces

TreeMesh.aveN2Fz

Averaging operator on cell nodes to z-faces

TreeMesh.axis_u

X

Type: axis_u (Vector3) Vector orientation of u-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of with shape (3), Default
TreeMesh.axis_v

Y

Type: axis_v (Vector3) Vector orientation of v-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of with shape (3), Default
TreeMesh.axis_w

Z

Type: axis_w (Vector3) Vector orientation of w-direction. For more details see the docs for the rotation_matrix property., a 3D Vector of with shape (3), Default
TreeMesh.cellBoundaryInd

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

TreeMesh.cellGrad

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

TreeMesh.cellGradStencil
TreeMesh.cellGradx

TreeMesh.cellGrady

TreeMesh.cellGradz

TreeMesh.dim

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

Returns: dimension of the mesh int
TreeMesh.edge

Returns a numpy array of length nE with the length of all edges ordered by x, then y, then z.

TreeMesh.edgeCurl

Construct the 3D curl operator.

TreeMesh.faceBoundaryInd

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

TreeMesh.faceDiv

Construct divergence operator (face-stg to cell-centres).

TreeMesh.faceDivx
TreeMesh.faceDivy
TreeMesh.faceDivz
TreeMesh.fill

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

TreeMesh.gridCC

Returns a numpy arrayof shape (nC, dim) with the center locations of all cells in order.

TreeMesh.gridEx

Returns a numpy array of shape (nEx, dim) with the centers of all non-hanging edges along the first dimension in order.

TreeMesh.gridEy

Returns a numpy array of shape (nEy, dim) with the centers of all non-hanging edges along the second dimension in order.

TreeMesh.gridEz

Returns a numpy array of shape (nEz, dim) with the centers of all non-hanging edges along the third dimension in order.

TreeMesh.gridFx

Returns a numpy array of shape (nFx, dim) with the centers of all non-hanging faces along the first dimension in order.

TreeMesh.gridFy

Returns a numpy array of shape (nFy, dim) with the centers of all non-hanging faces along the second dimension in order.

TreeMesh.gridFz

Returns a numpy array of shape (nFz, dim) with the centers of all non-hanging faces along the third dimension in order.

TreeMesh.gridN

Returns a numpy array of shape (nN, dim) with the locations of all non-hanging nodes in order.

TreeMesh.gridhEx

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

TreeMesh.gridhEy

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

TreeMesh.gridhEz

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

TreeMesh.gridhFx

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

TreeMesh.gridhFy

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

TreeMesh.gridhFz

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

TreeMesh.gridhN

Returns a numpy array of shape (nN, dim) with the locations of all hanging nodes in order.

TreeMesh.h

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

Type: h (a list of Array)
TreeMesh.h_gridded

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

TreeMesh.hx

Width of cells in the x direction

TreeMesh.hy

Width of cells in the y direction

TreeMesh.hz

Width of cells in the z direction

TreeMesh.maxLevel

The maximum level used, which may be less than levels or max_level.

TreeMesh.max_level

The maximum possible level for a cell on this mesh

TreeMesh.nC

Number of cells

TreeMesh.nE

Total number of non-hanging edges amongst all dimensions

TreeMesh.nEx

Number of non-hanging edges oriented along the first dimension

TreeMesh.nEy

Number of non-hanging edges oriented along the second dimension

TreeMesh.nEz

Number of non-hanging edges oriented along the third dimension

TreeMesh.nF

Total number of non-hanging faces amongst all dimensions

TreeMesh.nFx

Number of non-hanging faces oriented along the first dimension

TreeMesh.nFy

Number of non-hanging faces oriented along the second dimension

TreeMesh.nFz

Number of non-hanging faces oriented along the third dimension

TreeMesh.nN

Number of non-hanging nodes

TreeMesh.nhE

Total number of hanging edges amongst all dimensions

TreeMesh.nhEx

Number of hanging edges oriented along the first dimension

TreeMesh.nhEy

Number of hanging edges oriented along the second dimension

TreeMesh.nhEz

Number of hanging edges oriented along the third dimension

TreeMesh.nhF

Total number of hanging faces amongst all dimensions

TreeMesh.nhFx

Number of hanging faces oriented along the first dimension

TreeMesh.nhFy

Number of hanging faces oriented along the second dimension

TreeMesh.nhFz

Number of hanging faces oriented along the third dimension

TreeMesh.nhN

Number of hanging nodes

TreeMesh.nodalGrad

Construct gradient operator (nodes to edges).

TreeMesh.nodalLaplacian
TreeMesh.normals

Face Normals

Return type: numpy.ndarray normals, (sum(nF), dim)
TreeMesh.ntE

Total number of non-hanging and hanging edges amongst all dimensions

TreeMesh.ntEx

Number of non-hanging and hanging edges oriented along the first dimension

TreeMesh.ntEy

Number of non-hanging and hanging edges oriented along the second dimension

TreeMesh.ntEz

Number of non-hanging and hanging edges oriented along the third dimension

TreeMesh.ntF

Total number of hanging and non-hanging faces amongst all dimensions

TreeMesh.ntFx

Number of non-hanging and hanging faces oriented along the first dimension

TreeMesh.ntFy

Number of non-hanging and hanging faces oriented along the second dimension

TreeMesh.ntFz

Number of non-hanging and hanging faces oriented along the third dimension

TreeMesh.ntN

Number of non-hanging and hanging nodes

TreeMesh.permuteCC

Permutation matrix re-ordering of cells sorted by x, then y, then z

TreeMesh.permuteE

Permutation matrix re-ordering of edges sorted by x, then y, then z

TreeMesh.permuteF

Permutation matrix re-ordering 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

cartesian

Type: 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
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.tangents

Edge Tangents

Return type: numpy.ndarray normals, (sum(nE), dim)
TreeMesh.vectorCCx

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

TreeMesh.vectorCCy

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

TreeMesh.vectorCCz

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

TreeMesh.vectorNx

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

TreeMesh.vectorNy

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

TreeMesh.vectorNz

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

TreeMesh.vnE

Total number of edges in each direction

Returns: vnE (numpy.ndarray = [nEx, nEy, nEz], (dim, )) .. plot:: – :include-source:import discretize import numpy as np M = discretize.TensorMesh([np.ones(n) for n in [2,3]]) M.plotGrid(edges=True, showIt=True)
TreeMesh.vnF

Total number of faces in each direction

Return type: numpy.ndarray [nFx, nFy, nFz], (dim, )
import discretize
import numpy as np
M = discretize.TensorMesh([np.ones(n) for n in [2,3]])
M.plotGrid(faces=True, showIt=True)

TreeMesh.vntE

Total number of hanging and non-hanging edges in a [nx,ny,nz] form

TreeMesh.vntF

Total number of hanging and non-hanging faces in a [nx,ny,nz] form

TreeMesh.vol

Returns a numpy array of length nC with the volumes (areas in 2D) of all cells in order.

TreeMesh.x0

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

Type: x0 (Array)

## Methods¶

TreeMesh.cell_levels_by_index(self, 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 Levels for the cells. numpy.array of length (N)
TreeMesh.copy(self, *args, **kwargs)[source]

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 JSON-compatible 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(self, 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()

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(self, prop=None, invProp=False, invMat=False, doFast=True)

Generate the edge inner product matrix

Parameters: prop (numpy.ndarray) – material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6)) invProp (bool) – inverts the material property invMat (bool) – inverts the matrix doFast (bool) – do a faster implementation if available. M, the inner product matrix (nE, nE) scipy.sparse.csr_matrix
TreeMesh.getEdgeInnerProductDeriv(self, prop, doFast=True, invProp=False, invMat=False)
Parameters: prop (numpy.ndarray) – material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6)) doFast (bool) – do a faster implementation if available. invProp (bool) – inverts the material property invMat (bool) – inverts the matrix dMdm, the derivative of the inner product matrix (nE, nC*nA) scipy.sparse.csr_matrix
TreeMesh.getFaceInnerProduct(self, prop=None, invProp=False, invMat=False, doFast=True)

Generate the face inner product matrix

Parameters: prop (numpy.ndarray) – material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6)) invProp (bool) – inverts the material property invMat (bool) – inverts the matrix doFast (bool) – do a faster implementation if available. M, the inner product matrix (nF, nF) scipy.sparse.csr_matrix
TreeMesh.getFaceInnerProductDeriv(self, prop, doFast=True, invProp=False, invMat=False)
Parameters: prop (numpy.ndarray) – material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6)) doFast – bool do a faster implementation if available. invProp (bool) – inverts the material property invMat (bool) – inverts the matrix dMdmu(u), the derivative of the inner product matrix for a certain u scipy.sparse.csr_matrix
TreeMesh.getInterpolationMat(self, locs, locType, zerosOutside=False)[source]

Produces interpolation matrix

Parameters: loc (numpy.ndarray) – Location of points to interpolate to locType (str) – What to interpolate 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  M, the interpolation matrix scipy.sparse.csr_matrix
TreeMesh.getTensor(self, key)

Returns a tensor list.

Parameters: key (str) – Which tensor (see below) 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  list of the tensors that make up the mesh. list
TreeMesh.get_boundary_cells()

Returns the indices of boundary cells in a given direction given an active index array.

Parameters: active_ind (array_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’) Array of indices for the boundary cells in the requested direction numpy.array
TreeMesh.get_cells_along_line()

Finds the cells along a line segment defined by two points

Parameters: x0,x1 (array_like of length (dim)) – Begining and ending point of the line segment. Indexes for cells that contain the a line defined by the two input points, ordered in the direction of the line. list of ints
TreeMesh.insert_cells()

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: points (array_like with shape (N, dim)) – levels (array_like of integers with shape (N)) – finalize (bool, 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)
x0: 0.00
y0: 0.00
hx: 32*0.03,
hy: 32*0.03,
nC: 40
Fill: 3.91%

TreeMesh.isInside(self, pts, locType='N')

Determines if a set of points are inside a mesh.

Parameters: pts (numpy.ndarray) – Location of points to test numpy.ndarray inside, numpy array of booleans
TreeMesh.load(self, *args, **kwargs)[source]
TreeMesh.number()

Number the cells, nodes, faces, and edges of the TreeMesh

TreeMesh.plotGrid()

Plot the nodel, cell-centered, and staggered grids for 2 and 3 dimensions Plots the mesh grid in either 2D or 3D of the TreeMesh

Parameters: ax (matplotlib.axes.Axes or None, optional) – The axes handle to plot on nodes (bool, optional) – Plot the nodal points faces (bool, optional) – Plot the center points of the faces centers (bool, optional) – Plot the center points of the cells edges (bool, optional) – Plot the center points of the edges lines (bool, optional) – Plot the lines connecting the nodes cell_line (bool, optional) – Plot the line through the cell centers in order faces_y, faces_z (faces_x,) – Plot the center points of the x, y, or z faces edges_y, edges_z (edges_x,) – Plot the center points of the x, y, or z edges showIt (bool, optional) – whether to call plt.show() within the codes color (Color or str, optional) – if lines=True, the color of the lines, defaults to first color. linewidth (float, optional) – if lines=True, the linewidth for the lines. Axes handle for the plot matplotlib.axes.Axes
TreeMesh.plotImage()

Plots an image of values defined on the TreeMesh If 3D, this function plots a default slice of the TreeMesh

Parameters: v (array_like) – Array containing the values to plot vType (str, optional) – type of value in v one of ‘CC’, ‘N’, ‘Fx’, ‘Fy’, ‘Fz’, ‘Ex’, ‘Ey’, or ‘Ez’ grid (bool, optional) – plot the grid lines view (['real', 'imag', 'abs'], optional) – The values to plot from v ax (matplotlib.axes.Axes or None, optional) – The axes handle clim (array_like of length 2, or None, optional) – A pair of [min, max] for the Colorbar pcolorOpts (dict, or None) – options to be passed on to pcolormesh gridOpt (dict, or None) – options for the plotting the grid range_y (range_x,) – pairs of [min, max] values for the x and y ranges
TreeMesh.plotSlice(self, 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)[source]
TreeMesh.point2index(self, 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 Cell indices that contain the points numpy.array of integers of length(N)
TreeMesh.projectEdgeVector(self, eV)

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

Parameters: eV (numpy.ndarray) – edge vector with shape (nE, dim) numpy.ndarray projected edge vector, (nE, )
TreeMesh.projectFaceVector(self, fV)

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

Parameters: fV (numpy.ndarray) – face vector with shape (nF, dim) numpy.ndarray projected face vector, (nF, )
TreeMesh.readModelUBC(mesh, fileName)

Read UBC OcTree model and get vector :param string fileName: path to the UBC GIF model file to read :rtype: numpy.ndarray :return: OcTree model

classmethod TreeMesh.readUBC(meshFile)

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.refine()

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: function (callable | int) – a function describing the desired level, or an integer to refine all cells to at least that level. finalize (bool, optional) – Whether to finalize the mesh

Examples

>>> from discretize import TreeMesh
>>> mesh = TreeMesh([32,32])
>>> def func(cell):
>>>     r = np.linalg.norm(cell.center-0.5)
>>>     return mesh.max_level if r<0.2 else mesh.max_level-1
>>> mesh.refine(func)
>>> mesh
x0: 0.00
y0: 0.00
hx: 32*0.03,
hy: 32*0.03,
nC: 352
Fill: 34.38%


discretize.TreeMesh.TreeCell()
a description of the TreeCell object
TreeMesh.save(self, filename='mesh.json', verbose=False)

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

TreeMesh.serialize(self)[source]

Serializes a HasProperties instance to dictionary

This uses the Property serializers to serialize all Property values to a JSON-compatible 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(mesh, 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: models (dict(numpy.ndarray)) – Name(‘s) and array(‘s). Match number of cells
TreeMesh.to_omf(mesh, 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: models (dict(numpy.ndarray)) – Name(‘s) and array(‘s). Match number of cells
TreeMesh.to_vtk(mesh, 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: models (dict(numpy.ndarray)) – Name(‘s) and array(‘s). Match number of cells
TreeMesh.validate(self)

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.writeUBC(mesh, fileName, models=None)

Write UBC ocTree mesh and model files from a octree mesh and model. :param string fileName: File to write to :param dict models: Models in a dict, where each key is the filename

TreeMesh.writeVTK(mesh, filename, models=None, directory='')

Makes and saves a VTK object from this mesh and given models

Parameters: filename (str) – path to the output vtk file or just its name if directory is specified models (dict) – dictionary of numpy.array - Name(‘s) and array(‘s). Match number of cells directory (str) – directory where the UBC GIF file lives
TreeMesh.write_vtk(mesh, filename, models=None, directory='')

Makes and saves a VTK object from this mesh and given models

Parameters: filename (str) – path to the output vtk file or just its name if directory is specified models (dict) – dictionary of numpy.array - Name(‘s) and array(‘s). Match number of cells directory (str) – directory where the UBC GIF file lives