Generating True Random Close Packing is fundamentally more complex than simple random placement. At low densities, "place and reject" (Monte Carlo) methods are sufficient. However, as the system approaches the jamming limit (volume fraction
To generate dense packings, the system must evolve toward a jammed state using either optimization methods or dynamical simulations.
rcpgenerator is an open-source Python library developed to generate dense, jammed packings of non-overlapping spheres. Unlike simple rejection-sampling methods that fail at high volume fractions, this toolkit uses an optimization-based "inflation" approach to reach the Random Close Packing (RCP) limit (
- GitHub Repository: rcpgenerator: Fast Spehere Packing Generating
- Key Features: Support for polydisperse distributions, custom container geometries (box, cylinder, sphere), and higher dimensions (tested up to 7).
- Run in Colab ↗
from rcpgenerator import Packing
# Initialize 200 spheres in a unit cube
p = Packing(N=200, Ndim=3, box=[1,1,1]) # See colab getting_started for more examples and settings
# Evolve the system toward a jammed configuration
final_packing = p.pack()
# Visualize the final packing
p.show_packing() # should only take a few seconds to run
# Display Packing
p.show_packing(figsize=(4,4)) # could take 10's of seconds to runTwo common approaches are used in the literature to create such packings.
These methods allow particles to slightly overlap during the optimization process.
The idea is:
- Start from a random low-density configuration.
- Gradually increase particle diameters.
- Use an optimizer to adjust particle positions to minimize overlaps.
- Stop when overlaps fall below a small tolerance.
In well-converged packings, overlaps are typically extremely small (often ~10⁻³ of the particle diameter or less).
The position updates can follow either:
- physics-inspired force updates, or
- purely mathematical optimization methods.
Another class of algorithms simulates true hard spheres colliding like billiard balls.
In these algorithms:
- A gas of spheres starts at low density with high kinetic energy
- Particle diameters are slowly increased
- Energy is gradually removed from the system
- The system evolves through collisions until particles become jammed
These methods follow physically realistic particle dynamics and have been widely used to study hard-sphere systems.
These methods primarily use energy minimization, force-biased algorithms, or geometric inflation. They are often highly efficient for reaching static jammed states but may skip the intermediate physics of a settling system.
| Package | Functionality | Language | Specialization | Difficulty | Link |
|---|---|---|---|---|---|
| RCP Gen | Fast generator for arbitrary dimensions (ND). (MATLAB version of this code) | MATLAB | Made for RCP | Easy | FileEx |
| Circle Dist | Solve charge distribution problem that creates rcp | MATLAB | Made for Packing | Easy but slow | FileEx |
| Pack-spheres | Brute-force/stochastic circle and sphere packing. | JavaScript | Configurable | Easy | GitHub |
| Pyspherepack | Quick-and-dirty gradient-based optimization using Autograd. | Python | Made for Packing | Easy | GitHub |
These use Molecular Dynamics (MD), Discrete Element Method (DEM), or event-driven simulations. They provide high epistemic stability for studying physical packing kinetics and non-spherical geometries.
| Package | Functionality | Language | Specialization | Difficulty | Link |
|---|---|---|---|---|---|
| VasiliBaranov/PackingGen | Comprehensive suite for LS, Jodrey-Tory, and Force-Biased. | C++ | Made for RCP | Moderate | GitHub |
| ParticlePack | DEM-based shaking/shuffling for spherical and irregular grains. | C# / Unity | Made for Packing & Goes Beyond Spheres to Other Shapes | High | GitHub |
| LAMMPS | Massive-scale MD for granular systems and hard-spheres. | C++ / Python | Configurable | High | Website |
| YADE | DEM simulatpr | C++ / Python | Configurable | High | Website |
| HOOMD-blue | GPU-accelerated MD/HPMC for hard particles and shapes. | Python / C++ | Configurable | Moderate | GitHub |
Physics-based updates typically involve an associated step size (typically a time step) that must remain relatively small for numerical stability, and slow dramatically for highly polydisperse packings where the largest-to-smallest particle size ratio is large. Optimization methods, on the other hand, can take larger non-physical steps toward the minimum overlap configuration and tend to be more stable in highly polydisperse cases.
Because of this, optimization approaches often reach dense packings more quickly (allowing one to generate packings of 1000+ particle in seconds to minutes), although the intermediate states do not correspond to a physically realistic trajectory. In practice, structural properties of packings generated by optimization algorithms tend to agree well with physical experiments (packing fraction, structure factor, coordination number, etc).
rcpgenerator uses an optimization-based approach (ADAM optimizer) to separate particles as they grow in size.




