Skip to content

StanleyNeoh/particle-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Particle Sim

This is adapted from an assignment from NUS CS3210 (Parallel Computing). The objective is to simulate the motion of particles in a 2D space, taking into account collisions between particles and the boundaries of the space with OpenMP.

Particle Sim is a simple particle simulation program that demonstrates basic physics principles such as gravity, collision detection, and motion. It is designed for educational purposes and can be used to visualize how particles interact in a 2D space.

Examples

1k particles

long_random70.mp4

10k particles high density

10k_density_0.7.mp4

100k particles

100k_density_0.8.mp4

Input

The program accepts a text file as input, which specifies the initial conditions of the particles. The input file should be formatted as follows:

  1. N – Number of particles in the simulation
  2. L – Size of the square (in units)
  3. r – Radius of the particle (in units)
  4. S – Number of timesteps to run the simulation for
  5. For each particle, the following space-delimited information will be present on one line:
    • i – the index of the particle from 0 to N − 1
    • x – initial position of particle index i on x axis (in units)
    • y – initial position of particle index i on y axis (in units)
    • vx – initial velocity on the x axis of particle i (in units per timestep)
    • vy – initial velocity on the y axis of particle i (in units per timestep)

Example Input File

4
13
1
25
0 3 5 -1 0
1 5.05 5 0 0
2 7.1 5 0 0
3 9.15 5 0 0

Running the Simulation

To run the simulation, compile the code using a C++ compiler with OpenMP support and execute the resulting binary with the input file as an argument:

  1. First run make to compile the program.
  2. Then run the simulation with the command:
./sim <input_file> <num_threads>

Where <input_file> is the path to your input file and <num_threads> is the number of threads to use for parallel processing. For example:

./sim tests/correctness/patterns.in 1

This will create a positions.out file containing the positions of the particles at each timestep.

Creating video from output

To visualize the simulation, you can create a video from the output file using the provided Python script

./scripts/viz.py <input_file> positions.out

Where <input_file> is the same input file used for the simulation, positions.out is the output file generated by the simulation. This creates a simulation.mp4 video file showing the particle movements.

About

A particle sim powered by openmp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages