discretize.base.BaseTensorMesh¶

class
discretize.base.
BaseTensorMesh
(h=None, x0=None, **kwargs)[source]¶ Bases:
discretize.base.base_mesh.BaseMesh
Base class for tensorproduct style meshes
This class contains properites and methods that are common to cartesian and cylindrical meshes defined by tensorproduts of vectors describing cell spacings.
Do not use this class directly, instead, inherit it if you plan to develop a tensorstyle mesh (e.g. a spherical mesh) or use the
discretize.TensorMesh()
class to create a cartesian tensor mesh.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: X  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  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  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: 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: Zdim
The dimension of the mesh (1, 2, or 3).
gridCC
Cellcentered grid.
gridEx
Edge staggered grid in the x direction.
gridEy
Edge staggered grid in the y direction.
gridEz
Edge staggered grid in the z direction.
gridFx
Face staggered grid in the x direction.
gridFy
Face staggered grid in the y direction.
gridFz
Face staggered grid in the z direction.
gridN
Nodal grid.
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 <class ‘float’> with shape (*)) with length between 0 and 3h_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
nC
Total number of cells in the mesh.
nE
Total number of edges.
nEx
Number of xedges
nEy
Number of yedges
nEz
Number of zedges
nF
Total number of faces.
nFx
Number of xfaces
nFy
Number of yfaces
nFz
Number of zfaces
nN
Total number of nodes
normals
Face Normals
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.
tangents
Edge Tangents
vectorCCx
Cellcentered grid vector (1D) in the x direction.
vectorCCy
Cellcentered grid vector (1D) in the y direction.
vectorCCz
Cellcentered 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
x0
x0 (
Array
): origin of the mesh (dim, ), a list or numpy array of <class ‘float’>, <class ‘int’> with shape (*)
Methods
copy
(self)Make a copy of the current mesh deserialize
(value[, trusted, strict, …])Creates HasProperties instance from serialized dictionary equal
(self, other)Determine if two HasProperties instances are equivalent from_omf
(element)Convert an OMF element to it’s proper discretize
type.getInterpolationMat
(self, loc[, locType, …])Produces interpolation matrix getTensor
(self, key)Returns a tensor list. isInside
(self, pts[, locType])Determines if a set of points are inside a mesh. projectEdgeVector
(self, eV)Given a vector, eV, in cartesian coordinates, this will project it onto the mesh using the tangents projectFaceVector
(self, fV)Given a vector, fV, in cartesian coordinates, this will project it onto the mesh using the normals save
(self[, filename, verbose])Save the mesh to json :param str file: filename for saving the casing properties :param str directory: working directory for saving the file serialize
(self[, include_class, save_dynamic])Serializes a HasProperties instance to dictionary toVTK
(mesh[, 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
(mesh[, 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
(mesh[, 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
(self)Call all registered class validator methods writeVTK
(mesh, filename[, models, directory])Makes and saves a VTK object from this mesh and given models write_vtk
(mesh, filename[, models, directory])Makes and saves a VTK object from this mesh and given models  axis_u (
Attributes¶

BaseTensorMesh.
axis_u
¶ X
Type: axis_u ( Vector3
)Type: Vector orientation of udirection. For more details see the docs for the rotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default

BaseTensorMesh.
axis_v
¶ Y
Type: axis_v ( Vector3
)Type: Vector orientation of vdirection. For more details see the docs for the rotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default

BaseTensorMesh.
axis_w
¶ Z
Type: axis_w ( Vector3
)Type: Vector orientation of wdirection. For more details see the docs for the rotation_matrix
property., a 3D Vector of <class ‘float’> with shape (3), Default

BaseTensorMesh.
dim
¶ The dimension of the mesh (1, 2, or 3).
Returns: dimension of the mesh Return type: int

BaseTensorMesh.
gridCC
¶ Cellcentered grid.

BaseTensorMesh.
gridEx
¶ Edge staggered grid in the x direction.

BaseTensorMesh.
gridEy
¶ Edge staggered grid in the y direction.

BaseTensorMesh.
gridEz
¶ Edge staggered grid in the z direction.

BaseTensorMesh.
gridFx
¶ Face staggered grid in the x direction.

BaseTensorMesh.
gridFy
¶ Face staggered grid in the y direction.

BaseTensorMesh.
gridFz
¶ Face staggered grid in the z direction.

BaseTensorMesh.
gridN
¶ Nodal grid.

BaseTensorMesh.
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
)

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

BaseTensorMesh.
hx
¶ Width of cells in the x direction

BaseTensorMesh.
hy
¶ Width of cells in the y direction

BaseTensorMesh.
hz
¶ Width of cells in the z direction

BaseTensorMesh.
nC
¶ Total number of cells in the mesh.
Returns: number of cells in the mesh Return type: int Example
import discretize import numpy as np mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]]) mesh.plotGrid(centers=True, showIt=True) print(mesh.nC)
(Source code, png, hires.png, pdf)

BaseTensorMesh.
nE
¶ Total number of edges.
Returns: nE Return type: int = sum([nEx, nEy, nEz])

BaseTensorMesh.
nN
¶ Total number of nodes
Returns: number of nodes in the mesh Return type: int Example
import discretize import numpy as np mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]]) mesh.plotGrid(nodes=True, showIt=True) print(mesh.nN)
(Source code, png, hires.png, pdf)

