hannorein / rebound

💫 An open-source multi-purpose N-body code.
https://rebound.readthedocs.io/
GNU General Public License v3.0
817 stars 216 forks source link

`configure_ghostboxes` has no effect #764

Closed benvlehmann closed 3 months ago

benvlehmann commented 3 months ago

Environment Which version of REBOUND are you using and on what operating system?

Describe the bug The configure_ghostboxes method has no effect on the simulation. Directly setting e.g. N_ghost_x does have the expected effect.

In particular, in the example below, I expected the second simulation to take longer than the first one, and for the output to be different. However, they take the same time and have identical output. The third simulation takes longer and has a different output, as expected.

Please forgive me if I've misunderstood the use of configure_ghostboxes. I followed the example notebook "Simulating Saturn's rings" and noticed that changing the arguments to configure_ghostboxes had no effect.

To Reproduce

import rebound
import numpy as np

# Parameters for test simulations
boxsize = 1
x = np.linspace(-boxsize/3., boxsize/3., 10)
xyz = np.array(list(product(x, x, x)))

# First simulation: no ghostboxes
sim = rebound.Simulation()
sim.configure_box(boxsize)
sim.boundary = "periodic"
for p in xyz:
    sim.add(m=1, x=p[0], y=p[1], z=p[2])
sim.integrate(1e-3)  # Takes about 100 ms
print(np.sqrt(np.mean([p.x**2 for p in sim.particles])))
# Output: 0.21177428013277572

# Second simulation: `configure_ghostboxes`
sim = rebound.Simulation()
sim.configure_box(boxsize)
sim.boundary = "periodic"
sim.configure_ghostboxes(2, 2, 2)
for p in xyz:
    sim.add(m=1, x=p[0], y=p[1], z=p[2])
sim.integrate(1e-3)  # Takes about 100 ms
print(np.sqrt(np.mean([p.x**2 for p in sim.particles])))
# Output: 0.21177428013277572

# Third simulation: `N_ghost_x`
sim = rebound.Simulation()
sim.configure_box(boxsize)
sim.boundary = "periodic"
sim.N_ghost_x, sim.N_ghost_y, sim.N_ghost_z = 2, 2, 2
for p in xyz:
    sim.add(m=1, x=p[0], y=p[1], z=p[2])
sim.integrate(1e-3)  # Takes about 10 s
print(np.sqrt(np.mean([p.x**2 for p in sim.particles])))
# Output: 0.21172504114569596
hannorein commented 3 months ago

Thanks a lot for reporting this and especially for providing these great examples! This is indeed a bug in the python wrapper!

hannorein commented 3 months ago

I've simply remove the configure_ghostboxes function. I just doesn't do anything useful, it just tried to set sim.N_ghost_x, sim.N_ghost_y, sim.N_ghost_z like you already figured out. I've updated the examples accordingly. Again, thanks a lot for catching that!