Mesh Construction

The tokamesh.construction module provides tools for constructing and refining triangular meshes for use in tomography problems.

Example code for mesh construction & refinement can be found in the mesh construction jupyter notebook demo.

Mesh construction is handled by the mesh_generator function:

tokamesh.construction.mesh_generator(R_boundary: ndarray, z_boundary: ndarray, resolution: float, edge_resolution: float = None, edge_padding: float = 0.75, edge_max_area: float = 1.1, rotation: float = None, central_mesh: tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] = None) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

Generate a triangular mesh which fills the space inside a given boundary using a 2-stage process. First, a mesh of equilateral triangles is created which fills the space up to a chosen minimum distance from the boundary. An irregular mesh is then generated which fills the space between the central equilateral mesh and the boundary. The two meshes are then merged, and the resulting mesh is returned.

Parameters
  • R_boundary – The major-radius values of the boundary as a 1D numpy array.

  • z_boundary – The z-height values of the boundary as a 1D numpy array.

  • resolution – The side-length of triangles in the central equilateral mesh.

  • edge_resolution – Sets the target area of triangles in the irregular edge mesh, which fills the space between the central equilateral mesh and the boundary. The Triangle C-code, which is used to generate the irregular mesh, will attempt to construct triangles with areas equal to that of an equilateral triangle with side length edge_resolution. If not specified, the value passed as the resolution argument is used instead.

  • edge_padding – A multiplicative factor which defines the minimum allowed distance between a vertex in the central equilateral mesh and the boundary such that min_distance = edge_padding * resolution. No vertices in the central equilateral mesh will be closer to the boundary than min_distance.

  • edge_max_area – A multiplicative factor which sets the maximum allowed area of triangles in the irregular edge mesh, such that no triangle will have an area larger than edge_max_area times the target area set by the edge_resolution argument.

  • rotation – Angle (in radians) by which the orientations of triangles in the central equilateral mesh are rotated, relative to their default orientation.

  • central_mesh – Allows the central mesh to be specified directly rather than being generated automatically. The central mesh data is specified as a tuple of numpy arrays specifying the major radius of the vertices, the z-height of the vertices and the indices of the triangles respectively.

Returns

A tuple containing R_vert, z_vert and triangles. R_vert is the major-radius of the vertices as a 1D array. z_vert the is z-height of the vertices as a 1D array. triangles is a 2D array of integers of shape (N,3) specifying the indices of the vertices which form each triangle in the mesh, where N is the total number of triangles.