discretize.base.BaseMesh

class discretize.base.BaseMesh(shape_cells, origin=None, orientation=None, reference_system=None, **kwargs)

Bases: object

BaseMesh does all the counting you don’t want to do. BaseMesh should be inherited by meshes with a regular structure.

Attributes
axis_u

Deprecated since version 0.7.0.

axis_v

Deprecated since version 0.7.0.

axis_w

Deprecated since version 0.7.0.

dim

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

edge_tangents

Edge Tangents

face_normals

Face Normals

n_cells

Total number of cells in the mesh.

n_edges

Total number of edges.

n_edges_per_direction

The number of edges in each direction

n_edges_x

Number of x-edges

n_edges_y

Number of y-edges

n_edges_z

Number of z-edges

n_faces

Total number of faces.

n_faces_per_direction

The number of faces in each direction

n_faces_x

Number of x-faces

n_faces_y

Number of y-faces

n_faces_z

Number of z-faces

n_nodes

Total number of nodes

normals

normals has been deprecated. See face_normals for documentation

orientation
origin

Origin of the mesh

reference_is_rotated

True if the axes are rotated from the traditional <X,Y,Z> system

reference_system

The type of coordinate reference frame.

rotation_matrix

Builds a rotation matrix to transform coordinates from their coordinate system into a conventional cartesian system.

shape_cells

The number of cells in each direction

tangents

tangents has been deprecated. See edge_tangents for documentation

x0

Methods

copy()

Make a copy of the current mesh

projectEdgeVector(*args, **kwargs)

projectEdgeVector has been deprecated.

projectFaceVector(*args, **kwargs)

projectFaceVector has been deprecated.

project_edge_vector(edge_vector)

Project vectors onto the edges of the mesh

project_face_vector(face_vector)

Project vectors onto the faces of the mesh.

save([file_name, verbose])

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

validate()

Every object will be valid upon initialization

deserialize

equals

serialize

to_dict

Attributes

BaseMesh.axis_u

Deprecated since version 0.7.0: axis_u will be removed in discretize 1.0.0, it is replaced by mesh.orientation for better mesh orientation validation.

See also

orientation
BaseMesh.axis_v

Deprecated since version 0.7.0: axis_v will be removed in discretize 1.0.0, it is replaced by mesh.orientation for better mesh orientation validation.

See also

orientation
BaseMesh.axis_w

Deprecated since version 0.7.0: axis_w will be removed in discretize 1.0.0, it is replaced by mesh.orientation for better mesh orientation validation.

See also

orientation
BaseMesh.dim

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

Returns
int

dimension of the mesh

BaseMesh.edge_tangents

Edge Tangents

Returns
numpy.ndarray

normals, (n_edges, dim)

BaseMesh.face_normals

Face Normals

Returns
numpy.ndarray

normals, (n_faces, dim)

BaseMesh.n_cells

Total number of cells in the mesh.

Returns
int

number of cells in the mesh

Notes

Also accessible as nC.

Examples

>>> import discretize
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> mesh.plot_grid(centers=True, show_it=True)
>>> print(mesh.n_cells)

(Source code, png, pdf)

../../_images/discretize-base-BaseMesh-1.png
BaseMesh.n_edges

Total number of edges.

Returns
int

sum([n_edges_x, n_edges_y, n_edges_z])

Notes

Also accessible as nE.

BaseMesh.n_edges_per_direction

The number of edges in each direction

Returns
n_edges_per_directiontuple

[n_edges_x, n_edges_y, n_edges_z], (dim, )

Notes

Also accessible as vnE.

Examples

>>> import discretize
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> M = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> M.plot_grid(edges=True, show_it=True)

(Source code, png, pdf)

../../_images/discretize-base-BaseMesh-2.png
BaseMesh.n_edges_x

Number of x-edges

Returns
int

Notes

Also accessible as nEx.

BaseMesh.n_edges_y

Number of y-edges

Returns
int

Notes

Also accessible as nEy.

BaseMesh.n_edges_z

Number of z-edges

Returns
int

Notes

Also accessible as nEz.

BaseMesh.n_faces

Total number of faces.

Returns
int

sum([n_faces_x, n_faces_y, n_faces_z])

Notes

Also accessible as nF.

BaseMesh.n_faces_per_direction

The number of faces in each direction

Returns
n_faces_per_directiontuple

[n_faces_x, n_faces_y, n_faces_z], (dim, )

Notes

Also accessible as vnF.

Examples

>>> import discretize
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> M = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> M.plot_grid(faces=True, show_it=True)

(Source code, png, pdf)

../../_images/discretize-base-BaseMesh-3.png
BaseMesh.n_faces_x

Number of x-faces

Returns
int

Notes

Also accessible as nFx.

BaseMesh.n_faces_y

Number of y-faces

Returns
int

Notes

Also accessible as nFy.

BaseMesh.n_faces_z

Number of z-faces

Returns
int

Notes

Also accessible as nFz.

BaseMesh.n_nodes

Total number of nodes

Returns
int

number of nodes in the mesh

Notes

Also accessible as nN.

Examples

>>> import discretize
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> mesh = discretize.TensorMesh([np.ones(n) for n in [2,3]])
>>> mesh.plot_grid(nodes=True, show_it=True)
>>> print(mesh.n_nodes)

(Source code, png, pdf)

../../_images/discretize-base-BaseMesh-4.png
BaseMesh.normals

normals has been deprecated. See face_normals for documentation

BaseMesh.orientation
BaseMesh.origin

Origin of the mesh

BaseMesh.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)\)

BaseMesh.reference_system

The type of coordinate reference frame. Can take on the values

BaseMesh.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 relationship 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.

BaseMesh.shape_cells

The number of cells in each direction

Returns
tuple of ints

Notes

Also accessible as vnC.

BaseMesh.tangents

tangents has been deprecated. See edge_tangents for documentation

BaseMesh.x0

Methods

BaseMesh.copy()[source]

Make a copy of the current mesh

classmethod BaseMesh.deserialize(items, **kwargs)[source]
BaseMesh.equals(other)[source]
BaseMesh.projectEdgeVector(*args, **kwargs)

projectEdgeVector has been deprecated. See project_edge_vector for documentation

BaseMesh.projectFaceVector(*args, **kwargs)

projectFaceVector has been deprecated. See project_face_vector for documentation

BaseMesh.project_edge_vector(edge_vector)[source]

Project vectors onto the edges of the mesh

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

Parameters
edge_vectornumpy.ndarray

edge vector with shape (n_edges, dim)

Returns
numpy.ndarray

projected edge vector, (n_edges, )

BaseMesh.project_face_vector(face_vector)[source]

Project vectors onto the faces of the mesh.

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

Parameters
face_vectornumpy.ndarray

face vector with shape (n_faces, dim)

Returns
numpy.ndarray

projected face vector, (n_faces, )

BaseMesh.save(file_name='mesh.json', verbose=False, **kwargs)[source]

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

BaseMesh.serialize()[source]
BaseMesh.to_dict()[source]
BaseMesh.validate()[source]

Every object will be valid upon initialization