# B N-body random peak velocity of passing particles

1. Jun 26, 2017

### CommanderLake

I've been experimenting with my own N-body simulation and I've found a seemingly unsolvable problem.
When 2 particles cross paths exactly the peak velocity varies according to how close they are at their closest point and they either fly off the screen or slow right down, I can add an offset to the gravitational force but that makes acceleration more linear.
Obviously the real world doesn't have an update rate so conventional physics probably wont help but I wonder if anyone here might be able to tell me how I might solve this?

2. Jun 26, 2017

### rumborak

Simulating these things is notoriously tricky because you keep accumulating errors over time.
One thing I can suggest, presuming you are developing this simulation yourself, is to switch from a global "grid clock" to a "particle clock" whose resolution you can adjust for each particle. If a particle starts experiencing a strong field you reduce the step size of its clock to stay accurate, and later bring it back to a more manageable (for the overall simulation) step size.

In terms of pure physics, of course there are classic solutions to the 2-body problem (Kepler etc), but those won't help you much with your simulation.

3. Jun 27, 2017

### CommanderLake

Actually step size makes no difference because the particles have no size and its a matter of the ratio between how far apart they are before and after they pass, if they are closer after they pass they slow down and vice versa, thanks anyway for your input.

4. Jun 28, 2017

### A.T.

The time step size makes a difference in accuracy, regardless of the particle size. The zero size assumption is a problem in the sense that it allows arbitrarily small distances and thus arbitrarily large forces. In reality the objects would collide instead.

5. Jun 28, 2017

### rumborak

Yeah, step size is a huge factor in these things, and often decide whether you have a reasonable simulation, or particles flying off the screen at ridiculous speed.

6. Jun 30, 2017

### olgerm

imagine 1-dimensional 2-particle simulation. I am using units, where G=1. Masses of particles are $m_1=1$ and $m_2=1$. In initial time $x_1(0)=5.001$, $v_1(0)=-1$, $x_2(0)=-5$ and $v_2(0)=1$. therefore $a_1(0)=-0.01$ and $a_2(0)=0.01$.
Maybe after reading this you understand better, what problem occurs in simulation when point-masses get too close.
• $t$ ;$\ \ \ \ \ \ x_1\ \ \ \ \ \$;$\ \ \ \ \ \ v_1\ \ \ \ \$;$\ \ \ \ \ \ a_1 \ \ \ \ \$;$\ \ \ \ \ \ x_2 \ \ \ \ \$ ;$\ \ \ \ \ \ v_2 \ \ \ \ \$;$\ \ \ \ \ \ a_2$
• 0 ; 5.001000;-1.000000;-0.009998;-5.000000 ;1.000000;0.009998
• 1 ; 4.001000;-1.009998;-0.015625;-4.000000 ;1.009998;0.015625
• 2 ; 2.991002;-1.025623;-0.027954;-2.990002 ;1.025618;0,027954
• 3 ; 1.965379;-1.053577;-0.064754;-1.964384 ;1.053572;0.064754
• 4 ; 0.911802;-1.118331;-0.301030;-0.910812 ;1.118326;0.301031
• 5 ;-0.206529;-1.419360;5.8332300;0.207514 ;1.419356;-5.833230
• 6 ;-1.625889;4.4138700;0.0945140;1.626870;-4.413874;0.094514
• 7 ;2.787981 ;4.5083840;-0.0321745;-2.787004;-4.31936;0.032174

7. Jun 30, 2017

### rumborak

Here's a much more straightforward example:

One proton is at rest, and another proton is flying straight at it, at 1 m/s speed. And currently it's 1m away.
If you choose your time resolution to be 1 second, you find that at your next time step (i.e. 1 second later), the photon is *exactly* on top of the other one. Now you got infinite forces etc etc.

If on the other hand you choose 0.1s time resolution, the approaching proton will have experienced a nice gradual increase in repelling force as it approached, and your simulation looks a lot better.

8. Jul 1, 2017

### CommanderLake

I understand that a smaller time step will increase the simulation accuracy, its not a physically accurate simulation its just for fun and self education, I'm using an arbitrary G constant to make a pleasing amount of particles move at a pleasing velocity with a reasonable framerate with vsync off rather than compensating for the fluctuating update rate.
This has the effect of the update rate slowing to compensate for the increased acceleration due to more particles and therefore more gravity, so with non linear scaling due to overhead and SIMD instructions, 2 particles at say 9000 FPS will move at a reasonable speed as will 4096 at 100 FPS.
But even with 2 particles at 9000 FPS moving slowly enough to keep track of them, the peak velocity of intercepting particles is just as inconsistent as 4096.

Rather than adding the memory overhead of more variables such as size and mass, maybe I could do some kind of linear interpolation to calculate the average force along the path between A and B but I dont know how to do that, any volunteers?

9. Jul 2, 2017

### rumborak

It really depends what you're trying to get out of your simulation. If the goal is just something that looks reasonably convincing, then yeah, shortcuts like capping the force etc are totally fine. However, often those shortcuts send you into a one-way street that is hard to get out of when you are trying to extend your simulation. A shortcut that might have only affected your simulation imperceptibly originally, might make it useless further down the road.

10. Jul 2, 2017

### CommanderLake

So theres no real solution to this? I thought some sort of interpolation might be the best way.