Module i2pp.core.discretization_readers.trimesh_reader

Import discretizations readable by trimesh (.mesh).

Classes

class TrimeshReader
Expand source code
class TrimeshReader(DiscretizationReader):
    """Class for reading and processing finite element models with trimesh.

    This class extends `DiscretizationReader` to handle `.mesh` files via
    `trimesh`, which store discretized finite element models. It provides
    functionality to
    import the mesh, filter elements with an element filter, and structure the
    data into a `Discretization` object.
    """

    def _filter_discretization(self) -> None:
        """Filters the finite element model to include only elements passing
        the element filter.

        This function iterates through the elements in the discretized
        model and selects only those whose filter field matches one of
        the specified values. The corresponding nodes of these elements
        are also retained. After filtering, the nodes are sorted based
        on their IDs.
        """
        raise RuntimeError("This function is not implemented yet.")

    def load_discretization(
        self,
        file_path: Path,
        options: dict,
        processing: Processing,
    ) -> Discretization:
        """Loads and processes a finite element model from a .mesh file.

        This function imports the nodes and elements from a .mesh file using
        `trimesh`, organizes them into a `Discretization` object, and
        initializes necessary attributes.

        Arguments:
            file_path (Path): Path to the .mesh file.
            options (dict): Options for loading the discretization.

        Returns:
            Discretization: A structured representation of the finite element
                model, including nodes and elements.
        """

        logging.info("Importing Model data")

        raw_dis = trimesh.load(file_path)

        if (options or {}).get("element_filter") is not None:
            self._filter_discretization()

        nodes = Nodes(
            coords=raw_dis.vertices, ids=list(range(len(raw_dis.faces)))
        )

        elements = []
        for i, face in enumerate(raw_dis.faces):
            elements.append(Element(node_ids=face, id=i))

        # Add surfaces here if needed in the future

        dis = Discretization(nodes=nodes, elements=elements, surfaces=[])

        return dis

Class for reading and processing finite element models with trimesh.

This class extends DiscretizationReader to handle .mesh files via trimesh, which store discretized finite element models. It provides functionality to import the mesh, filter elements with an element filter, and structure the data into a Discretization object.

Init DiscretizationReader.

Ancestors

Methods

def load_discretization(self, file_path: Path, options: dict, processing: Processing) ‑> Discretization
Expand source code
def load_discretization(
    self,
    file_path: Path,
    options: dict,
    processing: Processing,
) -> Discretization:
    """Loads and processes a finite element model from a .mesh file.

    This function imports the nodes and elements from a .mesh file using
    `trimesh`, organizes them into a `Discretization` object, and
    initializes necessary attributes.

    Arguments:
        file_path (Path): Path to the .mesh file.
        options (dict): Options for loading the discretization.

    Returns:
        Discretization: A structured representation of the finite element
            model, including nodes and elements.
    """

    logging.info("Importing Model data")

    raw_dis = trimesh.load(file_path)

    if (options or {}).get("element_filter") is not None:
        self._filter_discretization()

    nodes = Nodes(
        coords=raw_dis.vertices, ids=list(range(len(raw_dis.faces)))
    )

    elements = []
    for i, face in enumerate(raw_dis.faces):
        elements.append(Element(node_ids=face, id=i))

    # Add surfaces here if needed in the future

    dis = Discretization(nodes=nodes, elements=elements, surfaces=[])

    return dis

Loads and processes a finite element model from a .mesh file.

This function imports the nodes and elements from a .mesh file using trimesh, organizes them into a Discretization object, and initializes necessary attributes.

Arguments

file_path (Path): Path to the .mesh file. options (dict): Options for loading the discretization.

Returns

Discretization
A structured representation of the finite element model, including nodes and elements.