Skip to content

Parsers

parsers

CloudParser

CloudParser(filepath: Path)

Object responsible for the parsing operation

Parameters:

Name Type Description Default
filepath Path

path to the source file

required
Source code in src/interpcore/parsers.py
def __init__(
    self,
    filepath: Path,
):
    """Object responsible for the parsing operation

    Parameters
    ----------
    filepath : Path
        path to the source file
    """
    # load the dataframe
    logging.info("Loading EM dataset...")
    skip = _detect_lines_to_skip(filepath)
    self.src_data = _detect_delimiter(filepath, skip)

get_coordinates

get_coordinates(col_mesh_x: int = 1) -> ndarray

Extract coordinates from the loaded data based on the specified columns and number of components.

Parameters:

Name Type Description Default
col_mesh_x int

index of the column containing x coordinates, by default 1

1

Returns:

Type Description
ndarray

point coordinates array of source mesh points

Source code in src/interpcore/parsers.py
def get_coordinates(self, col_mesh_x: int = 1) -> np.ndarray:
    """Extract coordinates from the loaded data based on the specified columns and
    number of components.

    Parameters
    ----------
    col_mesh_x : int, optional
        index of the column containing x coordinates, by default 1
    Returns
    -------
    np.ndarray
        point coordinates array of source mesh points
    """
    return self.src_data[:, col_mesh_x : col_mesh_x + 3]

get_values

get_values(val_idx: int, n_components: int = 1) -> ndarray

Extract values from the loaded data based on the specified column.

Parameters:

Name Type Description Default
val_idx int

index of the column containing the values

required
n_components int

number of components to extract, by default 1

1

Returns:

Type Description
ndarray

array of values from the specified columns

Source code in src/interpcore/parsers.py
def get_values(self, val_idx: int, n_components: int = 1) -> np.ndarray:
    """Extract values from the loaded data based on the specified column.

    Parameters
    ----------
    val_idx : int
        index of the column containing the values
    n_components : int, optional
        number of components to extract, by default 1
    Returns
    -------
    np.ndarray
        array of values from the specified columns
    """
    return self.src_data[:, val_idx : val_idx + n_components]

EMCloudParser

EMCloudParser(filepath: Path)

Bases: CloudParser

Source code in src/interpcore/parsers.py
def __init__(
    self,
    filepath: Path,
):
    """Object responsible for the parsing operation

    Parameters
    ----------
    filepath : Path
        path to the source file
    """
    # load the dataframe
    logging.info("Loading EM dataset...")
    skip = _detect_lines_to_skip(filepath)
    self.src_data = _detect_delimiter(filepath, skip)

get_values

get_values(val_idx: int, n_components: int = 3, v_idx: int | None = None) -> ndarray

Extract force values from the loaded data based on the specified columns for forces and volumes.

Parameters:

Name Type Description Default
val_idx int

index of the column containing the force components

required
v_idx int

index of the column containing volume information, by default None. If provided, the forces are interpreted as densities and scaled by the volume.

None

Returns:

Type Description
ndarray

array of force values, scaled by volume if v_idx is provided

Source code in src/interpcore/parsers.py
def get_values(
    self, val_idx: int, n_components: int = 3, v_idx: int | None = None
) -> np.ndarray:
    """Extract force values from the loaded data based on the specified columns for
    forces and volumes.

    Parameters
    ----------
    val_idx : int
        index of the column containing the force components
    v_idx : int, optional
        index of the column containing volume information, by default None.
        If provided, the forces are interpreted as densities and scaled by the volume.

    Returns
    -------
    np.ndarray
        array of force values, scaled by volume if v_idx is provided
    """
    forces = self.src_data[:, val_idx : val_idx + n_components]
    if v_idx is not None:
        volumes = self.src_data[:, v_idx]
        forces = forces * volumes[:, np.newaxis]
    return forces

parse_mech_mesh

parse_mech_mesh(filepath: Path, col_mesh_ids: int = 0, col_mesh_x: int = 1, col_vol: int | None = None, col_area: int | None = None) -> dict[str, ndarray]

Parse a mechanical mesh and return the array of coordinates and the vector of node numbers

