cherab.phix.tools.laplacian_matrix#

cherab.phix.tools.laplacian_matrix(voxel_map, dir=4)#

Generate Laplacian sparse matrix.

Parameters:
  • voxel_map (NDArray[int32]) – (N, M) voxel map matrix (negative value must be input into masked voxels) If the additional dimension size of the matrix is 1, then it is squeezed to a 2-D matrix.

  • dir ({4, 8}) – the number of laplacian kernel’s neighbor, by default 4.

Returns:

(N, N) laplacian Compressed Sparse Row matrix (if N > M)

Return type:

csr_matrix

Examples

from raysect.core import World
from cherab.phix.plasma import import_equilibrium
from cherab.phix.tools import laplacian_matrix, import_phix_rtm

world = World()
eq = import_equilibrium()
rtm = import_phix_rtm(world, equilibrium=eq)

laplacian = laplacian_matrix(rtm.voxel_map, dir=8)
laplacian.toarray()
array([[-8,  1,  0, ...,  0,  0,  0],
       [ 1, -8,  1, ...,  0,  0,  0],
       [ 0,  1, -8, ...,  0,  0,  0],
       ...,
       [ 0,  0,  0, ..., -8,  1,  0],
       [ 0,  0,  0, ...,  1, -8,  1],
       [ 0,  0,  0, ...,  0,  1, -8]], dtype=int32)