I am trying to understand how to calculate the orbits of solar system bodies in an n-body framework, based on the pair-wise gravitational interaction between the objects. At present, I am considering 44 objects (sun, planets, major moons and major asteroids).
I am starting with the state vectors (position and velocity) of each of the objects with Sun as centre obtained from telnet ssd.jpl.nasa.gov 6775
(JPL Horizons) 01-Jan-2017 at 00:00 UTC and would like to let the system evolve for 4344h, 01-July-2017 at 00:00h.
I have written a program to do this in Java, and so far the results do not seem to be even reasonably close to what they should be, comparing with the state vectors obtained from Horizons. After every 2 second time step the net gravitational forces on each body from all of the others is calculated, and then in one shot all the velocities and positions are updated based on the accelerations from those net forces. Then I compare the final updated position vectors from the application with data obtained from Horizons after correcting for the Sun's updated position.
The comparison shows that the positions of Earth and the outer planets are have position error of less than 50km (In fact, the farther planets it is less then 10km). Where as for Mercury the error is 250km. And the moons of Jupiter and Saturn are off by 50,000 to 300,000 km!
In my application, I am not differentiating between the Sun, planets and moons, so I am not sure why there should be so much more error for the moons. I have tried decreasing the step size, from 2 seconds down to 0.25 seconds, but there is not significant improvement.
What might be the problems that I should investigate here? Are there things that clearly need improvement right away? Or perhaps there are tests I can to do help diagagnose the primary sources of error?
EDIT: Here is the gist of the calculation method as requested in comments:
while (nowT < endT) {
doOneStep(step, nowT)
nowT += stepT
}
allItemLinks
is collections of ItemLink
- links between objects. in this case Gravity link between all object pairs. For n
objects, there will be n.(n+1)/2
links
doOneStep(double deltaT, double nowT){
initForces fo all items to 0,0,0
for each ItemLink **allItemLinks**)
inf.evalForce(deltaT, false)
updatePosAndVel(deltaT, nowT, true)
}
In ItemLink:
evalForce(double deltaT, boolean bFinal) {
addGravityEffect(deltaT);
}
boolean addGravityEffect(double deltaT) {
rVector = item2.pos - item1.pos
double gF = G.mq.m2/r2
fVector = gF in rVector direction
item1.addForce(fVector)
similarly for item2 to item1
}
allItems
is a collection of Item objects (Sun, planets and moons)
void updatePosAndVel(double deltaT, double nowT) {
for each Item of **allItems** updatePandV(deltaT, nowT);
}
In Item:
netForce, nowAcc, effectiveAcc, deltaV, newPos etc.
are all Vector3d
updatePAndV(double deltaT, double nowT, boolean bFinal){
nowAcc = netForce / mass
effectiveAcc = mean of lastAcc and nowAcc
deltaV = effectiveAcc * deltaT
meanV ...
newPos = oldPos + meanV * deltaT
}
Not working on gravitation fields but with direct forces due to inter-object gravity.
With the above code, I am able to get stable orbits. Even the orbit times of the moons are good. Get nice Saturn set with the Cycloidal motions of moons and the Uranus set with helical motion of the moons around Uranus. I do not know as to how to send files or images for this discussion