discretize.base.BaseTensorMesh¶

class
discretize.base.
BaseTensorMesh
(*args, **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: 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 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 3reference_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: cartesianx0 (
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
()Make a copy of the current mesh
deserialize
(value[, trusted, strict, …])Creates HasProperties instance from serialized dictionary
equal
(other)Determine if two HasProperties instances are equivalent
from_omf
(element)Convert an OMF element to it’s proper
discretize
type.getInterpolationMat
(loc[, locType, zerosOutside])Produces interpolation matrix
getTensor
(key)Returns a tensor list.
isInside
(pts[, locType])Determines if a set of points are inside a mesh.
Given a vector, eV, in cartesian coordinates, this will project it onto the mesh using the tangents
Given a vector, fV, in cartesian coordinates, this will project it onto the mesh using the normals
save
([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
([include_class, save_dynamic])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
writeVTK
(filename[, models, directory])Makes and saves a VTK object from this mesh and given models
write_vtk
(filename[, models, directory])Makes and saves a VTK object from this mesh and given models
Attributes¶

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

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

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

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

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

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
 int
number of cells in the mesh
Examples
import discretize import numpy as np mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]]) mesh.plotGrid(centers=True, show_it=True) print(mesh.nC)
(Source code, png, pdf)

BaseTensorMesh.
nE
¶ Total number of edges.
 Returns
 nEint = sum([nEx, nEy, nEz])

BaseTensorMesh.
nEx
¶ Number of xedges
 Returns
 nExint

BaseTensorMesh.
nEy
¶ Number of yedges
 Returns
 nEyint

BaseTensorMesh.
nEz
¶ Number of zedges
 Returns
 nEzint

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

BaseTensorMesh.
normals
¶ Face Normals
 Return type
 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
¶ 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

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
 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
 vnEnumpy.ndarray = [nEx, nEy, nEz], (dim, )
import discretize import numpy as np M = discretize.TensorMesh([np.ones(n) for n in [2,3]]) M.plotGrid(edges=True, show_it=True)
(Source code, png, pdf)

BaseTensorMesh.
vnF
¶ Total number of faces in each direction
 Return type
 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, show_it=True)
(Source code, png, pdf)
Methods¶

BaseTensorMesh.
copy
()¶ 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
(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
(loc, locType='CC', zerosOutside=False)[source]¶ Produces interpolation matrix
 Parameters
 locnumpy.ndarray
Location of points to interpolate to
 locTypestr
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
 scipy.sparse.csr_matrix
M, the interpolation matrix

BaseTensorMesh.
getTensor
(key)[source]¶ Returns a tensor list.
 Parameters
 keystr
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
list of the tensors that make up the mesh.

BaseTensorMesh.
isInside
(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
 Returns
inside, numpy array of booleans

BaseTensorMesh.
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
 Returns
projected edge vector, (nE, )

BaseTensorMesh.
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
 Returns
projected face vector, (nF, )

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

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

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

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

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

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

BaseTensorMesh.
writeVTK
(filename, models=None, directory='')¶ Makes and saves a VTK object from this mesh and given models
 Parameters
 filenamestr
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

BaseTensorMesh.
write_vtk
(filename, models=None, directory='')¶ Makes and saves a VTK object from this mesh and given models
 Parameters
 filenamestr
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