8.4. pyafv.ParallelFiniteVoronoiSimulator
- class ParallelFiniteVoronoiSimulator(pts, phys, grid_shape=(2, 2), n_workers=None, *, halo_width=None, backend=None, domain_bounds=None, decomposition_method='dense')[source]
Python multiprocessing domain-decomposed simulator for the AFV model.
This class decomposes the full point set into rectangular domains with halo regions, then composes
FiniteVoronoiSimulatoron each local subdomain. The returned diagnostics are merged back into global cell indexing for owned cells. Whenn_workers > 1, local subdomain builds use Python worker processes.- Parameters:
pts (ndarray) – (N,2) array of initial cell center positions.
phys (PhysicalParams) – Physical parameters used within this simulator.
grid_shape (tuple[int, int]) – Number of domains in the x and y directions.
n_workers (int | None) – Number of worker processes. If None, use
os.cpu_count().halo_width (float | None) – Width of the halo region added to each domain. If None, use
4.01 * phys.r.backend (Literal['cython', 'python'] | None) – Optional, specify “python” to force the use of the pure Python fallback implementation inside each local finite Voronoi simulator. Otherwise, the “cython” backend is used.
domain_bounds (tuple[tuple[float, float], tuple[float, float]] | None) – Optional domain bounds as
((xmin, xmax), (ymin, ymax)). If None, bounds are inferred from the current point positions.decomposition_method (Literal['dense', 'binned', 'sorted_x']) – Method used to collect halo points.
"dense"is usually faster for moderate systems."binned"can be faster for many domains."sorted_x"uses less temporary memory.
- Raises:
ValueError – If pts does not have shape (N,2).
ValueError – If grid_shape, halo_width, domain_bounds, or decomposition_method is invalid.
TypeError – If phys is not an instance of
PhysicalParams.
Note
For repeated calls with
n_workers > 1, put the loop inside the context manager so worker processes are created once and reused across build steps:with sim: # sim is an instance of ParallelFiniteVoronoiSimulator for step in range(num_steps): diag = sim.build()
Attributes
Return a copy of the preferred area array.
Methods
build([connect, plot_mode])Build local finite Voronoi structures and merge global diagnostics.
update_params(phys)Update physical parameters.
update_positions(pts[, A0])Update cell center positions.
Update the preferred areas for all cells.