Documentation

particle.py

class particle.Particle(x: float, y: float, velx: float, vely: float, radius: float)

Models real world molecules as elastic circles.

Parameters
  • x (float) – coordinate of the horizontal axis (L)

  • y (float) – coordinate of the vertical axis (L)

  • velx (float) – Velocity in the horizontal direction (L/s)

  • vely (float) – Velocity in the vertical direction (L/s)

  • radius (float) – radius of the particle (L)

coordinates

x and y coordinates of the circle (L)

Type

np.ndarray

vel

velocity of the particle (L/s)

Type

np.ndarray

r

radius (L)

Type

float

checkAndHandleWallCollision()None

Changes particle position such that it is always inside a unit rectangle.

collidesParticle(p2)bool

Checks if distance between self and p2 is less than the sum of their radiis

Parameters

p2 (Particle) – Another particle

Returns

True if self collides with p2, False otherwise

Return type

bool

run(dt: float)None

Advances particle position from current time to time+dt assuming constant velocity.

Parameters

dt (float) – time step

property velx
property vely
property x
property y

simulation.py

class simulation.Simulation(numParticles: int, radii: numpy.ndarray, outputfile: str)

Simulation class for particles in a box. Simulations are carried inside a unit rectangle.

Parameters
  • numParticles (int) – number of particles to be created

  • radii (np.ndarray) – Radius of each particle

  • outputfile (str) – name of the outputfile

particles

collection of all the particles

Type

np.ndarray

time

time in the simulation (s)

Type

float

outputfile

name of the outputfile

Type

str

results

results dataframe where the particle positions and velocities are recorded

Type

pd.DataFrame

checkAndHandleParticleCollisions()
handleParticleCollision(p1: particle.Particle, p2: particle.Particle)Tuple

Changes velocity of particles that have collided.

Parameters
Returns

First element is p1 and second p2, whose velocity has been updated following collision

Return type

Tuple

References

https://en.wikipedia.org/wiki/Elastic_collision

run(timeStart: float, timeEnd: float, dt: float)None

Advcances particles in box simulation from timeStart to timeEnd with time step dt

Parameters
  • timeStart (float) – Starting time of the simulation

  • timeEnd (float) – Ending time of the simulation

  • dt (float) – Simulation time step

updateResults(time: float)None

Appends current position and velocity of particles to results dataframe

Parameters

time (float) – Current time in the simulation. Will be included in results dataframe

writeOut()None

Saves the results to csv file. The filename is speciefied in outputfile when creating the simulation object.