BaseTensorMesh.
normals
¶ Face Normals
Return type: numpy.ndarray Returns: normals, (sum(nF), dim)

BaseTensorMesh.
reference_is_rotated
¶ True if the axes are rotated from the traditional <X,Y,Z> system with vectors of \((1,0,0)\), \((0,1,0)\), and \((0,0,1)\)

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

BaseTensorMesh.
rotation_matrix
¶ Builds a rotation matrix to transform coordinates from their coordinate system into a conventional cartesian system. This is built off of the three axis_u, axis_v, and axis_w properties; these mapping coordinates use the letters U, V, and W (the three letters preceding X, Y, and Z in the alphabet) to define the projection of the X, Y, and Z durections. These UVW vectors describe the placement and transformation of the mesh’s coordinate sytem assuming at most 3 directions.
Why would you want to use these UVW mapping vectors the this rotation_matrix property? They allow us to define the 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
.

BaseTensorMesh.
tangents
¶ Edge Tangents
Return type: numpy.ndarray Returns: normals, (sum(nE), dim)

BaseTensorMesh.
vectorCCx
¶ Cellcentered grid vector (1D) in the x direction.

BaseTensorMesh.
vectorCCy
¶ Cellcentered grid vector (1D) in the y direction.

BaseTensorMesh.
vectorCCz
¶ Cellcentered grid vector (1D) in the z direction.

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

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

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

BaseTensorMesh.
vnE
¶ Total number of edges in each direction
Returns:  vnE (numpy.ndarray = [nEx, nEy, nEz], (dim, ))
 .. plot:: – :includesource:
import discretize import numpy as np M = discretize.TensorMesh([np.ones(n) for n in [2,3]]) M.plotGrid(edges=True, showIt=True)

BaseTensorMesh.
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)
Methods¶

BaseTensorMesh.
copy
(self)¶ Make a copy of the current mesh

classmethod
BaseTensorMesh.
deserialize
(value, trusted=False, strict=False, assert_valid=False, **kwargs)¶ 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.

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

static
BaseTensorMesh.
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.

BaseTensorMesh.
getInterpolationMat
(self, loc, locType='CC', zerosOutside=False)[source]¶ Produces interpolation matrix
Parameters:  loc (numpy.ndarray) – Location of points to interpolate to
 locType (str) –
What to interpolate (see below)
locType 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 'CCVx' > xcomponent of vector field defined on cell centers 'CCVy' > ycomponent of vector field defined on cell centers 'CCVz' > zcomponent of vector field defined on cell centers
Returns: M, the interpolation matrix
Return type:

BaseTensorMesh.
getTensor
(self, key)[source]¶ 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' > xcomponent of field defined on faces 'Fy' > ycomponent of field defined on faces 'Fz' > zcomponent of field defined on faces 'Ex' > xcomponent of field defined on edges 'Ey' > ycomponent of field defined on edges 'Ez' > zcomponent of field defined on edges
Returns: list of the tensors that make up the mesh. Return type: list

BaseTensorMesh.
isInside
(self, pts, locType='N')[source]¶ Determines if a set of points are inside a mesh.
Parameters: pts (numpy.ndarray) – Location of points to test Return type: numpy.ndarray Returns: inside, numpy array of booleans

BaseTensorMesh.
projectEdgeVector
(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) Return type: numpy.ndarray Returns: projected edge vector, (nE, )

BaseTensorMesh.
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) Return type: numpy.ndarray Returns: projected face vector, (nF, )

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

BaseTensorMesh.
serialize
(self, 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 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.
 include_class  If True (the default), the name of the class
will also be saved to the serialized dictionary under key

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

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

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

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

BaseTensorMesh.
writeVTK
(mesh, filename, models=None, directory='')¶ Makes and saves a VTK object from this mesh and given models
Parameters:

BaseTensorMesh.
write_vtk
(mesh, filename, models=None, directory='')¶ Makes and saves a VTK object from this mesh and given models
Parameters: