Wolfram Function Repository
Instantuse addon functions for the Wolfram Language
Function Repository Resource:
Simulate hard spheres moving in an Ndimensional box with reflecting boundary conditions
ResourceFunction["HardSphereSimulation"][pos,vel,boxsize,stepsize,rad,steps] simulates a hard sphere gas comprised of identical particles of radius rad in a cube of side length 2boxsize, starting at the initial positions pos and corresponding initial velocities vel, for the given number of steps with each particle moving at stepsize times its velocity. 
Simulate five steps of a single circular particle starting at the origin with velocity {4.0,0.2}:
In[1]:= 

Out[1]= 

Plot the position at each time:
In[2]:= 

Out[2]= 

Use HardSphereSimulation to visualize the evolution of a single hard sphere in a box:
In[3]:= 

Out[3]= 

Use HardSphereSimulation to visualize many hard spheres moving in a box:
In[4]:= 

Out[8]= 

Derive causal graph from list of collisions:
In[9]:= 

In[10]:= 

Out[10]= 

Total kinetic energy of spheres should be conserved in time:
In[11]:= 

In[12]:= 

Out[12]= 

Use HardSphereSimulation to simulate simplified pool:
In[13]:= 

In[14]:= 

Out[14]= 

This work is licensed under a Creative Commons Attribution 4.0 International License