Skip to content

PointCloud Voronoi construction

Set dataset_type: pointcloud_voronoi and put construction options under pointcloud_voronoi.construction. All are optional. CGAL is the production default when compiled in; builds without CGAL default to Voro++.

dataset_type: pointcloud_voronoi
pointcloud_voronoi:
  loader: gadget
  gadget:
    path: ./snapdir_099
    fields: [Density, Temperature]
  construction:
    voronoi_backend: cgal

Construction options

Key Default Meaning
voronoi_backend cgal (voro without CGAL) cgal, voro, or experimental sycl.
fallback_backend cgal (voro without CGAL) Host fallback for unresolved SYCL cells: cgal, voro, or none.
voro_threads 1 Voro++ OpenMP workers per MPI rank.
bounded_tesselation false Debug-only convex-hull construction; removes infinite-vertex cells. Supported by CGAL.
ghost_thickness Auto for periodic; 0.51 for CUBE CGAL ghost-shell width as a fraction of the smallest box side; negative requests auto sizing. See below.
ghost_safety_factor 3.0 Radius multiplier for auto ghost sizing.
tessellation_domain_epsilon 0.0 Expand non-periodic CUBE clipping from [0, 1]^3 to [-eps, 1+eps]^3, admitting cutout particles on the lower face. Coordinates are unchanged.
min_face_area -1.0 Host backends discard face contributions below this area; negative disables filtering.
post_cleanup_sanity_checks true Validate the final topology, including self-neighbors and symmetry between certified cells.

Auto ghost sizing uses max_i(C·r_i − d_wall_i, 0) from volume-equivalent MaxDist radii, with C = ghost_safety_factor. Gadget gas loading requests the radius recipe when applicable; other loaders must provide MaxDist. Periodic construction uses auto sizing when ghost_thickness is omitted. CUBE requires an explicit negative value to enable it.

Without usable radii, the shell falls back to 0.51, which can be expensive in memory. Set an explicit thickness when needed; periodic ghost validation stops construction if it is too thin. Ghost shells apply to CGAL construction and CGAL fallback; Voro++ uses native periodic containers or box walls.

Default backend: CGAL

CGAL constructs the mesh through exact-predicates Delaunay triangulation. Normal runs use periodic boundaries or box-clipped CUBE_OLD; reserve bounded_tesselation for debugging.

For the known hang when independent CGAL constructions run concurrently on one node, see Troubleshooting. Build once and reuse a mesh cache for repeated runs.

Voro++ backend (opt in)

Select voronoi_backend: voro in a build with THOR_ENABLE_VORO=ON. The bundled library is the default; THOR_VORO_PROVIDER=SYSTEM selects an installed library. Voro++ supports CUBE_OLD and PERIODIC, but not BOUNDED. Set voro_threads to the CPU workers available per rank.

Local geometry completeness

Each MPI rank holds its owned cells and ghost cells owned by other ranks. Domain padding, controlled by local_domain_pad, extends the loaded region beyond the owned domain. It is separate from the periodic image shell controlled by construction.ghost_thickness.

Setup generates LocalGeometryComplete for every local cell, including ghost cells: 1 certifies that neither unloaded particles nor omitted periodic images can change its geometry; 0 means completeness is unproven. The shared sufficient condition is 2R + margin < D, where R encloses the final cell and D bounds the distance to either source of missing generators. Complete periodic image coverage, including native periodic construction, needs no finite shell bound. Validated mesh caches retain these results. The field cannot be supplied as an ordinary input field. Certification covers geometry, not physical-field coverage.

Certification requires complete loading coverage. Particle-count limits, Gadget file subsets and periodic Gadget zoom selections disable it. MPI transport requires every owned cell to pass; full serial periodic runs require every physical cell to pass. Uncertified ghost cells are allowed. Setup logs per-rank counts and stops all ranks on an owned-cell failure, identifying input coverage, periodic coverage, or reconstruction failures. When possible, an input-coverage failure recommends a larger local_domain_pad. Periodic-coverage failures require reviewing construction.ghost_thickness. Rebuild and rerun certification; padding is never enlarged automatically.

MCRT transport through padding

Read-only MCRT may propagate and scatter in certified ghost cells when physical fields cover all locally loaded particles. It hands an incomplete ghost cell to its owner before using its geometry or fields. Handoffs identify the cell by its generator position and preserve photon position and optical depth.

A kernel-budget yield in safe padding resumes locally. Periodic wrapping, domain escape, ray tracing and field-update ownership rules are unchanged. Ghost cells use zero for the nonlocal AtimesTau0_NL contribution while retaining local core-skipping acceleration; geometry certification does not authorize nonlocal cache access or writes to another rank's fields.

Mesh caching

Cache options live directly under pointcloud_voronoi. A cache saves neighbor connectivity so later runs can skip tessellation.

Key Default Meaning
mesh_cache_layout local Cache this rank's mesh, or use global for a rank-independent mesh reusable with any MPI rank count.
mesh_cache_mode disabled save: build and write; load: require a compatible cache; auto: load or rebuild and save. Global layout supports only save and load.
mesh_save_path "" Output path; generated when empty in local layout. Global layout requires an explicit path.
mesh_load_path "" Input path, with the same layout rules. In local auto mode, one explicit path serves both operations; two remain independent.
mesh_cache_ids true Include local-cache row identities for external readers, costing 8 bytes per point on disk. Global identities are always written.
exit_after_mesh_write false Exit after required certification and a successful save; global layout also waits for finalization. An auto cache hit does not trigger this exit.
mesh_part_count unset Split the box into this many domains and build only one of them in this process; see Independent parts.
mesh_part_index unset The domain to build, from 0 to mesh_part_count - 1.

Local v5 caches store per-row completeness results alongside the neighbor graph; uncertified ghost-cell rows remain uncertified after reload. Global v2 caches contain only certified owner rows. Loading validates the format, geometry identity, boundary conditions and checksum before reusing certificates; it does not repeat the geometric proof. A global consumer does not apply its own periodic shell to the already constructed mesh.

Older cache versions lack this certification contract. Local auto mode rebuilds them; explicit load mode requires regenerating the cache. Both cache layouts publish only after required ownership certification succeeds.

Global caches from parallel construction

Global caches require a full periodic Gadget snapshot: no particle limits, file subsets or zoom selections. All producer ranks must see the shared output path, which must not contain {rank}. For parallel mesh-only construction:

pointcloud_voronoi:
  mesh_cache_layout: global
  mesh_cache_mode: save
  mesh_save_path: /shared/cache/tng-global.bin
  exit_after_mesh_write: true

Choose enough local_domain_pad to certify every owned cell. Ranks write certified owned rows to .part0, .part1, etc.; rank zero streams these into the final file, validates coverage and checksums, and publishes it atomically.

For the subsequent transport run, with any number of ranks:

pointcloud_voronoi:
  mesh_cache_layout: global
  mesh_cache_mode: load
  mesh_load_path: /shared/cache/tng-global.bin

Keep the same snapshot, floating-point precision, periodic box and construction settings. The reader validates coordinates and remaps rows, allowing different producer rank counts, padding and Hilbert ordering. Snapshot identity includes ordered file paths and particle counts, so moving the inputs invalidates the cache. Use an I64 consumer build when the full snapshot exceeds the I32 range.

Parts remain on disk. To retry failed finalization without rebuilding, run one process with all parts from the same construction:

thor --finalize-mesh-cache /shared/cache/tng-global.bin /shared/cache/tng-global.bin.part*

Missing, duplicate, corrupt or mixed-generation parts are rejected without replacing an existing final file. Local .rankN caches cannot be used as parts. Delete parts only after successful finalization; allow space for both copies.

For N global cells, finalization needs a bitmap of about N/8 bytes plus stream buffers. Import uses two passes and writes directly into the final graph. A single rank needs an 8N-byte inverse permutation, and the full transport dataset and graph must fit in its memory.

With several ranks, each rank imports only the rows of the cells in its padded domain, at 16 bytes of lookup per local cell. A row whose neighbours are not all held by the rank keeps the ones it has and is left uncertified, so transport hands photons in that cell to its owner, as for ghost cells of a locally built mesh. Owned cells still need every neighbour, so the rank count and local_domain_pad must certify them as for construction. When the cache has an index, each rank reads only the blocks that meet its padded domain, including periodic images, and checks their checksums. Without an index, every rank reads and checks the whole file and THOR warns. A failure on any rank stops all ranks.

Block index

Export writes <cache>.index with spatial bounds and checksums for blocks of 65,536 rows, allowing readers to load selected regions. Finalization preserves an index only when all parts have one.

To index an older cache, use a config for the same snapshot:

thor --index-mesh-cache /shared/cache/tng-global.bin config.yaml

Run in one process. The command checks the snapshot coordinates and writes the index without starting a driver. It loads coordinates and any required MaxDist, including from a field cache; fields: all still loads every field. Memory includes the snapshot coordinates and an 8N-byte inverse permutation for N cells.

Independent parts

A global cache can also be built one domain at a time, by separate one-process jobs that need not run together. Each job sets the same mesh_part_count, its own mesh_part_index, and the shared mesh_save_path:

pointcloud_voronoi:
  local_domain_pad: 0.02
  mesh_cache_layout: global
  mesh_cache_mode: save
  mesh_save_path: /shared/cache/tng-global.bin
  exit_after_mesh_write: true
  mesh_part_count: 24
  mesh_part_index: 7

The box is divided exactly as for a 24-rank run. The job reads the snapshot with gadget.loading_mode: 0, keeps the particles in its padded domain, certifies its owned cells and writes .part7. It then exits without finalizing. Once every part exists, merge them in one process with thor --finalize-mesh-cache, as above.

Parts of one decomposition share a generation derived from the cache key and part count, so a part that failed certification can be rebuilt with a larger local_domain_pad and merged with the others. Parts from a different part count are rejected. With automatic ghost_thickness, each part estimates the periodic shell from its own particles; certification still proves every owned cell. Memory per part matches one rank of the equivalent MPI run.

Local cache compatibility

Local caches require matching numeric widths, point count, interpolator, boundary type, construction settings and ordered particle positions. Current payload version 4 rejects older caches; auto rebuilds them and load fails.

Compatibility uses effective construction settings:

  • Hilbert sorting and the rank's padded domain are checked. hilbert_bits matters only when sorting is enabled.
  • Backend, applicable fallback, face filtering, CUBE clipping and ghost-shell settings are checked where they affect construction. Auto ghost sizing also tracks whether radii are available, including from a warm field cache.
  • Validation, threading and CGAL lock settings do not invalidate a cache.

Radius values and auxiliary-file contents are not fingerprinted. Rebuild if changes to those inputs affect auto ghost sizing, even when positions match.

Generated filenames include mesh size, precision, construction digest and _rankN.bin. Explicit paths substitute {rank} when present; otherwise MPI runs append .rankN. Single-rank explicit paths are used as given.

Row order and the identity column

Local mesh rows follow filtering and Hilbert ordering, not snapshot order. Use the optional ids column to map back:

id_kind Identity
2 (PARTICLE_IDS) Gadget ParticleIDs, when available.
1 (SNAPSHOT_INDEX) Row ordinal in the concatenated full Gadget snapshot before particle filtering.
0 (NONE) No IDs: disabled or unavailable.

Snapshot ordinals are omitted for file subsets without usable ParticleIDs. Inspect local caches with thor-tools common mesh-cache info or Python's thor.common.mesh_cache.MeshCache. For a ParticleIDs cache:

import numpy as np
from thor.common.mesh_cache import MeshCache

mesh = MeshCache("voronoi_mesh.bin")
snap_ids = ...  # ParticleIDs in concatenated snapshot order
order = np.argsort(snap_ids)
row_to_snap = order[np.searchsorted(snap_ids, mesh.ids, sorter=order)]

Producing a mesh only

Set mesh_cache_mode: save, an output path, and exit_after_mesh_write: true. THOR writes the cache and shuts down cleanly before transport, including MPI finalization. For global layout, use the producer example above.

SYCL Voronoi (experimental)

voronoi_backend: sycl uses the Ray et al. 2018 algorithm: cells clip against nearest neighbors until a security-radius test closes them, with larger candidate sets on retry. Compare against CGAL on the target dataset before production use.

Unresolved rows use fallback_backend. CGAL builds a full reference mesh and replaces those rows; Voro++ computes only the requested rows. With none, unresolved cells retain best-effort SYCL output, which may contain extra neighbors. Failures requiring a whole-mesh fallback instead stop the run.

The deprecated use_sycl_voronoi and use_cgal_fallback booleans remain accepted with warnings; explicit backend names take precedence. CUBE clipping and final topology checks still apply. Normal SYCL construction uses wall sentinels or periodic wrapping; CGAL fallback may require ghosts. The diagnostic VORONOI_PBC_GHOST switch is also part of cache compatibility when active.

For nonperiodic SYCL construction with CUBE_OLD boundaries, select the optional linear octree for the first K=128 neighbor pass:

construction:
  voronoi_backend: sycl
  sycl_knn: linear_octree
  sycl_tree_leaf_capacity: 32

sycl_knn defaults to unigrid. Both choices use the existing unigrid retry tiers and configured fallback backend. The tree adds a host-built spatial index; it does not eliminate the grid build, and is not guaranteed to improve total construction time. Leaf capacity must be a positive integer. Coincident points can share a leaf larger than this limit at maximum tree depth.

The standalone spatial::LinearOctree API supports CPU and SYCL K-nearest queries for K=1 through 128. Results are ordered by the computed floating-point squared distance, with stable source IDs breaking ties. This is rounded-distance ordering, not exact geometric ordering. The owner must outlive every kernel using its non-owning view(). Periodic and radius queries are not provided.