cherab.imas.ggd.UnstructGrid2DExtended¶

class cherab.imas.ggd.UnstructGrid2DExtended(vertices: ArrayLike, cells: ArrayLike, num_faces: int, num_poloidal: int, num_toroidal: int, name: str = 'Cells', coordinate_system: 'cylindrical' | 'cartesian' = 'cylindrical')Source¶

Bases: GGDGrid

Unstructured 2D grid with toroidal extension.

The grid cells are voxels (cubes). Vertices may be shared with neighbouring cells.

To use Raysect’s KDtree accelerator, each cell is tetrahedralized.

Parameters:
vertices: ArrayLike¶

Array-like of shape (N, 3) containing coordinates of the cell vertices in the (X, Y, Z) space.

cells: ArrayLike¶

Array-like of shape (M, 8) containing the vertex indices in clockwise or counterclockwise order for each cubic cell in the list (the starting vertex must not be included twice).

num_faces: int¶

Number of faces at the poloidal plane.

num_poloidal: int¶

Number of poloidal points.

num_toroidal: int¶

Number of toroidal points.

name: str = 'Cells'¶

Name of the grid, by default "Cells".

coordinate_system: 'cylindrical' | 'cartesian' = 'cylindrical'¶

Coordinate system of the grid, by default "cylindrical".

Methods

interpolator(grid_data[, fill_value])

Return an UnstructGridFunction3D interpolator instance for the data defined on this grid.

plot_mesh([data, ax])

Plot the polygonal mesh grid geometry at the first poloidal plane to a matplotlib figure.

plot_tetra_mesh([data, ax])

Plot the tetrahedral mesh grid geometry.

plot_tri_mesh(data[, ax, cmap])

Plot the data defined on the triangular mesh at the poloidal plane to a matplotlib figure.

subset(indices[, name])

Create a subset UnstructGrid2DExtended from this instance.

subset_faces(indices[, name])

Create a subset UnstructGrid2DExtended from this instance.

vector_interpolator(grid_vectors[, fill_vector])

Return an UnstructGridVectorFunction3D interpolator instance for the vector data defined on this grid.

Attributes

cell_area

Cell areas as (num_cell,) array.

cell_centre

Coordinate of cell centres as (num_cell, dimension) array.

cell_to_tetra_map

Array of shape (M, 2) mapping every grid cell index to tetrahedral IDs.

cell_volume

Cell volume as (num_cell,) array.

cells

Mesh cells as (M, 8) array.

coordinate_system

Coordinate system.

dimension

Grid dimension.

mesh_extent

Extent of the mesh.

name

Grid name.

num_cell

Number of grid cells.

num_faces

Number of faces at the poloidal plane.

num_poloidal

Number of poloidal grid points.

num_toroidal

Number of toroidal grid points.

tetra_to_cell_map

Array of shape (5M,) mapping every tetrahedral index to a grid cell ID.

tetrahedra

Mesh tetrahedra as (5M, 4) array.

vertices

Mesh vertex coordinates as (N, 3) array in the (X, Y, Z) space.

property num_poloidal : intSource¶

Number of poloidal grid points.

property num_toroidal : intSource¶

Number of toroidal grid points.

property num_faces : intSource¶

Number of faces at the poloidal plane.

property vertices : ndarray[tuple[Any, ...], dtype[float64]]Source¶

Mesh vertex coordinates as (N, 3) array in the (X, Y, Z) space.

property cells : ndarray[tuple[Any, ...], dtype[int32]]Source¶

Mesh cells as (M, 8) array.

property tetrahedra : ndarray[tuple[Any, ...], dtype[int32]]Source¶

Mesh tetrahedra as (5M, 4) array.

property tetra_to_cell_map : ndarray[tuple[Any, ...], dtype[int32]]Source¶

Array of shape (5M,) mapping every tetrahedral index to a grid cell ID.

property cell_to_tetra_map : ndarray[tuple[Any, ...], dtype[int32]]Source¶

Array of shape (M, 2) mapping every grid cell index to tetrahedral IDs.

The first column is the index of the first tetrahedron forming the cell. The second column is the number of tetrahedra forming the cell.

>>> itet, ntet = mesh.cell_to_tetra_map[icell]
>>> tet_cell = mesh.tetrahedra[itet : itet + ntet]
subset_faces(indices: ArrayLike, name: str | None = None) UnstructGrid2DExtendedSource¶

Create a subset UnstructGrid2DExtended from this instance.

The subset is defined by the indices of the faces at the poloidal plane. Thus, the subset mesh is periodic in the toroidal direction.

See also

subset

For a method that creates a subset from the original grid cells.

Parameters:
indices: ArrayLike¶

