discretize.TreeMesh

class discretize.TreeMesh(h, 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’> with shape (*)

Attributes

TreeMesh.area
TreeMesh.aveCC2F
TreeMesh.aveCC2Fx
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
TreeMesh.aveE2CC
TreeMesh.aveE2CCV
TreeMesh.aveEx2CC
TreeMesh.aveEy2CC
TreeMesh.aveEz2CC
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
TreeMesh.aveFy2CC
TreeMesh.aveFz2CC
TreeMesh.aveN2CC
TreeMesh.aveN2E

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

TreeMesh.aveN2Ex
TreeMesh.aveN2Ey
TreeMesh.aveN2Ez
TreeMesh.aveN2F

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

TreeMesh.aveN2Fx
TreeMesh.aveN2Fy
TreeMesh.aveN2Fz
TreeMesh.axis_u

X

Type:axis_u (Vector3)
Type: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
TreeMesh.axis_v

Y

Type:axis_v (Vector3)
Type: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
TreeMesh.axis_w

Z

Type:axis_w (Vector3)
Type: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
TreeMesh.cellBoundaryInd
TreeMesh.cellGrad

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

TreeMesh.cellGradStencil
TreeMesh.cellGradx

Cell centered Gradient operator in x-direction (Gradx) Grad = sp.vstack((Gradx, Grady, Gradz))

TreeMesh.cellGrady

Cell centered Gradient operator in y-direction (Gradx) Grad = sp.vstack((Gradx, Grady, Gradz))

TreeMesh.cellGradz

Cell centered Gradient operator in z-direction (Gradz) Grad = sp.vstack((Gradx, Grady, Gradz))

TreeMesh.dim

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

Returns:dimension of the mesh
Return type:int
TreeMesh.edge
TreeMesh.edgeCurl
TreeMesh.faceBoundaryInd
TreeMesh.faceDiv
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 an M by N numpy array with the center locations of all cells in order. M is the number of cells and N=2,3 is the dimension of the mesh.

TreeMesh.gridEx
TreeMesh.gridEy
TreeMesh.gridEz
TreeMesh.gridFx
TreeMesh.gridFy
TreeMesh.gridFz
TreeMesh.gridN

Returns an M by N numpy array with the widths of all cells in order. M is the number of nodes and N=2,3 is the dimension of the mesh.

TreeMesh.gridhEx
TreeMesh.gridhEy
TreeMesh.gridhEz
TreeMesh.gridhFx
TreeMesh.gridhFy
TreeMesh.gridhFz
TreeMesh.gridhN
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.

TreeMesh.max_level
TreeMesh.nC
TreeMesh.nE
TreeMesh.nEx
TreeMesh.nEy
TreeMesh.nEz
TreeMesh.nF
TreeMesh.nFx
TreeMesh.nFy
TreeMesh.nFz
TreeMesh.nN
TreeMesh.nhE
TreeMesh.nhEx
TreeMesh.nhEy
TreeMesh.nhEz
TreeMesh.nhF
TreeMesh.nhFx
TreeMesh.nhFy
TreeMesh.nhFz
TreeMesh.nhN
TreeMesh.nodalGrad
TreeMesh.normals

Face Normals

Return type:numpy.ndarray
Returns:normals, (sum(nF), dim)
TreeMesh.ntE
TreeMesh.ntEx
TreeMesh.ntEy
TreeMesh.ntEz
TreeMesh.ntF
TreeMesh.ntFx
TreeMesh.ntFy
TreeMesh.ntFz
TreeMesh.ntN
TreeMesh.permuteCC
TreeMesh.permuteE
TreeMesh.permuteF
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)
Type: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 vtkInterface.

TreeMesh.tangents

Edge Tangents

Return type:numpy.ndarray
Returns: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
Returns:[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)

(Source code)

../../_images/discretize-TreeMesh-1.png
TreeMesh.vntE
TreeMesh.vntF
TreeMesh.vol
TreeMesh.x0

Methods

TreeMesh.copy(*args, **kwargs)[source]

Make a copy of the current mesh

classmethod TreeMesh.deserialize(value, trusted=False, strict=False, assert_valid=False, **kwargs)

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(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()
TreeMesh.getEdgeInnerProduct(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.
Returns:

M, the inner product matrix (nE, nE)

Return type:

scipy.sparse.csr_matrix

TreeMesh.getEdgeInnerProductDeriv(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
Returns:

dMdm, the derivative of the inner product matrix (nE, nC*nA)

Return type:

scipy.sparse.csr_matrix

TreeMesh.getFaceInnerProduct(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.
Returns:

M, the inner product matrix (nF, nF)

Return type:

scipy.sparse.csr_matrix

TreeMesh.getFaceInnerProductDeriv(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
Returns:

dMdmu(u), the derivative of the inner product matrix for a certain u

Return type:

scipy.sparse.csr_matrix

TreeMesh.getInterpolationMat()
TreeMesh.getTensor(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
Returns:list of the tensors that make up the mesh.
Return type:list
TreeMesh.insert_cells()
TreeMesh.isInside(pts, locType='N')

Determines if a set of points are inside a mesh.

Parameters:pts (numpy.ndarray) – Location of points to test
Return type:numpy.ndarray
Returns:inside, numpy array of booleans
TreeMesh.load(*args, **kwargs)[source]
TreeMesh.number()
TreeMesh.plotGrid()
TreeMesh.plotImage()
TreeMesh.plotSlice(v, vType='CC', normal='Z', ind=None, grid=True, view='real', ax=None, clim=None, showIt=False, pcolorOpts=None, streamOpts=None, gridOpts=None)[source]
TreeMesh.point2index(locs)[source]
TreeMesh.projectEdgeVector(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)
Return type:numpy.ndarray
Returns:projected edge vector, (nE, )
TreeMesh.projectFaceVector(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)
Return type:numpy.ndarray
Returns:projected face vector, (nF, )
TreeMesh.readModelUBC(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()
TreeMesh.save(*args, **kwargs)[source]

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(include_class=True, save_dynamic=False, **kwargs)

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(models=None)

Convert this mesh object to it’s proper vtki 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()

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