mesh-sieve
mesh-sieve is a modular, high-performance Rust library for mesh topology and field data. It powers refinement/assembly pipelines and overlap-driven exchange for serial, threaded, and MPI-distributed workflows. The APIs are Result-first (no hidden panics), invariants are easy to validate (strict-invariants), and the data layer is storage-generic (CPU Vec by default; optional wgpu backend).
Features
- Mesh Topology: generic Sieve graphs for incidence and traversal (cone/support/closure/star), plus lattice ops (meet/join) and strata (height/depth).
- Field Data: Atlas (layout) + Section (values) with fallible accessors and strong invariants. Fast scatter paths for contiguous layouts.
- Storage Abstraction:
Section<V, S>whereS: SliceStorage<V>(built-inVecStorage; optionalWgpuStoragewith compute kernels). - Parallel Communication: pluggable Communicator backends (serial
NoComm, in-processRayonComm, feature-gatedMpiComm). - Overlap: bipartite local↔rank structure with strict mirror validation; helpers to expand along mesh closure.
- Partitioning: optional METIS helpers and in-tree algorithms.
- Testing & CI: property tests, deterministic iterators, and feature-gated deep invariant checks.
- Performance: point-only adapters (no payload cloning), degree-local updates, preallocation hints, streaming algorithms, and inline hot paths.
Getting Started
Cargo Features
Enable only what you need:
[]
= { = "2", = [
# safety & determinism
# "strict-invariants", # deep invariant checks in debug/CI
# "deterministic-order", # stable BTree maps/sets for IO/repro
# "fast-hash", # AHash maps/sets for speed (non-deterministic order)
# parallel & distributed
# "rayon", # parallel refine/assemble utilities
# "mpi-support", # MPI communicator backend
# partitioning
# "metis-support", # METIS bindings
# data adapters
# "map-adapter", # legacy infallible helpers (panic-on-miss)
# GPU
# "wgpu", # WgpuStorage for Section (V: Pod + Zeroable)
] }
CI tip: run a lane with
--features strict-invariantsto catch structural and mirror mistakes early, even in optimized builds.
Quick Examples
Topology (InMemorySieve)
use ;
use PointId;
let mut g = default;
let a = new?; let b = new?;
g.add_arrow;
for v in g.cone_points
let reach: = g.closure_iter.collect;
Field Data (Atlas + Section over Vec)
use Atlas;
use VecStorage;
use Section;
use PointId;
let mut atlas = default;
let p = new?;
atlas.try_insert?;
let mut sec = new;
sec.try_set?;
let s = sec.try_restrict?; // &[f64]
Refine/Assemble (Bundle)
use ;
use InMemoryStack;
let mut bundle: = Bundle ;
// Refinement (base -> cap) with orientation-aware slice transforms:
bundle.refine?;
// Assembly (cap -> base) with explicit reduction; lengths checked up-front:
bundle.assemble_with?;
Overlap (distributed links)
use Overlap;
use PointId;
let mut ov = default;
let p = new?;
let neighbor = 1usize;
let inserted = ov.add_link_structural_one; // remote unknown yet
// Later:
ov.resolve_remote_point?;
MPI Examples
# build with MPI
# or:
More examples:
mpi_complete.rs,mpi_complete_stack.rs: section/stack completionmesh_distribute_two_ranks.rs: distributing a meshmpi_complete_multiple_neighbors.rs: multi-neighbor exchange
Project Structure
src/
topology/ # Sieve & traversal, strata, lattice
data/ # Atlas, Section, storage backends (Vec/WGPU), deltas, helpers
overlap/ # Overlap graph, value deltas, perf types
algs/ # communicators, completion, distribute, partition utilities
partitioning/ # METIS integration + in-tree algorithms
...
What’s New in 2.x (highlights)
Breaking (safer)
- Fallible APIs only in data/atlas: panicking shims (
insert,restrict,restrict_mut,set,get,get_mut) are removed or gated. Prefertry_*. Atlas::remove_point(p)now returnsErr(MissingAtlasPoint(p))if absent.Section::with_atlas_mutrejects length changes for existing points. Usewith_atlas_mut_resize(..., ResizePolicy)when resizing is intended.Orientation→Polarity(renamed). The old alias is deprecated.
Data/Storage
-
Section<V, S>is generic over storage (S: SliceStorage<V>):VecStorage(CPU) for anyV: Clone + DefaultWgpuStorage(featurewgpu) forV: bytemuck::Pod + Zeroable
-
ScatterPlan { atlas_version, spans }is a stable contract; plans are refused if versions diverge. -
Fast-path scatter: if spans are contiguous and buffer lengths match, we do a single
clone_from_slice.
Overlap
-
Stronger invariants in
validate_invariants():- Bipartite direction and payload.rank equals Part(r)
- No duplicate edges
- (opt-in) no empty Part nodes (
check-empty-part) - Strict in/out mirror (under
strict-invariants): counts, endpoints and payloads must match exactly.
Performance & Determinism
- Streaming in
Bundle::{refine, assemble_with}(no per-base heap churn). - Preallocation hints (
reserve_cone,reserve_support). - Inline hot getters (
Atlas::get,Section::try_restrict(_mut)). - Choose
fast-hashfor speed ordeterministic-orderfor reproducible iteration.
Error Hygiene
- No synthetic
PointIds in errors. - More precise variants (
AtlasPointLengthChanged { point, old_len, new_len },AtlasPlanStale, strict overlap mirror errors).
API Overview (at a glance)
| Area | Key APIs |
|---|---|
| Sieve | cone(_)/support(_), cone_points(_)/support_points(_), closure_iter, star_iter |
| Atlas | try_insert, get, remove_point, points, atlas_map, version, invariants |
| Section | new, try_restrict(_)/try_restrict_mut(_), try_set, with_atlas_mut, with_atlas_mut_resize, try_scatter_*, try_apply_delta_between_points |
| Storage | VecStorage, (opt-in) WgpuStorage (delta via copy/compute) |
| Deltas | data::refine::SliceDelta (slice→slice; e.g., Polarity), overlap::ValueDelta (comm/merge; e.g., CopyDelta, AddDelta, ZeroDelta) |
| Overlap | add_link_structural_one, add_links_structural_bulk, resolve_remote_point(s), ensure_closure_of_support |
| Bundles | refine(bases), assemble_with(bases, &Reducer) |
| Algs | completion for sieve/section/stack; communicator trait & backends |
Legacy infallible helpers (
restrict_closure,restrict_star, etc.) and theMapadapter are gated behindfeature = "map-adapter". PreferFallibleMap+try_*helpers.
GPU Backend (feature wgpu)
-
Use
Section<V, WgpuStorage<V>>withV: bytemuck::Pod + Zeroable. -
Delta routing:
Polarity::Forward→copy_buffer_to_bufferPolarity::Reverse→ tinyreverse_copy.wgslcompute kernel (or equivalent)- Custom
SliceDelta→ dedicate small compute pipelines
-
Scatter validates
ScatterPlan.atlas_versionvsAtlas::version()before encoding commands.
Performance & Determinism
- Prefer concrete iterators (
*_iter) and point-only adapters (cone_points,support_points) in hot paths. - Use
reserve_cone/reserve_supportbefore bulk updates. - Turn on
fast-hashfor speed ordeterministic-orderfor stable I/O and tests. - The data layer uses streaming and single-copy fast-paths whenever layouts are contiguous.
Testing
-
Property tests for Atlas/Section coherence (random insert/remove/shuffle +
validate_invariants+ scatter/gather round-trip). -
Delta aliasing tests (overlap/disjoint) to ensure no panics.
-
Parallel determinism (with
rayon) for refine/assemble parity. -
CI lane with:
Breaking Changes & Migration
-
Panicking data APIs removed/gated
- Migrate
insert/restrict/restrict_mut/set/get/get_mut→try_*equivalents. - Temporarily enable
map-adapterto keep legacy helpers while you refactor.
- Migrate
-
with_atlas_mutis strict- Existing points’ lengths may not change; you’ll get
AtlasPointLengthChanged. - Use
with_atlas_mut_resize(|atlas| { ... }, ResizePolicy::PreservePrefix|PreserveSuffix|Reinit)for explicit resizes.
- Existing points’ lengths may not change; you’ll get
-
Orientation→Polarity- Update imports/constructors.
-
Overlap mirror checks (strict)
- If you touched
adjacency_*directly, switch to API mutators. Strict mode verifies in/out symmetry and payload equality.
- If you touched
License
MIT — see LICENSE.