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, andfmean backward, center, and forward along the given axis respectively. e.g.bfmeans 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 0A grid point is regarded to be flattened along the axis 1, so if the index of
ccisi, then the index ofbcisi - N1,fcisi + N1, etc. whereN1is 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:
- 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.]])