salvus.mesh.data_structures.salvus_mesh.algorithms.fields
salvus.mesh.data_structures.salvus_mesh.algorithms.fields salvus mesh data_structures salvus_mesh algorithms fields Helper functions for field handling of mesh blocks.
Functions
choose_int_dtype()
choose_int_dtype()def choose_int_dtype(
arr: npt.NDArray, validate_whole: bool = False
) -> np.dtype: ...Choose the smallest integer dtype that can represent the array.
Prefer unsigned dtypes for arrays that are non-negative (connectivity, global point ids, etc.) to further reduce storage. Falls back to signed types when negative values are present.
If an array of size zero is given, np.int32 is returned.
arrnpt.NDArray — The array to choose the dtype for.validate_wholebool — If True, validate that all values in the array are whole numbers (integers). Floats are allowed if they are whole numbers.
collapse_constant_nodal_fields()
collapse_constant_nodal_fields()def collapse_constant_nodal_fields(
mesh: MeshType, field_name: str | None = None
) -> MeshType: ...Collapse constant nodal fields to scalars, in-place.
If mesh is a Mesh, operate on all blocks. If mesh is a MeshBlock,
operate on that block. If field_name is given, only collapse that field;
otherwise, collapse all nodal fields.
meshMeshType — The Mesh or MeshBlock to operate on.field_namestr | None — If provided, only collapse this nodal field.
collect_elemental_field_arrays()
collect_elemental_field_arrays()def collect_elemental_field_arrays(
blocks: tuple[MeshBlock, ...],
field_name: str,
fill_value: types.scalar_ | None = None,
output_dtype: np.dtype | None = None,
) -> tuple[list[npt.NDArray], np.dtype]: ...Collect and prepare per-block elemental field arrays for global assembly.
blockstuple[MeshBlock, ...] — List of MeshBlock objects.field_namestr — Name of the field to collect.fill_valuetypes.scalar_ | None — Value to fill missing blocks.output_dtypenp.dtype | None — Desired numpy dtype for output arrays.
fill_value and all arrays cast to output_dtype. The output dtype is the common dtype used for all arrays.collect_nodal_field_arrays()
collect_nodal_field_arrays()def collect_nodal_field_arrays(
blocks: tuple[MeshBlock, ...],
field_name: str,
fill_value: types.scalar_ | None = None,
output_dtype: np.dtype | None = None,
) -> tuple[list[npt.NDArray], np.dtype, npt.NDArray]: ...Collect and prepare per-block nodal field arrays for global assembly.
blockstuple[MeshBlock, ...] — List of MeshBlock objects.field_namestr — Name of the field to collect.fill_valuetypes.scalar_ | None — Value to fill missing blocks.output_dtypenp.dtype | None — Desired numpy dtype for output arrays.
fill_value and all arrays cast to output_dtype. The output dtype is the common dtype used for all arrays. The index mapping (section) is a 1D array of global indices corresponding to each entry.determine_common_dtype()
determine_common_dtype()def determine_common_dtype(dtypes: list[np.dtype]) -> np.dtype: ...Determine the common dtype for arrays, handling special cases.
This helper function determines the appropriate common dtype for a collection of arrays, taking into account the default value, potential upcasting needs, and explicit output dtype requirements.
dtypeslist[np.dtype] — List of dtypes from the arrays to be combined.
expand_scalar_nodal_fields()
expand_scalar_nodal_fields()def expand_scalar_nodal_fields(
mesh: MeshType, field_name: str | None = None
) -> MeshType: ...Expand scalar nodal fields back to arrays, in-place.
This is the reverse operation of collapse_constant_nodal_fields. Any
nodal field stored as a scalar will be broadcast to an array of length
number_of_points of its block. Existing array-valued nodal fields are
left untouched.
meshMeshType — TheMeshorMeshBlockto operate on.field_namestr | None — If provided, only expand this nodal field; otherwise all scalar nodal fields are expanded.
Mesh or MeshBlock with scalar nodal fields expanded to arrays.