Skip to content

lmarchesoti/n-body_simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

n-body simulation

Erlang n-body simulation

Documentation

This is a simulation of the n-body problem using erlang. The program spawns a thread for each 'body' and simulates the effect of gravity in ticks. This is the standard brute-force approach.

It automatically generates bodies across a bi-dimensional space bounded by user input. The output is, for each round, the mass and position of each body.

body.erl implements the body functionality of updating position according to the gravity influence of nearby bodies

gravity.erl calculates the force vector between two bodies using the formula F = G*(mass1 * mass2) / (distance^2)

sum_forces.erl gives the resulting force vector for a given body

simulation.erl implements the main simulation function.

simulation:simulation accepts four arguments: body_count, ticks, max_mass and max_dimension_size. The first parameter, body_count, is the number of bodies to be initialized. Ticks is the number of rounds the simulation will run for. Max_mass is the maximum mass for any of the generated bodies. Max_dimension_size is the boundary of the 2D space each body is inserted into.

Instructions

Compile each module with c(modulename).

Run the simulation module, for example as simulation:simulation(3, 80, 800, 800).

About

Erlang n-body simulation. Uses parallel programming in functional message-passing paradigm, spawning a light thread for each body and simulating the effect of joint pairwise gravity in ticks. It automatically generates bodies on a 2D space and outputs mass and position for each body at each tick.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages