Skip to content

Conversion

Both converters take a mesh and return a new one, leaving the original untouched.

torchfem.mesh.mesh_to_lattice(nodes, elements, variant='simple')

Converts a planar or solid mesh into a lattice of two-node bar elements.

The element type is inferred from the mesh. Bars are placed along all element edges, duplicates from shared edges removed. The braced variants add diagonals to every quadrilateral, which is the element itself for a quadrilateral mesh and each element face for a hexahedral mesh. Triangles and tetrahedra have no quadrilaterals and do not support them. No variant changes the node set.

Parameters:

  • nodes (Tensor) –

    Node coordinates as a tensor of shape (num_nodes, dim).

  • elements (Tensor) –

    Connectivity of a linear mesh.

  • variant (Literal['simple', 'up', 'down', 'cross'], default: 'simple' ) –

    Bracing of the quadrilaterals. Options are 'simple' (no diagonals), 'up' and 'down' (one diagonal each) and 'cross' (both).

Returns:

  • Tensor

    A tuple of (nodes, cells):

  • Tensor
    • nodes: Node coordinates, passed through unchanged.
  • tuple[Tensor, Tensor]
    • cells: Bar element connectivity as a tensor of shape (num_bars, 2).

On a quadrilateral mesh, the braced variants add the diagonals of every element:

Bracing variants on a quadrilateral mesh Bracing variants on a quadrilateral mesh

On a hexahedral mesh, they add the diagonals of every element face instead. Neighbouring elements pick matching diagonals, so a face shared by two of them is braced once:

Bracing variants on two hexahedra Bracing variants on two hexahedra

torchfem.elements.linear_to_quadratic(nodes, elements)

Convert supported linear meshes to quadratic meshes.

Supported topologies are:

  • 2-node bars to 3-node bars
  • 3-node triangles to 6-node triangles
  • 4-node quadrilaterals to 8-node quadrilaterals
  • 4-node tetrahedra to 10-node tetrahedra
  • 8-node hexahedra to 20-node hexahedra

New nodes are created at edge midpoints and appended to nodes.

Parameters:

  • nodes (Tensor) –

    Nodal coordinates. Shape: (n_nodes, dim).

  • elements (Tensor) –

    Connectivity of linear elements. Shape: (n_elem, n_nodes_per_elem).

Returns:

  • new_nodes ( Tensor ) –

    Extended nodal coordinates with edge midpoints. Shape: (n_nodes + n_unique_edges, dim).

  • new_elements ( Tensor ) –

    Quadratic element connectivity. Shape: (n_elem, n_quadratic_nodes_per_elem).

The corner nodes are kept and the mid-side nodes appended:

A linear mesh and its quadratic counterpart A linear mesh and its quadratic counterpart