hybridmesh.HybridMesh#

class hybridmesh.HybridMesh(coords=None, elems=None, eltypes=None)#

Bases: Geometry

A HybridMesh is a discrete geometric model with a single set of coordinates and multiple element connectivity blocks, each potentially of a different type.

It consists of:

  • nodes: points in 3D space, stored in a single Coords array of shape (n_coords, 3), where n_coords is the number of points.

  • elements: a list of Elems objects (connectivity blocks), each storing groups of nodes forming geometric entities (like lines, triangles, quads, or volumes) and the corresponding ElementType.

This structure allows compact storage while supporting hybrid meshes with mixed element types.

Element indexing#

All elements in a HybridMesh are addressed through a global element index. This global indexing is obtained by concatenating the elements of all connectivity blocks in the order they are stored in elems.

This global element numbering is used consistently throughout the API, notably for:

  • element-based selection and masking

  • element-based Sets

  • element-based Fields (see below)

Fields on HybridMesh#

HybridMesh supports field data defined on:

  • nodes (fldtype='node'): data defined per mesh node

  • elements (fldtype='elem'): data defined per element, using the global element numbering described above

Element-node ('elemn') fields are currently not supported on HybridMesh, because a HybridMesh may contain element blocks with different plexitudes.

Parameters#

coords: Coords or array_like, optional

Shared coordinates for all element blocks.

elems: list of Elems or array_like, optional
List of element connectivity blocks. Each block can be:
  • an Elems object (already typed)

  • a 2D array_like connectivity (indices into coords)

eltypes: list of str or ElementType, optional

Optional list of element types for each block. Only needed if elems contains raw connectivity arrays.

Attributes#

coords: Coords (n_coords,3)

Shared coordinates of the mesh points.

elems: list of Elems

List of element blocks, each with its own element type.

Important

The HybridMesh class inherits from geometry.Geometry and therefore has all the methods defined there readily available.

A HybridMesh can be initialized in several ways:

  • Empty HybridMesh:

    >>> H = HybridMesh()
    >>> H.coords is None
    True
    >>> H.elems
    []
    
  • Points only (coords given, no elements):

    >>> coords = Coords([[0,0,0], [1,0,0], [1,1,0]])
    >>> H = HybridMesh(coords)
    >>> len(H.elems)
    0
    
  • Raw connectivity blocks (default element types assigned based on plexitude):

    >>> edges = [[0,1], [1,2], [2,0]]
    >>> faces = [[0,1,2]]
    >>> H = HybridMesh(coords, elems=[edges, faces])
    >>> [e.eltype.name for e in H.elems]
    ['Line2', 'Tri3']
    
  • Raw connectivity blocks with explicit element types:

    >>> H = HybridMesh(coords, elems=[edges, faces], eltypes=['line2','tri3'])
    >>> H.eltypes
    [Line2, Tri3]
    
  • Using prebuilt Elems objects:

    >>> from hellotriangle.elements import Elems
    >>> edge_elems = Elems(edges)
    >>> face_elems = Elems(faces)
    >>> H = HybridMesh(coords, elems=[edge_elems, face_elems])
    >>> [e.eltype.name for e in H.elems]
    ['Line2', 'Tri3']