Skip to content

salvus.mesh.data_structures.salvus_mesh.material_codec

salvus.mesh.data_structures.salvus_mesh.material_codec salvus mesh data_structures salvus_mesh material_codec

Encode/decode a MeshBlock.material class as a plain string.

Lives here, next to MeshBlock itself, rather than inside serialization/hdf5.py: any interaction that needs to move a MeshBlock.material class somewhere it cannot be pickled directly (an HDF5 attribute, or across an MPI rank boundary) needs this same encode/decode pair, not just HDF5 serialization specifically.

Functions

material_class_from_fqn()

def material_class_from_fqn(
    mat_attr: str | bytes | np.bytes_ | None,
) -> type[PhysicalMaterial] | None: ...

Decode a material class from material_class_to_fqn’s own encoding (or the previous abc:-prefixed one older HDF5 files carry).

Shared by serialization/hdf5.py’s _read_material_in_block and algorithms.distributed_mesh.mpi_communication._transfer_mesh_block so the two decode paths cannot drift apart — the latter used to hardcode material=None unconditionally rather than risk reconstructing a class it could not yet decode; it now gets exactly the same reconstruction (and the same known limitation) this function already provides for HDF5.

Parameters
  • mat_attr str | bytes | np.bytes_ | None — The encoded string (a plain str, or bytes/ np.bytes_ as HDF5 attributes are read back), or None if no material class was attached.
Returns type[PhysicalMaterial] | None — The reconstructed material class, or None if mat_attr is None, not decodable, or names a class known to be unreconstructable from its name alone (e.g. an auto-derived wavelength-oracle approximation).

material_class_to_fqn()

def material_class_to_fqn(
    cls: type[PhysicalMaterial] | None,
) -> str | None: ...

Encode a material class as material_class_from_fqn’s own module:qualname string — its exact inverse.

Shared by serialization/hdf5.py (the block writer) and algorithms.distributed_mesh.mpi_communication._transfer_mesh_block (MPI rank-to-rank mesh transfer), so a MeshBlock.material round-trips the same way whether it crosses an HDF5 file or an MPI rank boundary.

Parameters
  • cls type[PhysicalMaterial] | None — The material class to encode, or None for a block with no material class attached.
Returns str | None — f"{cls.__module__}:{cls.__qualname__}", or None if cls is None.