tags¶
Sparse tag tables and the operations that carry them through a mesh.
- class nekmeshpy.tags.Tags[source]¶
Bases:
objectA mesh’s per-element region tags over
sizeelements, stored sparsely: only tagged elements.sizeis the total element count the table is over, so a tagged id outside it is refused at construction andto_denseneeds no length argument.- ids: NDArray[int64]¶
- classmethod empty(size)[source]¶
The nothing-tagged table over
sizeelements – what an untagged mesh stores.
- classmethod full(shape, fill_value)[source]¶
shapeelements all namedfill_value(orempty()when it is empty), asnp.full.
- to_dense()[source]¶
The equivalent dense
(size,)array,""where untagged.- Return type:
NDArray[str_]
- unique() → list[str][source]¶
- unique(return_inverse: Literal[True], return_counts: Literal[False] = False) → tuple[list[str], NDArray[int64]]
- unique(return_inverse: Literal[False] = False, *, return_counts: Literal[True]) → tuple[list[str], NDArray[int64]]
- unique(return_inverse: Literal[True], return_counts: Literal[True]) → tuple[list[str], NDArray[int64], NDArray[int64]]
Sorted unique tags, as
np.unique.With
return_inversealso the index into them of each stored row’s tag (aligned withids), soinverse + 1is a per-row integer code. Withreturn_countsalso how many elements carry each name.
- isin(test_elements)[source]¶
Boolean mask over the rows (not the elements) whose tag is one of
test_elements, asnp.isin; a single string is one name.
- flatnonzero(test_elements, strict=False)[source]¶
Ids of the elements whose tag is one of
test_elements, ascending, asnp.flatnonzero(np.isin(dense, test_elements)); a single string is one name.strictraisesValueErrorif any name is carried by no element – an empty result is otherwise silent, and a mis-spelled name is almost always a typo.
- compress(condition)[source]¶
The rows where
conditionis true, ascending id order preserved, asnp.compressover the stored rows (sizeis unchanged).conditionis 1-D and may be shorter than the table, the missing rows counting as false; a true entry past the last row raisesIndexError.
- retag(spec)[source]¶
One entry point for changing a table, by what
specis: a mappingrename()the existing vocabulary; a string names every element; aTagsor a per-element sequence replaces the table outright (and must be over this table’ssize).
- rename(mapping)[source]¶
The same elements under a new vocabulary: a tag the map does not name is left alone, the map applies simultaneously, two keys may share an image, and a key that names nothing raises.
Renaming a region to
""drops it back to untagged, which is what this sparse table stores as no row at all.The map is read once and written once, hence simultaneous:
{"a": "b", "b": "a"}swaps rather than collapsing. The result is re-widened, so a longer name is not truncated to the input’s dtype. A key naming nothing raises, since a rename that silently matches nothing is almost always a typo.
- take(indices)[source]¶
Tags for a new element list whose element
kcopies sourceindices[k], asnp.take(mode='raise'): negative indices count from the end, one out of bounds raisesIndexError. The result is overlen(indices)elements.The sparse form of
dense[indices].- Parameters:
indices (NDArray[int64])
- Return type:
- take_dense(indices)[source]¶
The name of each element in
indicesas a string array,""where untagged –take(indices).to_dense(), asnp.takeon the dense array.- Parameters:
indices (NDArray[int64])
- Return type:
NDArray[str_]
- put(ids, values)[source]¶
This table with
idsnamedvalues(one string for all, or one per id), asnp.put(mode='raise'): a name already on an id is overwritten, when an id repeats the last value wins, and one out of bounds raisesIndexError.A
""value names nothing and leaves that element as it was (useclear()to untag).
- clear(ids)[source]¶
This table with the tags on
idsremoved (sizeis unchanged); an id that is not tagged is ignored, one out of bounds raisesIndexError.- Parameters:
ids (NDArray[int64])
- Return type:
- repeat(repeats)[source]¶
Each element repeated
repeatstimes in place, overrepeats * sizeelements: elementi*repeats + jcopiesi.The sparse form of
np.repeat(dense, repeats)– a refine’s children each inherit their parent’s name.
- __init__(ids, tags, size)¶
- tile(reps)[source]¶
This table tiled
repstimes, overreps * sizeelements: elementi*size + q.The sparse form of
np.tile(dense, reps).
- nekmeshpy.tags.sweep_tags(spec, n_layers, n_slice)[source]¶
The swept elements’ region tags from a
loft’selement_tagsargument.Nonetags nothing, astrtags every swept element, and anTagsover one slice’sn_sliceelements tags each element by the slice element it was extruded from (elementi*n_slice + k).
- nekmeshpy.tags.sweep_cap(spec, default, n_slice)[source]¶
One cap’s dense
(n_slice,)tag row from aloft’sfirst_tag/last_tagargument, falling back todefault(the bounding slice’s own element tags – a cap side is that slice element) when the argument isNone.
- nekmeshpy.tags.weld(tables)[source]¶
Combine tables that may name the same element – what a
mergeproduces once its weld has carried two blocks’ tags onto one shared entity.Plain
Tags.concatenatecannot do this: it would hand the constructor two rows for one id, which is rejected. Here the duplicate is expected and meaningful, so it is resolved rather than refused – but only when the two agree. Two different non-empty names on one entity is the contradiction the shared-entity storage exists to rule out, and there is no honest way to pick between them, so it raises.An entity named by one side and left untagged by the other simply takes the name: that is the ordinary case of a tagged block welding onto an untagged neighbour.
Every table must be over the same element count, which the result keeps.