Skip to content

Sombrero is my A-Level Computer Science project focusing on the simulation of the N-Body Problem

Notifications You must be signed in to change notification settings

tvarnish/sombrero

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sombrero is a simple n-body simulator, written in C++, which enables users to simulate gravitational interactions between massive, spherical, rigid bodies. Sombrero is a command line tool, that generates a .mp4 video of the simulation, given an initialisation file containing the initial states of the bodies. It was originally written for my, A-Level Computer Science project and has been expanded since.

Sombrero is currently under development, and is not in a finished state!

Currently, Sombrero is capable of:

  • Simulating gravitational interactions between non-rotating spherical bodies.
  • Simulating collisions between bodies.
    • Right now, bodies can only merge upon impact, not split apart.
    • Whenever two bodies "collide", they will merge, regardless of impact speed.

Getting Started

These instructions will get a copy of the project running on your local machine, for development and testing purposes.

A make install command has not yet been implemented. The make setup command should be used to set up a self-contained development environment.

Prerequisites

Before you begin, you will need to make sure you have a few things installed to run and render simulations. On a UNIX (here Ubuntu) terminal:

sudo apt-get install -y make g++

Compiling from source (Development)

To start using Sombrero, make sure you've installed the prerequisites then:

git clone https://github.com/tvarnish/sombrero.git
cd sombrero/
make setup

This will clone the repository to your local machine, create the necessary directories, and build the necessary files for running Sombrero.

Basic Usage

Having followed the setup instructions, Sombrero can be run from within the sombrero/ directory using the following command:

./sombrero

If no (or incorrect) arguments are supplied, a usage message will be displayed.

Arguments

Initialisation files are supplied as follows:

-i [filepath]

where [filepath] is the path to a valid initialisation file. See the section on initialisation files for further information about these.

Currently, simple simulation parameters can be supplied using the -s and -t flags. The -s flag specifies the number of "frames" or "time steps" that the simulation should be run for. Each "frame" or "time step" will be equivalent to -t seconds. The argument passed via the -s flag should be an integer, and the argument passed via the -t flag should be an integer or a floating point number.

Use the -h or --help flags to display usage information.

Example Simulation

An example initialisation file has been included with the repository. To run a simulation using this file, run the following command:

./sombrero -i init/realsolarsystem.csv -s 365 -t 86400

This command will simulate the inner planets of the solar system, over a period of 365 time-steps (-s), where each time step (-t) lasts 86400 seconds (1 day).

Initialisation Files

Initialisation files are comprised of a number of lines, each describing one 'body' in the simulation. Each line must be written as follows (replacing the text in the example below with a numerical value, e.g. 5 or 4.0e10, etc.):

x_position, y_position, z_position, mass, radius, x_velocity, y_velocity, z_velocity, [object name]

Here, [object name] is an optional parameter which "labels" a body with a string identifier. This can be handy for keeping track of special objects in your simulations.

So, for example, if we were to have the Sun at the centre of the simulation (currently stationary), we could write:

0,0,0,1.989e30,6.955e8,0,0,0,Sun

Comments

Comments can be written within initialisation files, using // to indicate the rest of the text on that line is a comment. For example:

0,0,0,1.989e30,6.955e8,0,0,0 // An example comment.
// Another example comment. This whole line is a comment.

It is also acceptable to place any whitespace characters (except a newline!) between each of the parameters and the commas, should you wish.

Output

The output files generated by the software, are stored as ./data/bodyData_XX.csv, where XX is the (zero-padded) "frame" number. These files follow the same structure as the initialisation files described above. However, these output files include an additional simulation-parameters line at the beginning of the file. This line is structured like so:

step_number, dt, time_elapsed, body_count

where, step_number is the number of integrations steps between this frame and the initial conditions (initialisation file). Hence, a value of 0 denotes that this file contains the initial starting conditions of the simulation. Here, dt is the time (in seconds) between subsequent integration steps (or "frames"), and time_elapsed is the total elapsed time (within the simulation, in seconds) since the start of the simulation (step_number * dt). Lastly, body_count is the number of bodies currently in the situation.

Acknowledgements

Sombrero uses cxxopts for parsing command line options.

About

Sombrero is my A-Level Computer Science project focusing on the simulation of the N-Body Problem

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published