Computing Gravity: Formula for Average Acceleration

  • Thread starter Thread starter Alkatran
  • Start date Start date
  • Tags Tags
    Computing Gravity
AI Thread Summary
The discussion centers on challenges in simulating gravitational interactions between celestial bodies, particularly when they come very close together, leading to unrealistic accelerations and energy conservation issues. Suggestions include using adaptive time steps to manage large accelerations and implementing collision detection or treating planets as spheres to prevent unrealistic outcomes. The two-body problem is proposed as a potential solution when gravitational forces exceed a certain threshold, allowing for analytical solutions within a critical range. Additionally, the importance of integrating acceleration over time rather than simply adding delta values is emphasized to achieve more accurate results. The conversation highlights the need for numerical integration techniques, such as Runge-Kutta, to improve simulation accuracy.
Alkatran
Science Advisor
Homework Helper
Messages
959
Reaction score
0
I'm attempting to make a program which simulates the gravity of bodies in space. However, I've run into a problem:

The program takes the acceleration/speed/position at a certain time and calculates the new values a (small value of time) later. However, this doesn't work because when two masses get VERY close together:
-The program ees that they are VERY close and gives them a MASSIVE acceleration.
-This results in the planets ending up far away from each other in the next frame.
-Energy isn't conserved and the whole thing is useless.

I was just wondering if anyone had the formula for average gravity over a distance over a period of time. I can make a basic formula for average acceleration assuming the planet continues moving the same speed through the distance. However, the planet will change velocity, so it still won't be accurate at very close distances.
 
Physics news on Phys.org
You could maybe put conservation of energy in as a constraint on the program.
 
Well, I don´t know how good you are at programming or how simple/sophisticated your program is going to be but if you treat your planets as spheres with a radius instead of pointsize particles you can either

a) add a collision detection. Regardless of what happens on collision (bounce off, stick together, break up, ...) the distances between the planets should always be big enough to avoid your problems. If you still have probs you can either make your timesteps smaller od switch to a better intergration method (simple forward steps are the most basic integration method).

b) Let the planets pass through each other but calculate the force acting on them correctly. F=0 for d(istance)=0, for example. Too lazy to calculate it out now and maybe you can well do that yourself. Intuitively it should be F=a*d + b*d for d<r1+r2 where a and b are typical constants for the planets.

EDIT: On 2nd though option b) seems rather stupid (what would your planets be, then? Crystalline gas?)
 
Last edited:
You might want to have an adaptive time step. The program might use smaller time steps when the accelerations appear to be large. In other words, you first calculate the acceleration with the current time step. If that acceleration is very large, you halve the time step and try again. If, on the other hand, the acceleration is very small, you double the time step and try again. In this way, the program will never allow the acceleration to be change more than a certain amount from one frame to the next.

- Warren
 
While walking to the cinema earlier this evening I came up with an other alternative which would be my favorite atm:
When gravitational force between two objects exceeds a certain very large number of your choice:
Unless you accidentially have 3 bodies coming close to each other at the same time you can assume the force they exert on each other exceeds the forces from all other objects by far => neglect them => 2-body problem. The 2-body problem can be solved analytically so as long as both objects are within your critical range you move them along the trajectories of the 2-body problem. Once they get out of the critical range you proceed with your normal procedure. The error should be insignificant. You can even treat your objects as point-masses, then.
 
These are all excellent logical ideas... the only problem is it's the type of solution I already had! (For example, the radius limitation was the current solution)

I suppose my real question is:
Assuming you know the inital speed, initial force, final force, distance, and time, can you calculate final speed or acceleration?
 
I don't know how your program is done, but a common pitfall is to simply add up delta-Vs (or delta-Accelerations, or whatever delta) instead of integrating them for the timeframe. If the acceleration is a function of distance, and youv'e got a large acceleration due to close distance, AND you apply the same CONSTANT force through the next timeframe (incorrect), then your planets end up far away. If, instead, the result of the force is an integral of the acceleration over time (where the acceleration itself is a FUNCTION, probably a decreasing one), then maybe you get close to the real thing.
This is just general advise; the actual math should be shown by somebody else. :-p . Hope this helps, anyway.
 
Alkatran said:
I'm attempting to make a program which simulates the gravity of bodies in space. However, I've run into a problem:

The program takes the acceleration/speed/position at a certain time and calculates the new values a (small value of time) later. However, this doesn't work because when two masses get VERY close together:

You should do some web searches for "numerical integration" and "runge-kutta" for a starter.

link

will at least get you somewhat started.

Runge-kutta, in spite of being one of the standard workhouse schemes of numerical integration, isn't necessarily the best choice for large gravity simulations, though. But it's probably a good enough to "play around" with. You'll need an adaptive timestep to deal with close approach, too.
 
Dodo said:
I don't know how your program is done, but a common pitfall is to simply add up delta-Vs (or delta-Accelerations, or whatever delta) instead of integrating them for the timeframe. If the acceleration is a function of distance, and youv'e got a large acceleration due to close distance, AND you apply the same CONSTANT force through the next timeframe (incorrect), then your planets end up far away. If, instead, the result of the force is an integral of the acceleration over time (where the acceleration itself is a FUNCTION, probably a decreasing one), then maybe you get close to the real thing.
This is just general advise; the actual math should be shown by somebody else. :-p . Hope this helps, anyway.

Yes, I knew that was the problem. But I couldn't figure out how to do it with high-school maths.
 

Similar threads

Replies
6
Views
4K
Replies
13
Views
2K
Replies
5
Views
3K
Replies
7
Views
2K
Replies
73
Views
22K
Replies
12
Views
3K
Replies
8
Views
2K
Replies
17
Views
3K
Back
Top