Indices of the faces of the original grid in the subset.

name: str | None = None¶

Name of the grid subset. Default is instance.name + " subset".

Returns:

Subset instance.

Return type:

UnstructGrid2DExtended

Raises:

ValueError – If any of the indices of the faces is out of range.

subset(indices: ArrayLike, name: str | None = None) UnstructGrid2DExtendedSource¶

Create a subset UnstructGrid2DExtended from this instance.

Warning

The subset loses the range of cylindrical coordinates because the extracted vertex data is not necessarily periodic in the toroidal direction.

Parameters:
indices: ArrayLike¶

Indices of the cells of the original grid in the subset.

name: str | None = None¶

Name of the grid subset. Default is instance.name + " subset".

Returns:

Subset instance.

Return type:

UnstructGrid2DExtended

interpolator(grid_data: ArrayLike, fill_value: float = 0) UnstructGridFunction3DSource¶

Return an UnstructGridFunction3D interpolator instance for the data defined on this grid.

On the second and subsequent calls, the interpolator is created as an instance of the previously created interpolator sharing the same KDtree structure.

Parameters:
grid_data: ArrayLike¶

Array containing data in the grid cells.

fill_value: float = 0¶

Value returned outside the grid, by default 0.

Returns:

Interpolator instance.

Return type:

UnstructGridFunction3D

vector_interpolator(grid_vectors: ArrayLike, fill_vector: Vector3D = Vector3D(0.0, 0.0, 0.0)) UnstructGridVectorFunction3DSource¶

Return an UnstructGridVectorFunction3D interpolator instance for the vector data defined on this grid.

On the second and subsequent calls, the interpolator is created as an instance of the previously created interpolator sharing the same KDtree structure.

Parameters:
grid_vectors: ArrayLike¶

(3, L) Array containing 3D vectors in the grid cells.

fill_vector: Vector3D = Vector3D(0.0, 0.0, 0.0)¶

3D vector returned outside the grid.

Returns:

Interpolator instance.

Return type:

UnstructGridVectorFunction3D

plot_tetra_mesh(data: ArrayLike | None = None, ax: Axes | None = None) NoneSource¶

Plot the tetrahedral mesh grid geometry.

Warning

Plotting of tetrahedral mesh is not implemented yet.

Parameters:
data: ArrayLike | None = None¶

Data array defined on the tetrahedral mesh.

ax: Axes | None = None¶

Matplotlib axes to plot the mesh. If None, a new figure is created.

Raises:

NotImplementedError – Plotting of tetrahedral mesh is not implemented yet.

plot_mesh(data: ArrayLike | None = None, ax: Axes | None = None, **grid_styles: str | float) AxesSource¶

Plot the polygonal mesh grid geometry at the first poloidal plane to a matplotlib figure.

Parameters:
data: ArrayLike | None = None¶

Data array defined on the polygonal mesh at the poloidal plane.

ax: Axes | None = None¶

Matplotlib axes to plot the mesh. If None, a new figure is created.

**grid_styles: str | float¶

Styles for the grid lines and faces, by default {"facecolor": "none", "edgecolor": "b", "linewidth": 0.25}.

Returns:

Matplotlib axes with the plotted mesh.

Return type:

Axes

property cell_area : ndarray[tuple[Any, ...], dtype[float64]] | NoneSource¶

Cell areas as (num_cell,) array.

property cell_centre : ndarray[tuple[Any, ...], dtype[float64]] | NoneSource¶

Coordinate of cell centres as (num_cell, dimension) array.

property cell_volume : ndarray[tuple[Any, ...], dtype[float64]] | NoneSource¶

Cell volume as (num_cell,) array.

property coordinate_system : strSource¶

Coordinate system.

property dimension : intSource¶

Grid dimension.

property mesh_extent : dict[str, float] | NoneSource¶

Extent of the mesh.

A dictionary with xmin, xmax, ymin and ymax, … keys.

property name : strSource¶

Grid name.

property num_cell : intSource¶

Number of grid cells.

plot_tri_mesh(data: ArrayLike, ax: Axes | None = None, cmap: str = 'viridis') AxesSource¶

Plot the data defined on the triangular mesh at the poloidal plane to a matplotlib figure.

Parameters:
data: ArrayLike¶

Data array defined on the triangular mesh at the poloidal plane.

ax: Axes | None = None¶

Matplotlib axes to plot the mesh. If None, a new figure is created.

cmap: str = 'viridis'¶

Colormap to use for the data, by default ‘viridis’.

Returns:

Matplotlib axes with the plotted mesh.

Return type:

Axes

Raises:

ValueError – If the data array does not have the same number of faces as the grid.