tidy3d.TetrahedralGridDataset#

class TetrahedralGridDataset[source]#

Bases: UnstructuredGridDataset

Dataset for storing tetrahedral grid data. Data values are associated with the nodes of the grid.

Parameters:
  • attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields, attrs are mutable. For example, the following is allowed for setting an attr obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a TypeError if attrs contain objects that can not be serialized. One can check if attrs are serializable by calling obj.json().

  • points (PointDataArray) – Coordinates of points composing the unstructured grid.

  • values (Union[IndexedDataArray, IndexedVoltageDataArray]) – Values stored at the grid points.

  • cells (CellDataArray) – Cells composing the unstructured grid specified as connections between grid points.

Note

To use full functionality of unstructured datasets one must install vtk package (pip install tidy3d[vtk] or pip install vtk). Otherwise the functionality of unstructured datasets is limited to creation, writing to/loading from a file, and arithmetic manipulations.

Example

>>> tet_grid_points = PointDataArray(
...     [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]],
...     coords=dict(index=np.arange(4), axis=np.arange(3)),
... )
>>>
>>> tet_grid_cells = CellDataArray(
...     [[0, 1, 2, 3]],
...     coords=dict(cell_index=np.arange(1), vertex_index=np.arange(4)),
... )
>>>
>>> tet_grid_values = IndexedDataArray(
...     [1.0, 2.0, 3.0, 4.0], coords=dict(index=np.arange(4)),
... )
>>>
>>> tet_grid = TetrahedralGridDataset(
...     points=tet_grid_points,
...     cells=tet_grid_cells,
...     values=tet_grid_values,
... )

Attributes

Methods

get_cell_volumes()

Get the volumes associated to each cell in the grid

line_slice(axis, pos)

Slice data with a line and return the resulting xarray.DataArray.

plane_slice(axis, pos)

Slice data with a plane and return the resulting TriangularGridDataset.

sel([x, y, z, method])

Extract/interpolate data along one or more spatial or non-spatial directions.

Inherited Common Usage

plane_slice(axis, pos)[source]#

Slice data with a plane and return the resulting TriangularGridDataset.

Parameters:
  • axis (Axis) – The normal direction of the slicing plane.

  • pos (float) – Position of the slicing plane along its normal direction.

Returns:

The resulting slice.

Return type:

TriangularGridDataset

line_slice(axis, pos)[source]#

Slice data with a line and return the resulting xarray.DataArray.

Parameters:
  • axis (Axis) – The axis of the slicing line.

  • pos (Tuple[float, float, float]) – Position of the slicing line.

Returns:

The resulting slice.

Return type:

xarray.DataArray

sel(x=None, y=None, z=None, method=None, **sel_kwargs)[source]#

Extract/interpolate data along one or more spatial or non-spatial directions. Must provide at least one argument among β€˜x’, β€˜y’, β€˜z’ or non-spatial dimensions through additional arguments. Along spatial dimensions a suitable slicing of grid is applied (plane slice, line slice, or interpolation). Selection along non-spatial dimensions is forwarded to .sel() xarray function. Parameter β€˜method’ applies only to non-spatial dimensions.

Parameters:
  • x (Union[float, ArrayLike] = None) – x-coordinate of the slice.

  • y (Union[float, ArrayLike] = None) – y-coordinate of the slice.

  • z (Union[float, ArrayLike] = None) – z-coordinate of the slice.

  • method (Literal[None, "nearest", "pad", "ffill", "backfill", "bfill"] = None) – Method to use in xarray sel() function.

  • **sel_kwargs (dict) – Keyword arguments to pass to the xarray sel() function.

Returns:

Extracted data.

Return type:

Union[TriangularGridDataset, xarray.DataArray]

get_cell_volumes()[source]#

Get the volumes associated to each cell in the grid

__hash__()#

Hash method.