discretize.tensor_cell.TensorCell#
- class discretize.tensor_cell.TensorCell(h, origin, index_unraveled, mesh_shape)[source]#
Representation of a cell in a TensorMesh.
- Parameters:
- h(
dim
)numpy.ndarray
Array with the cell widths along each direction. For a 2D mesh, it must have two elements (
hx
,hy
). For a 3D mesh it must have three elements (hx
,hy
,hz
).- origin(
dim
)numpy.ndarray
Array with the coordinates of the origin of the cell, i.e. the bottom-left-frontmost corner.
- index_unraveled(
dim
)tuple
Array with the unraveled indices of the cell in its parent mesh.
- mesh_shape(
dim
)tuple
Shape of the parent mesh.
- h(
Attributes
Bounds of the cell.
Coordinates of the cell center.
Dimensions of the cell (1, 2 or 3).
Indices for this cell's edges within its parent mesh.
Indices for cell's faces within its parent mesh.
Cell widths.
Index of the cell in a TensorMesh.
Unraveled index of the cell in a TensorMesh.
Shape of the parent mesh.
Indices for this cell's neighbors within its parent mesh.
Indices for this cell's nodes within its parent mesh.
Coordinates of the origin of the cell.
Methods
get_neighbors
(mesh)Return the neighboring cells in the mesh.
Examples
Define a simple
discretize.TensorMesh
.>>> from discretize import TensorMesh >>> mesh = TensorMesh([5, 8, 10])
We can obtain a particular cell in the mesh by its index:
>>> cell = mesh[3] >>> cell TensorCell(h=[0.2 0.125 0.1 ], origin=[0.6 0. 0. ], index=3, mesh_shape=(5, 8, 10))
And then obtain information about it, like its
discretize.tensor_cell.TensorCell.origin
:>>> cell.origin array([0.6, 0. , 0. ])
Or its
discretize.tensor_cell.TensorCell.bounds
:>>> cell.bounds array([0.6 , 0.8 , 0. , 0.125, 0. , 0.1 ])
We can also get its neighboring cells:
>>> neighbours = cell.get_neighbors(mesh) >>> for neighbor in neighbours: ... print(neighbor.center) [0.5 0.0625 0.05 ] [0.9 0.0625 0.05 ] [0.7 0.1875 0.05 ] [0.7 0.0625 0.15 ]
Alternatively, we can iterate over all cells in the mesh with a simple for loop or list comprehension:
>>> cells = [cell for cell in mesh] >>> len(cells) 400