Welcome, Guest. Please Login.
Gravity Simulator
11/18/17 at 00:34:05
News: Registration for new users has been disabled to discourage spam. If you would like to join the forum please send me an email with your desired screen name to tony at gravitysimulator dot com.
Home Help Search Login


Pages: 1
Send Topic Print
How accurate is Gravity Simulator? (Read 9555 times)
FedericoP
Uploader



I Love YaBB 2!

Posts: 12
How accurate is Gravity Simulator?
05/30/11 at 06:05:28
 
I am a student in Astrophysics (Bologna University, Italy)  and i want to know how accurate is Gravity Simulator.
 
In detail, i want to know what is the numerical method (hermite, runge kutta 4th, sympletic....) used by that program  Smiley  .
 
It's important because i'm writing my thesis and i must write a N-body code, that resolve, for example, this kind of problem:
 
http://www.princeton.edu/~rvdb/JAVA/astro/galaxy/DustDisk.html
 
http://astro.u-strasbg.fr/~koppen/body/SaturnRing.html
 
Someone know if there is yet a routine to do this in gravity simulator ?
 
Thanks everybody.
Back to top
 
 
View Profile   IP Logged
Tony
YaBB Administrator
*****




Posts: 1049
Gender: male
Re: How accurate is Gravity Simulator?
Reply #1 - 05/30/11 at 12:57:46
 
Hi Federico,
Gravity Simulator 2.0 uses the Euler-Cromer.  The latest beta version introduces a 4th order Runge Kutta method.  You can choose between EC and RK4.  They both have their strengths and weaknesses.  During the next few days, I'm going to be working on an analysis that compares the two methods.  You are also free to write your own methods and introduce them through a dll.
 
Gravity Simulator can do the types of simulations you've linked to, but its best to keep the number of particles to about 500 or less, or the program becomes very sluggish.
 
See here for the latest beta version:
http://www.orbitsimulator.com/cgi-bin/yabb/YaBB.pl?num=1176774875/36#36
Back to top
 
 
Email View Profile WWW   IP Logged
guyy
Uploader



Warning: Often
Incomprehensible

Posts: 18
Re: How accurate is Gravity Simulator?
Reply #2 - 05/30/11 at 14:08:06
 
RK4 generally works better than Euler; it takes about 4 times as much calculation per step, but increases accuracy by a much larger factor, so you can use larger timesteps without losing accuracy (that's why it's the default in my own program Tongue). Euler is better when you need a simpler method, or if you want to do a quicker "test run" of a simulation.
 
Euler's method can actually be a bit misleading, as high timesteps can ruin accuracy but won't necessarily break orbits; they'll just become elliptical and precess rapidly instead. You can see this in galilean.gsim, for example, if you set the timestep to 2048+ seconds; the moons stay in orbit, but their orbits change in unrealistic ways, and they become stable again if you reduce the timestep. This isn't necessarily a bad thing, but if you want very good accuracy, it's something to watch out for.
Back to top
 
 
Email View Profile   IP Logged
Tony
YaBB Administrator
*****




Posts: 1049
Gender: male
Re: How accurate is Gravity Simulator?
Reply #3 - 05/30/11 at 14:33:38
 
In the tests I'm running, I seem to verify the statement that a 4th order routine has only 1/16 the error when you cut the time step in half, while a 1st order routine has only half the error.  But doesn't the inverse also make sense:  double the time step and the 4th order routine has 16x the error while the 1st order routine has 2x the error?  If so, it would seem to me that there is a specific time step at which the two routines are equal.  Time steps greater than this specific value favor 1st order, and time steps less than this specific value favor 4th order routines.  Since you've coded RK4 before, can you take a look at the source code I posted on the 'beta' thread and see if logic is good?  Thanks!
Back to top
 
 
Email View Profile WWW   IP Logged
frankuitaalst
Ultimate Member
*****


Great site

Posts: 1507
Gender: male
Re: How accurate is Gravity Simulator?
Reply #4 - 05/30/11 at 14:41:01
 
AFAIR one important feature of the Euler method is that it conserves time reversal results , which may be unique vs other routines such as RK.  
What I mean is , if you run 1000 hours forward and then 1000 hours backwards you should end up at the same position using Euler .  
This isn't the case with other routines.
Back to top
 
 
Email View Profile   IP Logged
FedericoP
Uploader



I Love YaBB 2!

Posts: 12
Re: How accurate is Gravity Simulator?
Reply #5 - 05/30/11 at 16:16:13
 
thanks for your answer.
 
Could you tell me, please, how to choose the method of integration and how to change or to edit it.  Huh
 
I am also interesting about how to graph data files that revenue, because these files are txt and charts, which I saw in the various threads are made with xls:
 
1) run the simulation;
2) file->output file/systemic output file;
3) a file.txt.
4) how can i get a file.xls ?  Shocked
 