Parameters:

Name Type Description Default
filepath Path

path to the mechanical mesh file

required
col_mesh_ids int

index of the column containing node/element numbers, by default 0

0
col_mesh_x int

index of the column containing x coordinates, by default 1

1
col_vol int

index of the column containing volume information, by default None

None
col_area int

index of the column containing area information, by default None

None

Returns:

Type Description
tuple[ndarray, ndarray]

coordinates: np.ndarray point coordinates array of mechanical mesh nodes/element centroids id_numbers: np.ndarray array of mechanical mesh node/element numbers

Source code in src/interpcore/parsers.py
def parse_mech_mesh(
    filepath: Path,
    col_mesh_ids: int = 0,
    col_mesh_x: int = 1,
    col_vol: int | None = None,
    col_area: int | None = None,
) -> dict[str, np.ndarray]:
    """Parse a mechanical mesh and return the array of coordinates and the vector
    of node numbers

    Parameters
    ----------
    filepath : Path
        path to the mechanical mesh file
    col_mesh_ids : int, optional
        index of the column containing node/element numbers, by default 0
    col_mesh_x : int, optional
        index of the column containing x coordinates, by default 1
    col_vol : int, optional
        index of the column containing volume information, by default None
    col_area : int, optional
        index of the column containing area information, by default None

    Returns
    -------
    tuple[np.ndarray, np.ndarray]
        coordinates: np.ndarray
            point coordinates array of mechanical mesh nodes/element centroids
        id_numbers: np.ndarray
            array of mechanical mesh node/element numbers
    """
    logging.info("Loading Mechanical Mesh...")
    skip1 = _detect_lines_to_skip(filepath)
    Detailed_mesh = _detect_delimiter(filepath, skip1)
    # Detailed_mesh  =  df1.values

    coordinates = Detailed_mesh[:, col_mesh_x : col_mesh_x + 3]
    id_numbers = Detailed_mesh[:, col_mesh_ids]
    result = {"coordinates": coordinates, "id_numbers": id_numbers}
    if col_vol is not None:
        result["volumes"] = Detailed_mesh[:, col_vol]
    if col_area is not None:
        result["areas"] = Detailed_mesh[:, col_area]
    return result

parse_values

parse_values(filepath: Path, load_type: INTERPOLATED_LOAD_TYPE, columns: ColumnsConfig, n_components: int) -> tuple[ndarray, ndarray]

Parse values to be interpolated

Parameters:

Name Type Description Default
filepath Path

path to the source file

required
load_type INTERPOLATED_LOAD_TYPE

type of load to be interpolated

required
columns ColumnsConfig

column indices for parsing the source file

required
n_components int

number of components to extract

required

Returns:

Type Description
tuple[ndarray, ndarray, ndarray]

coordinates: np.ndarray point coordinates array of source mesh points values: np.ndarray array of values to interpolate

Source code in src/interpcore/parsers.py
def parse_values(
    filepath: Path,
    load_type: INTERPOLATED_LOAD_TYPE,
    columns: ColumnsConfig,
    n_components: int,
) -> tuple[np.ndarray, np.ndarray]:
    """Parse values to be interpolated

    Parameters
    ----------
    filepath : Path
        path to the source file
    load_type : INTERPOLATED_LOAD_TYPE
        type of load to be interpolated
    columns : ColumnsConfig
        column indices for parsing the source file
    n_components : int
        number of components to extract

    Returns
    -------
    tuple[np.ndarray, np.ndarray, np.ndarray]
        coordinates: np.ndarray
            point coordinates array of source mesh points
        values: np.ndarray
            array of values to interpolate
    """
    if load_type == INTERPOLATED_LOAD_TYPE.EM_FORCE:
        parser = EMCloudParser(filepath)
        values = parser.get_values(
            val_idx=columns.value,
            n_components=n_components,
            v_idx=columns.volume_area,
        )
    else:
        parser = CloudParser(filepath)
        values = parser.get_values(val_idx=columns.value, n_components=n_components)

    coordinates = parser.get_coordinates(col_mesh_x=columns.source_xyz)
    return coordinates, values