Calculating geometry matrices

Geometry matrix calculation is handled by the calculate_geometry_matrix class from the tokamesh.geometry module.

Example code for geometry matrix calculation can be found in the geometry matrix jupyter notebook demo.

tokamesh.geometry.calculate_geometry_matrix(R: ndarray, z: ndarray, triangles: ndarray, ray_origins: ndarray, ray_ends: ndarray, n_processes: int) GeometryMatrix

Calculate a geometry matrix over a given triangular mesh using barycentric linear interpolation.

Parameters
  • R – The major radius of each mesh vertex as a 1D numpy array.

  • z – The z-height of each mesh vertex as a 1D numpy array.

  • triangles – A 2D numpy array of integers specifying the indices of the vertices which form each of the triangles in the mesh. The array must have shape (N,3) where N is the total number of triangles.

  • ray_origins – The (x,y,z) position vectors of the origin of each ray (i.e. line-of-sight) as a 2D numpy array. The array must have shape (M,3) where M is the total number of rays.

  • ray_ends – The (x,y,z) position vectors of the end-points of each ray (i.e. line-of-sight) as a 2D numpy array. The array must have shape (M,3) where M is the total number of rays.

  • n_processes – Number of processes over which the computation is distributed.

Returns

A GeometryMatrix object containing the geometry matrix data - see the documentation for GeometryMatrix for details.

class tokamesh.geometry.GeometryMatrix(entry_values: ndarray, row_indices: ndarray, col_indices: ndarray, matrix_shape: ndarray, R_vertices: ndarray, z_vertices: ndarray, triangle_vertices: ndarray)

A class for packaging and manipulating geometry matrix data.

Variables
  • entry_values – The values of the non-zero matrix elements as a numpy ndarray.

  • row_indices – The row indices of the non-zero matrix elements as a numpy ndarray.

  • col_indices – The column indices of the non-zero matrix elements as a numpy ndarray.

  • matrix_shape – The shape of the geometry matrix as a numpy ndarray.

  • R_vertices – The major-radius of the triangular mesh vertices as a numpy ndarray.

  • z_vertices – The z-height of the triangular mesh vertices as a numpy ndarray.

  • triangle_vertices – A 2D numpy ndarray of integers specifying the indices of the vertices which form each of the triangles in the mesh. The array has shape (N,3) where N is the total number of triangles.

build_sparse_array(sparse_array_type=<class 'scipy.sparse._csc.csc_array'>)
Parameters

sparse_array_type – A sparse array type from scipy.sparse.

Returns

The geometry matrix as an instance of the given sparse array type.

classmethod load(filename: str)

Load and return a saved GeometryMatrix instance from file.

Parameters

filename – The filename of the saved geometry matrix data.

Returns

The loaded data as a GeometryMatrix instance.

save(filename: str)

Save the geometry matrix data in the numpy .npz format.

Parameters

filename – The filename to which the geometry matrix data is saved.