Computing Gravity: Formula for Average Acceleration

  • Context: Undergrad 
  • Thread starter Thread starter Alkatran
  • Start date Start date
  • Tags Tags
    Computing Gravity
Click For Summary

Discussion Overview

The discussion revolves around challenges in simulating gravitational interactions between celestial bodies in a programming context. Participants explore issues related to calculating average acceleration and the effects of close proximity between masses, focusing on numerical integration methods and potential solutions to maintain energy conservation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a problem where the simulation yields massive accelerations when two bodies are very close, leading to unrealistic outcomes and energy non-conservation.
  • Another suggests incorporating conservation of energy as a constraint in the simulation.
  • A different participant proposes treating planets as spheres with a radius to avoid issues, suggesting collision detection or allowing planets to pass through each other while calculating forces correctly.
  • Adaptive time steps are recommended by one participant to manage large accelerations, proposing to adjust the time step based on the calculated acceleration.
  • One participant introduces a method to simplify calculations by treating close interactions as a two-body problem when gravitational forces exceed a certain threshold.
  • A participant expresses a desire to calculate final speed or acceleration given initial conditions, indicating a need for clarity on the mathematical approach.
  • Concerns are raised about the common pitfall of simply adding delta values instead of integrating over time, emphasizing the need for a function-based approach to acceleration.
  • Another participant suggests researching numerical integration methods, specifically mentioning Runge-Kutta, while noting that it may not be the best choice for large gravity simulations.

Areas of Agreement / Disagreement

Participants present various approaches and solutions, but there is no consensus on a single method or formula for addressing the simulation challenges. Multiple competing views and suggestions remain throughout the discussion.

Contextual Notes

Limitations include the dependence on specific assumptions about the simulation's setup, the need for precise definitions of forces and distances, and unresolved mathematical steps related to integrating acceleration over time.

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 7 ·
Replies
7
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 14 ·
Replies
14
Views
22K
Replies
4
Views
2K
  • · Replies 47 ·
2
Replies
47
Views
6K
  • · Replies 2 ·
Replies
2
Views
16K