Skip to content

Generators

Each generator takes the number of grid points per axis followed by the extent of the domain, and places the nodes on a regular grid over that domain. The figures below pair the default unit domain with one of explicit lengths, drawn at the same scale.

torchfem.mesh.rect_quad(Nx, Ny, Lx=1.0, Ly=1.0)

Generates a structured quadrilateral mesh on a rectangle.

Parameters:

  • Nx (int) –

    Number of grid points along the x-axis.

  • Ny (int) –

    Number of grid points along the y-axis.

  • Lx (float, default: 1.0 ) –

    Total length of the rectangle along the x-axis (default 1.0).

  • Ly (float, default: 1.0 ) –

    Total length of the rectangle along the y-axis (default 1.0).

Returns:

  • Tensor

    A tuple of (nodes, cells):

  • Tensor
    • nodes: Node coordinates as a tensor of shape (num_nodes, 2).
  • tuple[Tensor, Tensor]
    • cells: Quadrilateral element connectivity as a tensor of shape (num_quads, 4).

A quadrilateral mesh on a rectangle A quadrilateral mesh on a rectangle

torchfem.mesh.rect_tri(Nx, Ny, Lx=1.0, Ly=1.0, variant='zigzag')

Generates a structured triangular mesh on a rectangle.

Parameters:

  • Nx (int) –

    Number of grid points along the x-axis.

  • Ny (int) –

    Number of grid points along the y-axis.

  • Lx (float, default: 1.0 ) –

    Total length of the rectangle along the x-axis (default 1.0).

  • Ly (float, default: 1.0 ) –

    Total length of the rectangle along the y-axis (default 1.0).

  • variant (Literal['up', 'down', 'zigzag', 'center'], default: 'zigzag' ) –

    Triangulation. Options are 'up', 'down', 'zigzag', and 'center'.

Returns:

  • Tensor

    A tuple of (nodes, cells):

  • Tensor
    • nodes: Node coordinates as a tensor of shape (num_nodes, 2).
  • tuple[Tensor, Tensor]
    • cells: Triangle element connectivity as a tensor of shape (num_triangles, 3).

Triangulation variants of rect_tri Triangulation variants of rect_tri

torchfem.mesh.cube_hexa(Nx, Ny, Nz, Lx=1.0, Ly=1.0, Lz=1.0)

Generates a structured hexahedral mesh on a cube.

Parameters:

  • Nx (int) –

    Number of grid points along the x-axis.

  • Ny (int) –

    Number of grid points along the y-axis.

  • Nz (int) –

    Number of grid points along the z-axis.

  • Lx (float, default: 1.0 ) –

    Total length of the cube along the x-axis (default 1.0).

  • Ly (float, default: 1.0 ) –

    Total length of the cube along the y-axis (default 1.0).

  • Lz (float, default: 1.0 ) –

    Total length of the cube along the z-axis (default 1.0).

Returns:

  • Tensor

    A tuple of (nodes, cells):

  • Tensor
    • nodes: Node coordinates as a tensor of shape (num_nodes, 3).
  • tuple[Tensor, Tensor]
    • cells: Hexahedral element connectivity as a tensor of shape (num_hexes, 8).

A hexahedral mesh on a cube A hexahedral mesh on a cube

torchfem.mesh.cube_tetra(Nx, Ny, Nz, Lx=1.0, Ly=1.0, Lz=1.0)

Generates a structured tetrahedral mesh on a cube via splitting hexahedra into five tetrahedra each. The splitting alternates between two different patterns in a checkerboard fashion to improve mesh quality.

Parameters:

  • Nx (int) –

    Number of grid points along the x-axis.

  • Ny (int) –

    Number of grid points along the y-axis.

  • Nz (int) –

    Number of grid points along the z-axis.

  • Lx (float, default: 1.0 ) –

    Total length of the cube along the x-axis (default 1.0).

  • Ly (float, default: 1.0 ) –

    Total length of the cube along the y-axis (default 1.0).

  • Lz (float, default: 1.0 ) –

    Total length of the cube along the z-axis (default 1.0).

Returns:

  • Tensor

    A tuple of (nodes, cells):

  • Tensor
    • nodes: Node coordinates as a tensor of shape (num_nodes, 3).
  • tuple[Tensor, Tensor]
    • cells: Tetrahedral element connectivity as a tensor of shape (num_tetras, 4).

Two neighbouring hexahedra, showing how the split alternates between them:

A tetrahedral mesh on a cube A tetrahedral mesh on a cube