Or there might be an issue with there being only 5 bodies in the test. Im a bit puzzled.
Ill send the code later in the day.
x = bodies_x[body_index]
versus
x = bodies[body_index].x
The "issue" with the nbody benchmark from the benchmarks game is that there's only four bodies, making this SOA-style approach have little payoff.
It would be great if you could do such a test, but with a significantly larger amount of bodies.
body={ x:[] ,y:[] ,z:[] ,vx:[] ,vy:[] ,vz:[] ,mass:[] }
I find this is running 20% faster than the fastest on my chrome browser (an old version) but is slightly slower on firefox, but catches up a bit with 11 bodies.
I expect it could run faster yet by crunching the code up more and maybe removing objects altogether, but i made few changes as possible just to compare the difference in addressing.
There is also function "offsetMomentum" which tweaks the suns movement according to momentum of the planets, it seems very extraneous to me, gravitational influence should surely be sufficient in itself regarding conservation of momentum. I suspect that function is more likely a catch for large errors which can result from point grav bodies getting to close to each other.
[1] https://software.intel.com/sites/default/files/article/39227...
When dt is too large and bodies get too close, they get super-attracted to each other in one step, and by the time of the next step, they have travelled too far to get slowed again, this is where I see major errors can occur. Its necessary to put a throttle in the force calculation, or to reduce dt to deal with that 'near missing'. Or to substep but that seems to require excessive adjustments.
Now chuck in some velocity dependent forces and start screaming (that's what I've found with physical simulations anyway).
"velocity dependent forces" I have been wondering how to implement a sort of quasi-electromagnetic force without the big expense of maintaining a magnetic field. I find the electro-magnetic force mind blowing compared to newtonian gravity. Like charges seem to be able to attract when travelling together, this would seem to produce patterns and structure more readily than gravitation.
Global value numbering (GVN) should be trivially able to do this.
x = body.x[body_index]
I expect this should be much faster than accessing them like this:
x = body.[body_index].x
Because the latter requires pointer-from-property calculation for every single values access (which must be somehow optimised)
The former just requires pointer-from-property calculation for every array (not element) involved in the nbody loops, the individual element|values are picked out by array addressing which is inherently much simpler than property access.
I've used this method for nbody physics. I can modify a test to it and push to the repo.