Mondaic

salvus.mesh.data_structures.salvus_mesh.migration.unstructured_mesh

salvus.mesh.data_structures.salvus_mesh.migration.unstructured_mesh salvus mesh data_structures salvus_mesh migration unstructured_mesh

Migration utilities for UnstructuredMesh in relation to Mesh.

Functions

compare_um_migration_data()

def compare_um_migration_data(
    md_A: UnstructuredMeshMigrationData,
    md_B: typing.Any,
    raise_with_error_if_not_equal: bool = False,
) -> bool: ...

Compare two UnstructuredMeshMigrationData objects for equality.

Parameters
  • md_A UnstructuredMeshMigrationData — First UnstructuredMeshMigrationData object to compare.
  • md_B typing.Any — Second object to compare with.
  • raise_with_error_if_not_equal bool — If True, raise an error with a detailed report if the objects are not equal.
Returns bool — True if the objects are equal, False otherwise.

element_ordering_from_partitioning_field()

def element_ordering_from_partitioning_field(
    um: UnstructuredMesh, partitioning_field: str
) -> list[npt.NDArray]: ...

Compute the original element indices per block from an unstructured mesh.

Helpful for reconstructing elemental fields on the original unstructured mesh after partitioning into blocks.

Parameters
  • um UnstructuredMesh — The unstructured mesh.
  • partitioning_field str — The name of the elemental field used to partition the mesh into blocks.
Returns list[npt.NDArray] — A list where each entry contains the original element indices for each block.

mesh_from_unstructured_mesh()

def mesh_from_unstructured_mesh(
    um: UnstructuredMesh,
    partitioning_field: str | None,
    elemental_nodal_reduction: (
        typing.Literal["safe", "mean"] | numpy_utils._UfuncLike | None
    ) = "safe",
) -> Mesh: ...

Create mesh from an unstructured mesh.

As element-nodal fields cannot be represented in the new Mesh format, they are reduced to nodal fields during the conversion. Their discontinuities between blocks are preserved, but within-block discontinuities are handled according to the specified reduction method.

If global_element_ids is present as an elemental field in the unstructured mesh, it is used to set the global_element_ids of the new mesh (a dataclass member not considered a field), as well as being retained as an elemental field. If it is not present, global_element_ids is set to a consecutive numbering starting at zero for the first block, and continuing consecutively across blocks.

Parameters
  • um UnstructuredMesh — The unstructured mesh.
  • partitioning_field str | None — The name of the elemental field used to partition the mesh into blocks. If None, the following logic is applied in sequence, matching the first found: - If the field block is present, use that. - If the field layer is present, use that. - If neither is present, the entire mesh is treated as a single block.
  • elemental_nodal_reduction typing.Literal['safe', 'mean'] | numpy_utils._UfuncLike | None — The reduction method to use when converting elemental-nodal fields to nodal fields within each block. If “safe”, an error is raised if conflicting values are found at the same node. If “mean”, conflicting values are averaged. If None, the first occurrence is used. UFunc operations like np.add, np.maximum, np.minimum are also supported.
Returns Mesh — A mesh object representing the partitioned unstructured mesh. When constructed using this method, the mesh contains migration data allowing it to be converted back to the original unstructured mesh, available via the _migration_data attribute.

replace_side_sets_and_materials()

def replace_side_sets_and_materials(
    mesh: Mesh,
    side_sets: tuple[SideSet, ...] | None,
    materials: dict[int, type[PhysicalMaterial] | None] | None,
) -> Mesh: ...

Replace side sets and materials in a mesh.

Useful when applying unstructured mesh algorithms to the new format, which doesn’t retain side sets and materials.

Will overwrite existing materials if None is explicitly passed for a block.

Parameters
  • mesh Mesh — The mesh to modify.
  • side_sets tuple[SideSet, ...] | None — The new side sets to apply to the mesh.
  • materials dict[int, type[PhysicalMaterial] | None] | None — The new materials to apply to each block in the mesh.
Returns Mesh — A new mesh with the specified side sets and materials.

unstructured_mesh_from_mesh()

def unstructured_mesh_from_mesh(mesh: Mesh) -> UnstructuredMesh: ...

Convert the Mesh to an UnstructuredMesh.

Note that any discontinuous elemental-nodal fields are mean-reduced to nodal fields during the conversion. Their discontinuities between blocks are preserved, but within-block discontinuities are averaged out.

Any scalar nodal fields in the mesh are broadcast to full nodal fields in the new mesh.

This method will add two extra fields to the mesh if they are not present in the fields of the blocks:

  • global_element_ids: An elemental scalar field containing the global element IDs for each element in the mesh.
  • block: An elemental scalar field containing the block ID for each element in the mesh, which tells one which block the element came from. This is omitted if the mesh was constructed from an unstructured mesh. In that case, the migration data already contains the partitioning field, which is often block or layer.
Parameters
  • mesh Mesh — The mesh to convert.
Returns UnstructuredMesh — An UnstructuredMesh object representing the same mesh.

Classes

UmField

class UmField(enum.Enum):
    def __init__(self): ...

Field types in UnstructuredMesh.

UnstructuredMeshMigrationData

class UnstructuredMeshMigrationData(builtins.object):
    def __init__(
        self,
        original_element_indices: list[npt.NDArray],
        partitioning_field: str | None,
        field_mappings: dict[str, UmField],
        original_scale: float,
    ) -> None: ...

Data required to migrate a Mesh back to an UnstructuredMesh.

This class is used internally by the Mesh class to store data required for migration back to an UnstructuredMesh. It is not intended to be used directly by users.

Parameters
  • original_element_indices list[npt.NDArray] — List of original element indices per block. If one uses these arrays to index into fields on the original mesh, one obtains the fields in global element order of the new mesh blocks. Alternatively, the property reverse_ordering can be used to permute fields on the new mesh back to the original unstructured mesh.
  • partitioning_field str | None — The name of the elemental field used to partition the mesh into blocks. Is also still present as elemental field in the new mesh.
  • field_mappings dict[str, UmField] — Fields in the new mesh, and how they were originally represented in the unstructured mesh.
  • original_scale float — If a scale other than 1.0 was present on the original mesh, it is stored here to allow correct reconstruction of the original mesh.
Attributes
reverse_ordering npt.NDArray

The reverse ordering of elements to reconstruct the original mesh.

Property, as the reverse ordering can be fully computed from original_element_indices. This reverse ordering can be used to reconstruct the original unstructured mesh from the partitioned blocks.