Mesh Operators
The tokamesh.operators module provides functions for constructing
linear operators (i.e. matrices) which act on a vector of field values
at each mesh vertex to compute a new vector.
- tokamesh.operators.edge_difference_matrix(R: ~numpy.ndarray, z: ~numpy.ndarray, triangles: ~numpy.ndarray, normalised=False, sparse_array_type=<class 'scipy.sparse._csr.csr_array'>) sparray
Generates a sparse matrix which, when operating on a vector of field values at each vertex, produces a vector of the differences in those field values along each edge in the mesh.
- 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)whereNis the total number of triangles.normalised (bool) – If set as
True, the difference in the value across each edge is normalised by the length of the edge, yielding an estimate of the gradient along that edge.sparse_array_type – A sparse array type from
scipy.sparsewhich will be used as the returned type of the matrix operator.
- Returns
The edge-difference matrix operator as a sparse array.
- tokamesh.operators.umbrella_matrix(R: ~numpy.ndarray, z: ~numpy.ndarray, triangles: ~numpy.ndarray, ignore_boundary=True, inverse_distance_weighting=True, normalised=False, sparse_array_type=<class 'scipy.sparse._csr.csr_array'>) sparray
Returns a sparse ‘umbrella’ matrix operator, which finds the difference between the value of every internal vertex and the average value of the other vertices to which it is connected.
- 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)whereNis the total number of triangles.ignore_boundary (bool) – If set as
True, the operator will ignore vertices on any boundary of the mesh, instead returning a value of zero for those vertices.inverse_distance_weighting (bool) – If set as
True, the sum over the neighbouring vertices is weighted by their inverse-distance to the central vertex. This tends to produce better results for irregular meshes with significant variation of edge-lengths.normalised (bool) – If set as
Truethe value produced by the operator for each vertex is normalised by the square of the mean distance between the neighbouring vertices and the central vertex.sparse_array_type – A sparse array type from
scipy.sparsewhich will be used as the returned type of the matrix operator.
- Returns
The umbrella matrix operator as a sparse array.
- tokamesh.operators.parallel_derivative(R: ~numpy.ndarray, z: ~numpy.ndarray, index_grid: ~numpy.ndarray, order=2, sparse_array_type=<class 'scipy.sparse._csr.csr_array'>) sparray
Constructs a sparse matrix operator which estimates the derivative (with respect to poloidal distance) of a given set of field values at each vertex in direction parallel to the magnetic field.
- 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.
index_grid – A 2D numpy array specifying the indices of triangular mesh vertices corresponding to each cell of the rectangular field-aligned grid.
order – The order of the derivative to be estimated. Must be either 1 or 2.
sparse_array_type – A sparse array type from
scipy.sparsewhich will be used as the returned type of the matrix operator.
- Returns
The parallel derivative matrix operator as a sparse array.
- tokamesh.operators.perpendicular_derivative(R: ~numpy.ndarray, z: ~numpy.ndarray, index_grid: ~numpy.ndarray, order=2, sparse_array_type=<class 'scipy.sparse._csr.csr_array'>) sparray
Constructs a sparse matrix operator which estimates the derivative (with respect to poloidal distance) of a given set of field values at each vertex in direction perpendicular to the magnetic field.
- 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.
index_grid – A 2D numpy array specifying the indices of triangular mesh vertices corresponding to each cell of the rectangular field-aligned grid.
order – The order of the derivative to be estimated. Must be either 1 or 2.
sparse_array_type – A sparse array type from
scipy.sparsewhich will be used as the returned type of the matrix operator.
- Returns
The perpendicular derivative matrix operator as a sparse array.