Skip to content

Commit

Permalink
python cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Nov 4, 2023
1 parent ca5612c commit 3b45d56
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 90 deletions.
4 changes: 2 additions & 2 deletions examples/shearing_sheet/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export OPENGL=1
export OPT=-DSERVER
#export OPENGL=1
#export OPT=-DSERVER
include ../../src/Makefile.defs

# CCPROBLEM is defined in Makefile.defs to allow for
Expand Down
1 change: 0 additions & 1 deletion examples/shearing_sheet/problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void heartbeat(struct reb_simulation* const r);
int main(int argc, char* argv[]) {
struct reb_simulation* r = reb_simulation_create();
// Setup constants
//r->visualization = REB_VISUALIZATION_SERVER;
r->opening_angle2 = .5; // This determines the precission of the tree code gravity calculation.
r->integrator = REB_INTEGRATOR_SEI;
r->boundary = REB_BOUNDARY_SHEAR;
Expand Down
83 changes: 2 additions & 81 deletions rebound/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
BOUNDARIES = {"none": 0, "open": 1, "periodic": 2, "shear": 3}
GRAVITIES = {"none": 0, "basic": 1, "compensated": 2, "tree": 3, "mercurius": 4, "jacobi": 5}
COLLISIONS = {"none": 0, "direct": 1, "tree": 2, "line": 4, "linetree": 5}
VISUALIZATIONS = {"none": 0, "opengl": 1, "webgl": 2, "server":3}
# Format: Majorerror, id, message
BINARY_WARNINGS = [
(True, 1, "Cannot read binary file. Check filename and file contents."),
Expand Down Expand Up @@ -200,62 +199,6 @@ def cite(self):
# one could check for REBOUNDx here, then append txt and bib accordingly
print(txt + "\n\n\n" + bib)

def widget(self,**kwargs):
"""
Wrapper function that returns a new widget attached to this simulation.
Widgets provide real-time 3D visualizations from within a Jupyter notebook.
See the Widget class for more details on the possible arguments.
Arguments
---------
All arguments passed to this wrapper function will be passed to /Widget class.
Returns
-------
A rebound.Widget object.
Examples
--------
>>> sim = rebound.Simulation()
>>> sim.add(m=1.)
>>> sim.add(m=1.e-3,x=1.,vy=1.)
>>> sim.widget()
"""
from .widget import Widget # ondemand
from ipywidgets import DOMWidget
from IPython.display import display, HTML
if not hasattr(self, '_widgets'):
self._widgets = []
def display_heartbeat(simp):
for w in self._widgets:
w.refresh(simp,isauto=1)
self.visualization = VISUALIZATIONS["webgl"]
clibrebound.reb_display_init_data(byref(self))
self._dhbf = AFF(display_heartbeat)
self._display_heartbeat = self._dhbf
display(HTML(Widget.getClientCode())) # HACK! Javascript should go into custom.js
newWidget = Widget(self,**kwargs)
self._widgets.append(newWidget)
newWidget.refresh(isauto=0)
return newWidget

def refresh_widgets(self):
"""
This function manually refreshed all widgets attached to this simulation.
You want to call this function if any particle data has been manually changed.
"""
if hasattr(self, '_widgets'):
for w in self._widgets:
w.refresh(isauto=0)
else:
raise RuntimeError("No widgets found")


@property
def simulationarchive_filename(self):
"""
Expand Down Expand Up @@ -946,8 +889,6 @@ def add(self, particle=None, **kwargs):
raise ValueError("Argument passed to add() not supported.")
else:
self.add(Particle(simulation=self, **kwargs))
if hasattr(self, '_widgets'):
self._display_heartbeat(pointer(self))

# Particle getter functions
@property
Expand Down Expand Up @@ -1001,8 +942,6 @@ def remove(self, index=None, hash=None, keep_sorted=True):
clibrebound.reb_simulation_remove_particle_by_hash(byref(self), c_uint32(hash), keep_sorted)
elif isinstance(hash, hash_types):
clibrebound.reb_simulation_remove_particle_by_hash(byref(self), hash, keep_sorted)
if hasattr(self, '_widgets'):
self._display_heartbeat(pointer(self))

self.process_messages()

Expand Down Expand Up @@ -1445,23 +1384,6 @@ class timeval(Structure):
from .particle import Particle
from .particles import Particles

class DisplayData(Structure):
_fields_ = [("r", POINTER(Simulation)),
("r_copy", POINTER(Simulation)),
("particle_data", c_void_p),
("orbit_data", c_void_p),
("particles_copy", POINTER(Particle)),
("p_jh_copy", POINTER(Particle)),
("N_allocated", c_uint64),
("N_allocated_whfast", c_uint64),
("opengl_enabled", c_int),
("scale", c_double),
("mouse_x", c_double),
("mouse_y", c_double),
("retina", c_double),
# ignoring other data (never used)
]


from .integrators.bs import ODE, IntegratorBS
from .integrators.whfast import IntegratorWHFast
Expand Down Expand Up @@ -1507,13 +1429,13 @@ class DisplayData(Structure):
("force_is_velocity_dependent", c_uint),
("gravity_ignore", c_uint),
("_output_timing_last", c_double),
("_display_clock", c_uint64),
("save_messages", c_int),
("messages", c_void_p),
("exit_max_distance", c_double),
("exit_min_distance", c_double),
("usleep", c_double),
("display_data", POINTER(DisplayData)),
("_display_data", c_void_p), # not needed from python
("_server_data", c_void_p), # not needed from python
("track_energy_offset", c_int),
("energy_offset", c_double),
("walltime", c_double),
Expand Down Expand Up @@ -1553,7 +1475,6 @@ class DisplayData(Structure):
("simulationarchive_next", c_double),
("simulationarchive_next_step", c_uint64),
("_simulationarchive_filename", c_char_p),
("_visualization", c_int),
("_collision", c_int),
("_integrator", c_int),
("_boundary", c_int),
Expand Down
5 changes: 5 additions & 0 deletions src/rebound.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ void reb_sigint_handler(int signum) {
}
}

struct reb_thread_info {
struct reb_simulation* r;
double tmax;
};

static void* reb_simulation_integrate_raw(void* args){
reb_sigint = 0;
signal(SIGINT, reb_sigint_handler);
Expand Down
6 changes: 0 additions & 6 deletions src/rebound.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ struct reb_simulation {
unsigned int force_is_velocity_dependent; // 0 (default): force only depends on position, 1: force also depends on velocities
unsigned int gravity_ignore_terms;
double output_timing_last; // Time when reb_simulation_output_timing() was called the last time.
uint64_t display_clock; // Internal variable for timing visualization refreshs.
int save_messages; // 0 (default): print messages on screen, 1: ignore messages (used in python interface).
char** messages; // Array of strings containing last messages (only used if save_messages==1).
double exit_max_distance; // Exit simulation if a particle is this far away from the origin.
Expand Down Expand Up @@ -1048,11 +1047,6 @@ DLLEXPORT void reb_omp_set_num_threads(int num_threads);

// The following stuctures are related to OpenGL/WebGL visualization. Nothing to be changed by the user.

struct reb_thread_info {
struct reb_simulation* r;
double tmax;
};

struct reb_particle_opengl {
float x,y,z;
float vx,vy,vz;
Expand Down

0 comments on commit 3b45d56

Please sign in to comment.