And finally wanted to know if you can make simulations similar to the two that I posted on this page.  embarrassed
 
Thank you very much for your help. greetings.
 
 
 
 
 
 
 
Back to top
 
 
View Profile   IP Logged
Tony
YaBB Administrator
*****




Posts: 1049
Gender: male
Re: How accurate is Gravity Simulator?
Reply #6 - 05/30/11 at 17:23:15
 
First, download this file into your Gravity Simulator folder.  Then use it instead of gravitysimulator.exe
http://orbitsimulator.com/gravity/beta/GravitySimulatorBeta2011May30.exe  
 
This is the beta version that lets you choose between Euler-Cromer and Runge Kutta 4.  In the beta menu just choose which integrator you want.
 
If you want to edit it, you can either:  1) send me your changes and I'll do it for you, or 2) do it in C++, compile it into a dll named codepotomizer.dll, then replace the existing codeoptomizer.dll in your gravitysimulator folder, then finally, download the most recent beta version not counting 2011May30.  Then it will use your C++ code instead.
 
To output data:  
First, create a simulation and save it.  It is recommended that you save it in its own folder.
 
File > Output File (don't choose systemic).  Check the "Create Data File" box and the "Create Data File Copy" boxes.  It then creates 2 files.  The difference is that you can play around with the copy while the simulation is running.  For example, if you open the data file in Excel, then Gravity Simulator can not write to the file.  The original copy cares about this, while the copy does not.  The copy won't update again until you close it in Excel, then it will copy the original version so they're identical again.  Then choose how often you want the data to be written to the files, and the maximum number of data samples.  Then choose for which objects, and finally choose what orbital elements you want written to the data file.
 
The files are created in the same folder as your .gsim simulation file.  They have the same name as your .gsim file, except the extension is .txt.  In Excel, choose file type txt and browse to the file.  Choose deliminated, and choose the comma as your delimiter.  Then it should open for you.  If you want .xls, you can save it in Excel with file type xls.
 
Here are step-by-step instructions for creating the first simulation you linked to:
 
Open Gravity Simulator and pause the simulation
Open "fullsystem.gsim" which is in your "simulations" folder.
Objects > Delete
Delete all unwanted objects.  Your article talks about the "14 main bodies".  From their list I would delete Haley's comet as one of the 14 main bodies.  You might also want to exclude  Sedna, Eris and Pluto.  If not, you might as well keep Ceres, Pallas, Vesta, and Juno, as they're more significant as Sedna.
 
Save your simulation.  Create a new folder for it and give it a name.
 
The link you provide uses 2000 massless test particles.  I'd suggest starting out with 200 until you are comfortable with creating simulations.  Besides, 200 should be fine to show you their general distribution after a given time since they are massless and don't interact with each other.  It says they are in circular orbits with inclinations distributed between 0 and 5 degrees.  The article doesn't mention how they're distributed in distance. But looking at their animation, there don't seem to be any interior to Earth's orbit, and they seem to stretch out to Neptune.  So let's just assume that they're evenly distributed between 1 and 30 AU.
 
Objects > Create Objects
Number of objects: 200
Semi-major axis:  First hit the distribution button until the words "Start, End" appear under SMA.  Make sure that AU is selected as your unit of distance.  Enter 1,30
Inclination:  Choose 2.5 degrees +/- 100%
Make sure the reference object is the Sun.
Give them a name such as "Asteroids"
Press Create
Under menu > Preferences, set the "Do Events" to 5 so your program doesn't seem non-responsive due the high number of objects.  Also set the Graphics Updates to 50 to speed things up.
Save the simulation.  Give it a different name than before in case you need to start over.
Unpause and watch.
 
To hold Jupiter still like they have in your article, use menu View > Rotating Frame Adjustment.  Choose Jupiter.  This gives you approximately the right period for the rotating frame.  Experiment to come up with a better value.  Hit "Calibrate" and click on Jupiter.  Return a few minutes later and click on Jupiter again.  Gravity Simulator will then compensate for Jupiter's drift.
 
To make the asteroids appear different colors depending on whether they're above or below the ecliptic, menu Objects > Edit Objects.  Select each asteroid and put an asterick after its name and hit "Apply".  I don't have an automated way to do this, sorry, so you'll just have to spend a few minutes and do them one at a time.  Any object with * as the last character of its name appears red when below the ecliptic.
 
One more change I would make is to use Earth Barycenter rather than the Earth and the Moon.  With the Moon orbiting the Earth, this sets the maximum step size you can use, preventing you from taking huge time steps like the 3 days they use in your link.  Even so, I'd keep the time step to 16K seconds or less.
 
Following my above instructions, I just made one for you.  You can get it here:
http://orbitsimulator.com/gravity/simulations/frederico.gsim
 
At a timestep of 16384, it does about 6 years per minute, or about 27 hours to do 10000 years, so you'll want to run this thing over night, save it, and run it again the next night or any time your computer is free.  You can speed things up a bit by pressing the P button on the Graphics Options interface.  This disables the graphing.
 
 
Back to top
 
 
Email View Profile WWW   IP Logged
guyy
Uploader



Warning: Often
Incomprehensible

Posts: 18
Re: How accurate is Gravity Simulator?
Reply #7 - 05/30/11 at 20:56:51
 
Quote from Tony on 05/30/11 at 14:33:38:
In the tests I'm running, I seem to verify the statement that a 4th order routine has only 1/16 the error when you cut the time step in half, while a 1st order routine has only half the error.  But doesn't the inverse also make sense:  double the time step and the 4th order routine has 16x the error while the 1st order routine has 2x the error?  If so, it would seem to me that there is a specific time step at which the two routines are equal.  Time steps greater than this specific value favor 1st order, and time steps less than this specific value favor 4th order routines.  Since you've coded RK4 before, can you take a look at the source code I posted on the 'beta' thread and see if logic is good?  Thanks!

 
It's possible that's true, though I doubt it's really so simple and linear like that; I haven't done any really exhaustive tests. But the two routines behave very differently; from a quick test just now, a 2-body system stays perfectly static (orbital elements don't change significantly) in RK4 up to about 8 minutes per step, while with Euler you have to go down to 0.0625 seconds per step (128 times smaller) to get about the same result. If the errors go up by about 16x/2x, Euler should have about 32x as much error at one-fourth of RK4's timestep (where it runs as fast as RK4), and they should have the same error if you increase their timesteps 4 times (8x higher error in RK4 compared to Euler each time).
 
The problem is...at that timestep (~2 hours for RK4, one-fourth that for Euler), neither of them really work. In RK4, the orbit quickly collapses, and in Euler it warps and precesses a huge amount. The latter is actually worse, I think, because it's hard to notice in multi-body systems (is the orbit precessing because of error, or because of other objects interacting with it?). So...it's possible there's a special timestep like that, but it seems like it's so high that neither method can really handle it, and because Euler loses so much less error as you decrease the timestep, RK4 takes the lead pretty quickly.
 
I haven't done anything with my RK4 code in years, so I don't really know how to read yours. Tongue Though I think errors in the code usually mess up simulation enough that it's hard not to notice, so if it seems to work, it probably does.
Back to top
 
 
Email View Profile   IP Logged
Tony
YaBB Administrator
*****




Posts: 1049
Gender: male
Re: How accurate is Gravity Simulator?
Reply #8 - 05/30/11 at 21:22:42
 
Quote from guyy on 05/30/11 at 20:56:51:
Though I think errors in the code usually mess up simulation enough that it's hard not to notice, so if it seems to work, it probably does.

It definitely seems to work.  RK4 allows an object in a circular low Earth orbit to orbit for months (maybe longer) without deviating from a perfectly-circular orbit by even 1 meter at time steps as high as 16 seconds.  At a time step of 1 second, EC deviates by about 300 meters high or low from a perfectly circular orbit.  However, it can maintain this indefinitely without the error growing.  So this gives me confidence that I coded the RK4 properly.
 
But during longer simulations with larger time steps, EC seems to be the winner.  I downloaded JPL elements for the solar system from yesterday's date, including the asteroid Apophis.  Using EC, I propagated the system forward until April 13, 2029, the date that Apophis will pass within 30,000 km of Earth.  Then I compared my results with JPL's predictions.  EC's Apophis was 10,000 km away from JPL's predection with a time step of 128 seconds.  As I recall from trying this previously, with time steps as low as 1 second, EC is only about 200km from JPL's prediction.  When I tried this in RK, I needed to increase the time step to 1024 seconds so RK, with its longer code, would complete the mission in the same amount of real time.  When Apophis arrived, it was over 1 million km from JPL's predicted position, and Earth's moon had its eccentricity pumped up to over 0.2.  I'm in the process of doing a much slower RK run at a time step of 16 seconds, but it will take 27 hours to complete.  Perhaps by tommorow night I'll have an answer.  But unless I made a mistake coding, it seems that EC is more robust for solar system simulations.  Soon I'll write up a summary of all my testing.
 
Quote:
from a quick test just now, a 2-body system stays perfectly static (orbital elements don't change significantly) in RK4 up to about 8 minutes per step, while with Euler you have to go down to 0.0625 seconds per step (128 times smaller) to get about the same result.

I think it depends on the size of the system.  In a 2-body system containing the center of the galaxy and the sun, much larger time steps can be taken than with the Moon orbiting the Earth.  I think it has more to do with how many steps it takes to complete a full orbit.
Back to top
 
 
Email View Profile WWW   IP Logged
guyy
Uploader



Warning: Often
Incomprehensible

Posts: 18
Re: How accurate is Gravity Simulator?
Reply #9 - 05/30/11 at 22:31:35
 
Quote from Tony on 05/30/11 at 21:22:42:
Quote:
from a quick test just now, a 2-body system stays perfectly static (orbital elements don't change significantly) in RK4 up to about 8 minutes per step, while with Euler you have to go down to 0.0625 seconds per step (128 times smaller) to get about the same result.

I think it depends on the size of the system.  In a 2-body system containing the center of the galaxy and the sun, much larger time steps can be taken than with the Moon orbiting the Earth.  I think it has more to do with how many steps it takes to complete a full orbit.

 
Yes, but the steps to finish an orbit should scale with the timestep, so I don't think that matters. (If that weren't true, you could scale all the masses/orbit distances/other constants down and make RK4 suddenly work better with the system effectively the same, which wouldn't really make sense.)
 
As for the accuracy, I'm not so sure. I mainly used planetary transit times when I was debugging RK4 (not incredibly precise, but it helps test against reality); from a test I just did in Pixel Gravity using RK4 and a timestep of 1024 sec, Mercury's transit on May 7th, 2003 (simulated from 1/1/2001) happened at 5:07, 6 minutes before the recorded time (and even closer once you add on ~8 minutes of light travel time). Using Euler and a timestep of 256 sec (lower because of ~4x extra computation in RK4), I got a time of 5:56, 43 minutes too late (and even worse corrected for light-time). A 128 sec Euler timestep isn't much better (5:32), and takes longer than RK4 does at 1024 sec. RK4, on the other hand, didn't have any significant change to its transit time until I set the timestep above 32768.
 
That could be a fluke, of course, but I've done similar tests (with different transits) in the past and got similar results. I'm not sure why you needed to go all the way up from 128->1024 to run RK4 as fast as Euler, since it should only take 4 times as much computation, but even with an 8x timestep difference (or more) RK4 seems a lot more accurate. I think either there's a bug somewhere, or something's wrong with one of these testing methods...
Back to top
 
 
Email View Profile   IP Logged
FedericoP
Uploader



I Love YaBB 2!

Posts: 12
Re: How accurate is Gravity Simulator?
Reply #10 - 05/31/11 at 10:26:31
 
thank to everybody !!!!  Grin
 
I "created" my simulation and I observed some very interesting results:
 
1) the scattering theory (or slingshot effect) is confirmed by simulation: the internal objects give energy to the outer spiraling toward the center of the system while the outermost buy energy and spiraling out, this is the phenomenon of in-outward migration.  Cool
 
http://astro.u-strasbg.fr/~/body/SaturnRing.html
 
2) I also noted the phenomenon of precession of the outer objects which I do not expect it at all.  Shocked
This is very interesting and deserves some explanation.
 
3) I would add the number of collisions of objects because I think that, you can solve the inconvenienceof the explosion of the inner system.
 
I give by email my result (because i can't link it here  cry ) , open to any questions, improvement  Roll Eyes  Wink or clarification.
Back to top
 
 
View Profile   IP Logged
Tony
YaBB Administrator
*****




Posts: 1049
Gender: male
Re: How accurate is Gravity Simulator?
Reply #11 - 05/31/11 at 11:37:20
 
I will link it for you:
http://orbitsimulator.com/gravity/simulations/fredericoNew.gsim
In the future you should be able to upload files (It now says uploader).
 
Your internal objects have no energy to give away.  They are massless.  Only the planet in your simulation can affect the orbits of the massless particles.  They can not interact with themselves.
 
Objects can precess when the time step is set too high.  Cut the time step in half and see if they still precess.  That's how you can differentiate between numerical error and actual precession.
 
Not bad for a 1st attempt!
Back to top
 
 
Email View Profile WWW   IP Logged
Tony
YaBB Administrator
*****




Posts: 1049
Gender: male
Re: How accurate is Gravity Simulator?
Reply #12 - 05/31/11 at 15:19:43
 
Quote from guyy on 05/30/11 at 22:31:35:
...I think either there's a bug somewhere, or something's wrong with one of these testing methods...

You're right.  I had some plus signs where I should have had minus signs in the code.  I'm testing it now and it's passing the Apophis test with flying colors.  I'll release a new beta when I'm finished.  In the meantime, don't use my RK4!
Back to top
 
 
Email View Profile WWW   IP Logged
EDG
Ultimate Member
*****


oh, crumbs!!!

Posts: 611
Gender: male
Re: How accurate is Gravity Simulator?
Reply #13 - 06/02/11 at 03:05:40
 
Oh sweet! New toys to play with! Smiley (when I have time...)
Back to top
 
 

(formerly known as Mal)
View Profile WWW   IP Logged
Pages: 1
Send Topic Print