Skip to content

Commit

Permalink
Renamed python functions of Simulation to be consistent with C:
Browse files Browse the repository at this point in the history
integrator_reset -> reset_integrator
integrator_synchronize ->  synchronize
tree_update -> update_tree
  • Loading branch information
hannorein committed Jan 1, 2025
1 parent a8c1f2e commit 15becb2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/outer_solar_system/problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* The example also works with the WHFAST symplectic integrator. We turn
* off safe-mode to allow fast and accurate simulations with the symplectic
* corrector. If an output is required, you need to call ireb_simulation_synchronize()
* corrector. If an output is required, you need to call reb_simulation_synchronize()
* before accessing the particle structure.
*/
#include <stdio.h>
Expand Down Expand Up @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) {
const double k = 0.01720209895; // Gaussian constant
r->dt = 40; // in days
r->G = k * k; // These are the same units as used by the mercury6 code.
r->ri_whfast.safe_mode = 0; // Turn of safe mode. Need to call integrator_synchronize() before outputs.
r->ri_whfast.safe_mode = 0; // Turn of safe mode. Need to call reb_simulation_synchronize() before outputs.
r->ri_whfast.corrector = 11; // Turn on symplectic correctors (11th order).

// Setup callbacks:
Expand Down
8 changes: 4 additions & 4 deletions ipython_examples/AdvWHFast.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"editable": true
},
"source": [
"REBOUND will synchronize every timestep even if you set `sim.ri_whfast.safe_mode = 0` and never explicitly call `sim.integrator_synchronize()`."
"REBOUND will synchronize every timestep even if you set `sim.ri_whfast.safe_mode = 0` and never explicitly call `sim.synchronize()`."
]
},
{
Expand Down Expand Up @@ -259,7 +259,7 @@
" sim.step()\n",
" sim.particles[1].m += 1.e-10\n",
" sim.ri_whfast.recalculate_coordinates_this_timestep = 1\n",
" sim.integrator_synchronize()"
" sim.synchronize()"
]
},
{
Expand Down Expand Up @@ -291,7 +291,7 @@
" sim.step()\n",
" sim.particles[1].vx += 1.e-10*sim.dt\n",
" sim.ri_whfast.recalculate_coordinates_this_timestep = 1\n",
" sim.integrator_synchronize()"
" sim.synchronize()"
]
},
{
Expand All @@ -301,7 +301,7 @@
"editable": true
},
"source": [
"This would not give accurate results, because the `sim.particles[1].vx` we access after `sim.step()` isn't a physical velocity (it's missing a half-Kepler step). It's basically at an intermediate point in the calculation. In order to make this work, one would call `sim.integrator_synchronize()` between `sim.step()` and accessing `sim.particles[1].vx`, to ensure the velocity is physical."
"This would not give accurate results, because the `sim.particles[1].vx` we access after `sim.step()` isn't a physical velocity (it's missing a half-Kepler step). It's basically at an intermediate point in the calculation. In order to make this work, one would call `sim.synchronize()` between `sim.step()` and accessing `sim.particles[1].vx`, to ensure the velocity is physical."
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions rebound/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,20 +1412,20 @@ def stop(self):
"""
clibrebound.reb_simulation_stop(byref(self))

def integrator_reset(self):
def reset_integrator(self):
"""
Call this function to reset temporary integrator variables
"""
clibrebound.reb_simulation_reset_integrator(byref(self))

def integrator_synchronize(self):
def synchronize(self):
"""
Call this function if safe-mode is disabled and you need to synchronize particle positions and velocities between timesteps.
"""
clibrebound.reb_simulation_synchronize(byref(self))
self.process_messages()

def tree_update(self):
def update_tree(self):
"""
Call this function to update the tree structure manually after removing particles.
"""
Expand Down
4 changes: 2 additions & 2 deletions rebound/simulationarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __getitem__(self, key):
if self.process_warnings:
warnings.warn(message, RuntimeWarning)
if sim.ri_eos.is_synchronized==0 or sim.ri_mercurius.is_synchronized==0 or sim.ri_whfast.is_synchronized==0 or sim.ri_mercurius.is_synchronized==0:
warnings.warn("The simulation might not be synchronized. You can manually synchronize it by calling sim.integrator_synchronize().", RuntimeWarning)
warnings.warn("The simulation might not be synchronized. You can manually synchronize it by calling sim.synchronize().", RuntimeWarning)

return sim

Expand Down Expand Up @@ -241,7 +241,7 @@ def getSimulation(self, t, mode='snapshot', keep_unsynchronized=1):
keep_unsynchronized = 0
sim.ri_whfast.keep_unsynchronized = keep_unsynchronized
sim.ri_saba.keep_unsynchronized = keep_unsynchronized
sim.integrator_synchronize()
sim.synchronize()
return sim
else:
if mode=='exact':
Expand Down
2 changes: 1 addition & 1 deletion rebound/tests/test_shearingsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def powerlaw(slope, min_v, max_v):
self.assertGreater(sim.collisions_log_n,1000)
Nbefore = sim.N
sim.remove(0,keep_sorted=0)
sim.tree_update()
sim.update_tree()
self.assertEqual(Nbefore-1,sim.N)
with self.assertRaises(RuntimeError):
sim.remove(0,keep_sorted=1)
Expand Down
2 changes: 1 addition & 1 deletion src/particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ int reb_simulation_remove_particle(struct reb_simulation* const r, int index, in
}
}else{
if (r->tree_root){
// Just flag particle, will be removed in tree_update.
// Just flag particle, will be removed in update_tree.
r->particles[index].y = nan("");
if(r->free_particle_ap){
r->free_particle_ap(&r->particles[index]);
Expand Down

0 comments on commit 15becb2

Please sign in to comment.