Wrappable Universe mode
gak opened this issue · 4 comments
My suggestion has two parts, the first could be an interesting type of simulation, and both parts joined would be the full idea.
- To restrict a certain area of the simulation within a cube (or rectangular prism) where when a particle exits the area, it is teleported to the other end of the cube. The teleportation should be a subtraction of the width, rather than teleporting exactly to the edge.
- Each force calculation is done an extra 6 times with a "copied" universe in the adjacent sides of the cube. Initially I was considering 27 (3^3) which includes the diagonal edges (i.e. 45 degrees to the edges and corners), which may cause the simulation to be much slower without much extra accuracy added*.
This will slow down the simulation by a factor of 6, but might give a very different, interesting simulation. The aim is to make the universe not have a centre point of gravity where all particles tend to go towards, which is more like our current universe.
Initially this could be a variable called boundary_mode to be 0 by default and 1 as the first point above, and 2 as the two points above. These would mean "No Wrapping", "Position Wrapping", "Position + Gravity Wrapping".
*Not sure how to determine how much more accurate it is.
From a quick Google search, it appears the idea of that universe a three-dimensional torus shape.
http://en.wikipedia.org/wiki/Doughnut_theory_of_the_universe
Very interesting idea! I think that step 2 could even be optimized a bit, because the "twin universes" have some symetries:
- the acceleration between on particle and his 6 "twins" is always zero (the left + right twins have the same distances and mass; same argument for upper/lower and front/back twins)
- Image you are a, and you know the distance vector to b. b has 6 twins, and you can get their distances by adding/subtracting the "universe offset" to the x/y/z part of the distance vector you already have. This should allow us to save some computations and memory access in the inner loop.
.. I'm curious to see how our simulations will look like in the "wrapped universe".
Great optimisation ideas!
There's an experimental branch with lots of hard coded values. I created a "uniform" spawn script which is just randomly placed particles. I was expecting particles to only be interacting with their local area, but instead they started moving towards the centre. This happened even when I removed any calculations towards the middle universe. This could very well be a bug in my modifications, because to me, it doesn't make sense for this to happen! I found a video of someone else doing similar, with many more neighbours, and the same thing happens: https://www.youtube.com/watch?v=KkgyKQantbg
There is a rendering problem when particles wrap around. The particle tails create a long line from one edge to the other. Not a big deal to solve it though. Either keep a ledger of wraps so gfx knows to skip that render, or detect if the position difference is very similar to the width and skip it.
I'll play with it some more today.
hmmm...
- if the initial particles have no velocity, they should start to accelerate towards the center of gravity, which is still in center of space; adding a small random velocity might change this.
- what you see might also be a side-effect of the weird physics in "classic gravit"... how about trying with the "fixed physics" branch?