In an nbody gravity simulation, instead of doing exact(all-pair brute force) solution, I added masses of each body into cells of a 3D grid(each cell is just a float value having a mass value). Then smoothed the grid using a stencil. Now I'm trying to get an approximation of point masses for point masses, from grid. I have already tried directly doing body-cell interaction(similar to body-body but using smoothed mass of cell and center position of cell) but this selects originally non-mass containing cells as if they are attracting and leads to high errors.
What could be the most precise(or logical) way to do one of below options:
- a unit mass at an approximated position
- an approximated mass at a unit distance and angle
- approximation of both mass and distance
so that long-range component of total force properly acts same as all-pair brute-force version(long-range part of it)?
Or, what could be a proper way other than upper options? Can I use derivate of mass density(by neighboring cells) for these?
For now I'm calculating only an RMS error between all pair(but only long range part) version and this center-of-cell with smoothed mass (only with closest neighbor cells after long range distance(which equals 2*cell size)) to check how close the simulation is to all-pair version.
I'm doing this grid smoothing because I want to learn multigrid acceleration for nbody. To learn it step by step (and to do a performance comparison against later), only using a single grid with simple smoothing(16x16x16 cubes(as grid size) and 16 smoothing steps with 26 closest neighbor cells(using successive over relaxation ).
Initially both versions start in a cube volume.(Total particles are just 3072)
then at each timestep, rms of error of all body positions between two versions is calculated.
Addition of point masses to cells are done very simply as