Skip to content

Mesh¤

tatva.mesh.Mesh dataclass ¤

Mesh(coords: Array, elements: Array)

A class used to represent a Mesh for finite element method (FEM) simulations.

Attributes:

  • nodes

    The coordinates of the mesh nodes.

  • elements (Array) –

    The connectivity of the mesh elements.

Methods:

  • set_coords

    Return a new Mesh with the same connectivity but updated node coordinates.

  • hmin

    Compute the minimum element diameter in the mesh.

  • hmax

    Compute the maximum element diameter in the mesh.

  • unit_square

    Generate a unit square mesh with n_x and n_y nodes in the x and y directions.

  • rectangle

    Generate a rectangular mesh with specified x and y ranges and number of nodes.

coords instance-attribute ¤

coords: Array

Coordinates of the mesh nodes, shape (n_nodes, n_dim)

elements instance-attribute ¤

elements: Array

Connectivity of the mesh elements, shape (n_elements, nodes_per_element)

set_coords ¤

set_coords(new_coords: Array) -> Mesh

Return a new Mesh with the same connectivity but updated node coordinates.

Parameters:

  • new_coords ¤
    (Array) –

    An array of shape (n_nodes, n_dim) containing the new coordinates for the mesh nodes.

hmin ¤

hmin() -> Array

Compute the minimum element diameter in the mesh.

hmax ¤

hmax() -> Array

Compute the maximum element diameter in the mesh.

unit_square classmethod ¤

unit_square(
    n_x: int,
    n_y: int,
    *,
    type: ElementType
    | Literal["triangle", "quad"] = ElementType.TRIANGLE,
    dim: Literal[2, 3] = 2,
) -> Mesh

Generate a unit square mesh with n_x and n_y nodes in the x and y directions.

rectangle classmethod ¤

rectangle(
    x: tuple[float, float],
    y: tuple[float, float],
    n_x: int,
    n_y: int,
    *,
    type: ElementType
    | Literal["triangle", "quad"] = ElementType.TRIANGLE,
    dim: Literal[2, 3] = 2,
) -> Mesh

Generate a rectangular mesh with specified x and y ranges and number of nodes.

tatva.mesh.ElementType ¤

Enumeration of different finite element types.

Attributes:

TRIANGLE class-attribute instance-attribute ¤

TRIANGLE = 'triangle'

QUAD class-attribute instance-attribute ¤

QUAD = 'quad'

TETRAHEDRON class-attribute instance-attribute ¤

TETRAHEDRON = 'tetrahedron'

HEXAHEDRON class-attribute instance-attribute ¤

HEXAHEDRON = 'hexahedron'

tatva.mesh.PartitionInfo ¤

Information about the partitioning of the mesh across MPI ranks.

Attributes:

  • nodes_local_to_global (NDArray[int32]) –

    Local to global node mapping array, where node_l2g[i] gives the global index of the

  • n_owned_nodes (int) –

    Number of nodes owned by the local process. Since the local mesh sorts owned nodes

nodes_local_to_global instance-attribute ¤

nodes_local_to_global: NDArray[int32]

Local to global node mapping array, where node_l2g[i] gives the global index of the local node i.

n_owned_nodes instance-attribute ¤

n_owned_nodes: int

Number of nodes owned by the local process. Since the local mesh sorts owned nodes before ghosts, nodes 0:n_owned_nodes are owned.

tatva.mesh.extract_local_mesh ¤

extract_local_mesh(
    mesh_global: Mesh, element_partition: NDArray, part: int
) -> tuple[Mesh, PartitionInfo]

Return the local mesh, and node-ownership mask.

Nodes are ordered such that OWNED nodes come first, followed by GHOST nodes. This "Owned-First" ordering aligns with PETSc's VecGhost convention and allows for zero-copy local access.

Parameters:

  • mesh_global ¤

    (Mesh) –

    the global mesh

  • element_partition ¤

    (NDArray) –

    int array of shape (n_elements,) mapping each element to its owning partition

  • part ¤

    (int) –

    this partition index. Usually, you would pass the MPI rank here.

Returns:

  • Mesh

    A tuple of (local_mesh, partition_info) where: local_mesh is a Mesh object

  • PartitionInfo

    containing only the elements and nodes relevant to this partition; partition_info

  • tuple[Mesh, PartitionInfo]

    contains metadata about node ownership and global indexing.

tatva.mesh.find_containing_polygons ¤

find_containing_polygons(
    points: Array, polygons: Array
) -> Array

Finds the index of the containing polygon for each point.

This function uses a vectorized Ray Casting algorithm with AABB acceleration and is JIT-compiled for maximum performance. It assumes polygons are non-overlapping.

Parameters:

  • points ¤

    (Array) –

    An array of points to test, shape (num_points, 2).

  • polygons ¤

    (Array) –

    A 3D array of polygons, where each polygon is a list of vertices. Shape (num_polygons, num_vertices, 2).

Returns:

  • Array ( Array ) –

    An array of shape (num_points,) where each element is the index of the polygon containing the corresponding point. Returns -1 if a point is not in any polygon.