cherab.imas.ggd.UnstructGrid2DExtendedΒΆ

class cherab.imas.ggd.UnstructGrid2DExtended(vertices: ArrayLike, cells: NDArray[integer[Any]] | Sequence[Sequence[SupportsIndex] | NDArray[integer[Any]]], 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: NDArray[integer[Any]] | Sequence[Sequence[SupportsIndex] | NDArray[integer[Any]]]ΒΆ

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 UnstructGrid3D from this instance.

subset_faces(indices[,Β name])

Create a subset UnstructGrid2DExtended from this instance.

vector_interpolator(grid_vectors[,Β ...])

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[float64]SourceΒΆ

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

property cells : NDArray[int32]SourceΒΆ

Mesh cells as (M, 8) array.

property tetrahedra : NDArray[int32]SourceΒΆ

Mesh tetrahedra as (5M, 4) array.

property tetra_to_cell_map : NDArray[int32]SourceΒΆ

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

property cell_to_tetra_map : NDArray[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: Sequence[SupportsIndex] | NDArray[integer[Any]], 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.

Parameters:
indices: Sequence[SupportsIndex] | NDArray[integer[Any]]ΒΆ

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:

UnstructGrid2DExtended – Subset instance.

Raises:

ValueError – If any of the indices of the faces is out of range. If the number of faces at the poloidal plane, the number of poloidal points, or the number of toroidal points is not defined for this grid.

See also

subset

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

subset(indices: Sequence[SupportsIndex] | NDArray[integer[Any]], name: str | None = None) → UnstructGrid3DSourceΒΆ

Create a subset UnstructGrid3D 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: Sequence[SupportsIndex] | NDArray[integer[Any]]ΒΆ

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:

UnstructGrid3D – Subset instance.

interpolator(grid_data: NDArray[floating[Any]] | Sequence[float], fill_value: float = 0, *, interpolator_cache: 'none' | 'memory' | 'disk' = 'memory', interpolator_cache_dir: str | Path | None = None, interpolator_cache_namespace: str = 'ggd') → 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: NDArray[floating[Any]] | Sequence[float]ΒΆ

Array containing data in the grid cells.

fill_value: float = 0ΒΆ

Value returned outside the grid, by default 0.0.

interpolator_cache: 'none' | 'memory' | 'disk' = 'memory'ΒΆ

Cache mode for the interpolator, by default "memory". The cache mode is described in the InterpolatorCacheMode type alias.

interpolator_cache_dir: str | Path | None = NoneΒΆ

Directory used when interpolator_cache="disk", by default None (uses the system cache directory, e.g., ~/.cache/cherab/imas/interpolators).

interpolator_cache_namespace: str = 'ggd'ΒΆ

Namespace prefix to avoid cache-key collisions, by default "ggd".

Returns:

UnstructGridFunction3D – Interpolator instance.

vector_interpolator(grid_vectors: NDArray[float64], fill_vector: Vector3D = Vector3D(0.0, 0.0, 0.0), *, interpolator_cache: 'none' | 'memory' | 'disk' = 'memory', interpolator_cache_dir: str | Path | None = None, interpolator_cache_namespace: str = 'ggd') → 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: NDArray[float64]ΒΆ

(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, by default Vector3D(0, 0, 0).

interpolator_cache: 'none' | 'memory' | 'disk' = 'memory'ΒΆ

Cache mode for the interpolator, by default "memory". The cache mode is described in the InterpolatorCacheMode type alias.

interpolator_cache_dir: str | Path | None = NoneΒΆ

Directory used when interpolator_cache="disk", by default None (uses the system cache directory, e.g., ~/.cache/cherab/imas/interpolators).

interpolator_cache_namespace: str = 'ggd'ΒΆ

Namespace prefix to avoid cache-key collisions, by default "ggd".

Returns:

UnstructGridVectorFunction3D – Interpolator instance.

plot_tetra_mesh(data: NDArray[floating[Any]] | Sequence[float] | None = None, ax: Axes | None = None) → NoneSourceΒΆ

Plot the tetrahedral mesh grid geometry.

Warning

Plotting of tetrahedral mesh is not implemented yet.

Parameters:
data: NDArray[floating[Any]] | Sequence[float] | 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: NDArray[floating[Any]] | Sequence[float] | None = None, ax: Axes | None = None, **grid_styles) → AxesSourceΒΆ

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

Parameters:
data: NDArray[floating[Any]] | Sequence[float] | 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ΒΆ

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

Returns:

Axes – Matplotlib axes with the plotted mesh.

property cell_area : NDArray[float64]SourceΒΆ

Cell areas as (num_cell,) array.

property cell_centre : NDArray[float64]SourceΒΆ

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

property cell_volume : NDArray[float64]SourceΒΆ

Cell volume as (num_cell,) array.

property coordinate_system : strSourceΒΆ

Coordinate system.

property dimension : intSourceΒΆ

Grid dimension.

property mesh_extent : dict[str, float]SourceΒΆ

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: NDArray[floating[Any]] | Sequence[float], ax: Axes | None = None, cmap: str = 'viridis', **kwargs) → AxesSourceΒΆ

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

Parameters:
data: NDArray[floating[Any]] | Sequence[float]ΒΆ

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

**kwargsΒΆ

Additional keyword arguments passed to tripcolor.

Returns:

Axes – Matplotlib axes with the plotted mesh.

Raises:

ValueError – If the data array does not have the same number of faces as the grid. If the number of faces at the poloidal plane or the number of poloidal points is not defined for this grid.