cherab.inversion.tools.diag_dictΒΆ

cherab.inversion.tools.diag_dict(grid_shape: tuple[int, int]) dict[str, dia_array]SourceΒΆ

Return a dictionary of diagonal matrices.

The key of the dictionary corresponds to the position of grid points. b, c, and f mean backward, center, and forward along the given axis respectively. e.g. bf means the backward and forward grid points along the axis 0 and 1 respectively.

The following figure shows how the each grid point is connected.

bb ─── bc ─── bf    --> axis 1
β”‚       β”‚       β”‚
β”‚       β”‚       β”‚
cb ─── cc ─── cf
β”‚       β”‚       β”‚
β”‚       β”‚       β”‚
fb ─── fc ─── ff

|
V
axis 0

A grid point is regarded to be flattened along the axis 1, so if the index of cc is i, then the index of bc is i - N1, fc is i + N1, etc. where N1 is the number of grid points along the axis 1. If the index is out of the grid, then the corresponding element is set to zero (dirichlet boundary condition).

Parameters:
grid_shape: tuple[int, int]ΒΆ

Shape of the grid (N0, N1), where N0 and N1 are the number of grid points along the axis 0 and 1 respectively.

Returns:

dict[str, scipy.sparse.dia_array] – Dictionary of diagonal matrices, the keys of which are "bb", "bc", "bf", "cb", "cc", "cf", "fb", "fc", and "ff".

Examples

>>> diag = diag_dict((3, 3))
>>> diag["cc"].toarray()
array([[1., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 1., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 1., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 1., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 1., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 1., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 1., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 1., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 1.]])
>>> diag["bf"].toarray()
array([[0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 1., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 1., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 1., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 1., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 0., 0.]])