# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Simulate hard spheres moving in an N-dimensional box with reflecting boundary conditions

Contributed by:
Matt Kafker and Christopher Wolfram

ResourceFunction["HardSphereSimulation"][ simulates a hard sphere gas comprised of identical particles of radius |

ResourceFunction["HardSphereSimulation"] returns a list of the full state of the system at each time-step, and also a list of all collisions that occur during evolution.

The output has the form {{{*p*_{1},*v*_{1}},{*p*_{2},*v*_{2}},…},*collisions*}, where the *p*_{i} are the positions and the *v*_{i} are velocities and time *i*.

Each collision takes the form {*particle*_{i},*particle*_{j},*stepofcollision*}.

The dimensions of vectors in *pos* and *vel* determine the spatial dimension of system (they can be any positive integer dimension).

The box is centered on the origin, and *boxsize* refers to half of the side length of a square.

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