Skip to content

sanyapandit/N-Body

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

N-Body: a Lightweight N-Body Simulator

This is n-body simulator I'm currently writing in C. It solves the n-body system numerically using the midpoint formula and Newton's law of universal gravitation.

How to Use

Cloning

You can clone the repository with git clone https://github.com/davidretler/N-Body.git.

Building

To build, type gcc main.c -lm -g -std=gnu99

Running

To run, ./a.out > data.csv

Output

The program will write to a .csv file that contains on each row the following data:

Planet_1_ID, pos_1, pos_2, pos_3, Planet_2_ID, pos_1, pos_2, pos_3,...

with successive rows representing different points in time. Currently I have not written a script to plot the data. I suggest viewing the data in either LibreOffice Calc or Microsoft Excel.

Planet list

If you make a file called planets which contains initial planetary data, run the program with ./a.out /path/to/planets and the program will initialize the universe with that data. Each body should have a it's own line formatted as:

NAME,POS_1,POS_2,POS_3,VEL_1,VEL_2,VEL_3,MASS

For example, to add the Earth and the Sun:

Earth,1.52e11,0,0,0,29316,0,5.972e24
Sun,0,0,0,0,0,0.0,1.988435e30

Note that the numerical value of every quantity is given in SI (MKS) units.

Features to Add

I will be attempting to add the following features:

  • Allow for custom lists of bodies [✓]
  • Script to plot output

Current Issues

  • The sun appears to be slowing drifting from the center, but only when using the midpoint algorithm (which should be more accurate)

About

An N-body simulator I wrote in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 99.7%
  • Makefile 0.3%