hannorein/rebound

`configure_ghostboxes` has no effect

benvlehmann opened this issue · 2 comments

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

  • REBOUND Version: 4.3.2
  • API interface: Python
  • Operating System (including version): MacOS Sonoma 14.3.1

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

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

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!