Source code for nekmeshpy.tags.sweep
"""Reading a ``loft``'s three tag arguments into stored tables."""
from __future__ import annotations
import numpy as np
from .._typing import StrArray
from .tags import Tags
__all__ = ["sweep_tags", "sweep_cap"]
def _check_slice(spec: Tags, n_slice: int) -> None:
if spec.size != int(n_slice):
raise ValueError("a Tags handed to a loft must be over the %d elements of one "
"slice, got one over %d" % (n_slice, spec.size))
[docs]
def sweep_cap(spec: str | Tags | None, default: Tags, n_slice: int) -> StrArray:
"""One cap's dense ``(n_slice,)`` tag row from a ``loft``'s ``first_tag`` /
``last_tag`` argument, falling back to ``default`` (the bounding slice's own
element tags -- a cap side *is* that slice element) when the argument is ``None``.
"""
if spec is None:
return default.to_dense()
if isinstance(spec, str):
return np.full(int(n_slice), spec)
if isinstance(spec, Tags):
_check_slice(spec, n_slice)
return spec.to_dense()
raise TypeError(
"a cap tag must be a tag string, a Tags over the %d elements of "
"one slice, or None; got %s" % (n_slice, type(spec).__name__))