discretize.base.BaseRectangularMesh

class discretize.base.BaseRectangularMesh(n, x0=None, **kwargs)[source]

Bases: discretize.base.base_mesh.BaseMesh

BaseRectangularMesh

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

BaseRectangularMesh.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
BaseRectangularMesh.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
BaseRectangularMesh.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
BaseRectangularMesh.dim

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

Returns:dimension of the mesh
Return type:int
BaseRectangularMesh.nC

Total number of cells

Return type:int
Returns:nC
BaseRectangularMesh.nCx

Number of cells in the x direction

Return type:int
Returns:nCx
BaseRectangularMesh.nCy

Number of cells in the y direction

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

Number of cells in the z direction

Return type:int
Returns:nCz or None if dim < 3
BaseRectangularMesh.nE

Total number of edges.

Returns:nE
Return type:int = sum([nEx, nEy, nEz])
BaseRectangularMesh.nEx

Number of x-edges

Return type:int
Returns:nEx
BaseRectangularMesh.nEy

Number of y-edges

Return type:int
Returns:nEy
BaseRectangularMesh.nEz

Number of z-edges

Return type:int
Returns:nEz
BaseRectangularMesh.nF

Total number of faces.

Return type:int
Returns:sum([nFx, nFy, nFz])
BaseRectangularMesh.nFx

Number of x-faces

Return type:int
Returns:nFx
BaseRectangularMesh.nFy

Number of y-faces

Return type:int
Returns:nFy
BaseRectangularMesh.nFz

Number of z-faces

Return type:int
Returns:nFz
BaseRectangularMesh.nN

Total number of nodes

Return type:int
Returns:nN
BaseRectangularMesh.nNx

Number of nodes in the x-direction

Return type:int
Returns:nNx
BaseRectangularMesh.nNy

Number of nodes in the y-direction

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

Number of nodes in the z-direction

Return type:int
Returns:nNz or None if dim < 3
BaseRectangularMesh.normals

Face Normals

Return type:numpy.ndarray
Returns:normals, (sum(nF), dim)
BaseRectangularMesh.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)\)

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

BaseRectangularMesh.tangents

Edge Tangents

Return type:numpy.ndarray
Returns:normals, (sum(nE), dim)
BaseRectangularMesh.vnC

Total number of cells in each direction

Return type:numpy.ndarray
Returns:[nCx, nCy, nCz]
BaseRectangularMesh.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)

BaseRectangularMesh.vnEx

Number of x-edges in each direction

Return type:numpy.ndarray
Returns:vnEx
BaseRectangularMesh.vnEy

Number of y-edges in each direction

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

Number of z-edges in each direction

Return type:numpy.ndarray
Returns:vnEz or None if dim < 3
BaseRectangularMesh.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, png, hires.png, pdf)

../../_images/discretize-base-BaseRectangularMesh-1.png
BaseRectangularMesh.vnFx

Number of x-faces in each direction

Return type:numpy.ndarray
Returns:vnFx
BaseRectangularMesh.vnFy

Number of y-faces in each direction

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

Number of z-faces in each direction

Return type:numpy.ndarray
Returns:vnFz or None if dim < 3
BaseRectangularMesh.vnN

Total number of nodes in each direction

Return type:numpy.ndarray
Returns:[nNx, nNy, nNz]
BaseRectangularMesh.x0

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

Type:x0 (Array)

Methods

BaseRectangularMesh.copy()

Make a copy of the current mesh

classmethod BaseRectangularMesh.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.
BaseRectangularMesh.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.

BaseRectangularMesh.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, )
BaseRectangularMesh.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, )
BaseRectangularMesh.r(x, xType='CC', outType='CC', format='V')[source]

r is a quick reshape command that will do the best it can at giving you what you want.

For example, you have a face variable, and you want the x component of it reshaped to a 3D matrix.

r can fulfil your dreams:

mesh.r(V, 'F', 'Fx', 'M')
       |   |     |    |
       |   |     |    {
       |   |     |      How: 'M' or ['V'] for a matrix
       |   |     |      (ndgrid style) or a vector (n x dim)
       |   |     |    }
       |   |     {
       |   |       What you want: ['CC'], 'N',
       |   |                       'F', 'Fx', 'Fy', 'Fz',
       |   |                       'E', 'Ex', 'Ey', or 'Ez'
       |   |     }
       |   {
       |     What is it: ['CC'], 'N',
       |                  'F', 'Fx', 'Fy', 'Fz',
       |                  'E', 'Ex', 'Ey', or 'Ez'
       |   }
       {
         The input: as a list or ndarray
       }

For example:

# Separates each component of the Ex grid into 3 matrices
Xex, Yex, Zex = r(mesh.gridEx, 'Ex', 'Ex', 'M')

# Given an edge vector, return just the x edges as a vector
XedgeVector = r(edgeVector, 'E', 'Ex', 'V')

# Separates each component of the edgeVector into 3 vectors
eX, eY, eZ = r(edgeVector, 'E', 'E', 'V')
BaseRectangularMesh.save(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

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

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