Skip to content

GAVLAB is a high accuracy solar simulation system with symplectic algorithm and the mesh schema

Notifications You must be signed in to change notification settings

cskksdfklpz/GAVLAB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mr.B's Gravitational Laboratory

Hello,welcome to Mr.B's Gravitational Laboratory or you can call it GAVLAB.

What can you do in GAVLAB

Please don't be confused by its name because GAVLAB is not a real laboratory. Actually it's a virtual laboratory running on computer, a program which can simulate the physical process or a system driven by gravitational force.

You can simulate any gravitational process because GAVLAB allows the users to design their own system in the universe. In this manual mode users have to set up all information of the system,including the planet's name,mass,radius,position,velocity and RGB color. It's an exhausting task!

Besides manual mode there are another two automodes for the users who are too busy to set up the system manually.

The first choice is to simulate the real solar system with eight planets in it. All data was provided by Professor Xue on the website.

The other choice is a little crazy. It's random mode. Random mode can generate any number of planets randomly in random position with random velocity and random mass and even random color. Everything is random! It means we can simulate hundreds of planets by typing several keys on the keyboard and then enjoy the universe and drink a cup of coffee. It's convenient!

How to run GAVLAB

The first step of running GAVLAB is easy:get a computer. More specifi- cally, a computer with UNIX based system such as Mac OS or Linux system. Unfortunately GAVLAB cannot run on Windows system because there are a lot of libraries missing which I will list out later.

Anyway Macintosh is the best choice. On a Mac computer all you have to do is double clicking the executable file named GAVLAB with the sun-shaped logo.

Overview of GAVLAB

GAVLAB was built in C++ language with a little Object-Oriented programing technique. It contains data abstraction,inheritance and dynamic binding.

In GAVLAB each planet is a CPlanet object and the whole solar is a CSolar object which is data abstraction.

There are several kinds of integrators in GAVLAB. Each of them is an object of class derived from CIntegrator class which is inheritance. Different integrators share the same method Update with different implementation code which is dynamic binding.

Also I used class template when I was building my math library Vector which is generic programing.

The structure of GAVLAB is MVC where I imitated from the software developing. Control class takes in charge of the whole program and interact with users in command window. Model is actually math. To make our trajectory stable and correct I used Symplectic Integrator with two order,four order and six order. They can be notated as SI2,SI4 and SI6. View method makes GAVLAB visual with OpenGL which is an open graphics API.

MVC

MVC is Model View and Controller. Model for GAVLAB here is just simulating the gravitational process. View is to let the users see the result of the program. And Controller is the commander which takes the command of users and tells the program what to do.

In GAVLAB there will be a loop. At the beginning of each loop the Controller will get the command of the users such as starting simulation or pause. Then it parses the command and execute the command.

After that the model will simulate the physics process according the integrator and update the state.

Finally View is responsible for making the animation according the data generated by model.

Quick description of Symplectic Integrator

As we know almost all GAVLAB has to do is simulating. Because the real physics world is driven by differential equation such as Newton’s Law or Hamiltonian equation, GAVLAB has to integrate those equations to get the solution. So we need a good integrator.

There’s something different between computer simulation and real world’s physical process. In computer we can only solve difference equations rather than differential equations because computers can only deal with decrete math. So instead of calculating infinitesimal step time we have to calculate the new state of the system after some pretty small but finite time step τ.Then if τ is too large it will lose accuracy.

There’re some good integrators such as Euler method or Runge-Kutta method. However those methods are not suitable in GAVLAB cause we want our trajectory stable. It’s easy to know that the deviation of energy will increase as time goes through using Euler or Runge-Kutta method which means the radius of planet’s trajectory will decrease slowly and finally move to sun.

So in GAVLAB I used Symplectic Integrating method which is able to maintain the symplectic proporty of the planet’s canonical coordinate and canonical momentum .

SI2

Actually SI2 is just Leap Frog algorithm.

here

And here's the how SI2 works.

As you can see SI2(LeapFrog method) is not pretty stable for trajectory. The energy of planet will decrease as time goes by and finally fall into sun. So we have to increase the order of integration to get more precise solution.

SI4

The formula of SI4 was derived by Neri in 1987 and the difference equation is

and the coefficient is

So it's clearly that SI4 can handle the gravitational system simulation. The trajectory of mercury venus and earth can maintain perfect ellipse after long time.

SI6

The formula of SI6 was derived by Yoshida in 1990 and the difference equation is

here the coefficient is

Detail of the algorithm above is provided in my blog MR. B’S HIDING PLACE

How to simulate thousands of planets or more

(This hasn't been done yet)

About

GAVLAB is a high accuracy solar simulation system with symplectic algorithm and the mesh schema

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published