cherab.imas.ggd.UnstructGrid2D¶

class cherab.imas.ggd.UnstructGrid2D(vertices: ArrayLike, cells: list[ArrayLike], name: str = 'Cells', coordinate_system: 'cylindrical' | 'cartesian' = 'cylindrical')Source¶

Bases: GGDGrid

Unstructured 2D grid object.

The grid cells are polygons. Vertices may be shared with neighbouring cells.

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

Parameters:
vertices: ArrayLike¶

Array-like of shape (N, 2) containing coordinates of the polygon vertices.

cells: list[ArrayLike]¶

List of (N,)-shaped arrays containing the vertex indices in clockwise or counterclockwise order for each polygonal cell in the list (the starting vertex must not be included twice).

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 UnstructGridFunction2D interpolator instance for the data defined on this grid.

plot_mesh([data, ax])

Plot the polygonal mesh grid geometry to a matplotlib figure.

plot_triangle_mesh([data, ax])

Plot the triangle mesh grid geometry to a matplotlib figure.

subset(indices[, name])

Create a subset UnstructGrid2D from this instance.

vector_interpolator(grid_vectors[, fill_vector])

Return an UnstructGridVectorFunction2D 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_triangle_map

Array of shape (K, 2) mapping every grid cell index to triangle IDs.

cell_volume

Cell volume as (num_cell,) array.

cells

List of K polygonal cells.

coordinate_system

Coordinate system.

dimension

Grid dimension.

mesh_extent

Extent of the mesh.

name

Grid name.

num_cell

Number of grid cells.

triangle_to_cell_map

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

triangles

Mesh triangles as (M, 3) array.

vertices

Mesh vertex coordinates as (N, 2) array.

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

Mesh vertex coordinates as (N, 2) array.

property cells : tuple[ArrayLike, ...]Source¶

List of K polygonal cells.

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

Mesh triangles as (M, 3) array.

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

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

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

Array of shape (K, 2) mapping every grid cell index to triangle IDs.

The first column is the index of the first triangle forming the cell. The second column is the number of triangles forming the cell.

>>> itri, ntri = mesh.cell_to_triangle_map[icell]
>>> tri_cell = mesh.triangles[itri : itri + ntri]
subset(indices: ArrayLike, name: str | None = None) UnstructGrid2DSource¶

Create a subset UnstructGrid2D from this instance.

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:

UnstructGrid2D

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

Return an UnstructGridFunction2D 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 is 0.

Returns:

Interpolator instance.

Return type:

UnstructGridFunction2D

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

Return an UnstructGridVectorFunction2D 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, K) 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:

UnstructGridVectorFunction2D

plot_triangle_mesh(data: ArrayLike | None = None, ax: Axes | None = None) AxesSource¶

Plot the triangle mesh grid geometry to a matplotlib figure.

Parameters:
data: ArrayLike | None = None¶

Data array defined on the polygonal mesh.

ax: Axes | None = None¶

Matplotlib axes to plot on. If None, a new figure and axes are created.

Returns:

The 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_mesh(data: ArrayLike | None = None, ax: Axes | None = None, **grid_styles: str | float) AxesSource¶

Plot the polygonal mesh grid geometry to a matplotlib figure.

Parameters:
data: ArrayLike | None = None¶

Data array defined on the polygonal mesh.

ax: Axes | None = None¶

Matplotlib axes to plot on. If None, a new figure and axes are created.

Returns:

The matplotlib axes with the plotted mesh.

Return type:

Axes