From 3b45d56bafa32cdd14f7287572f2de931271ad3d Mon Sep 17 00:00:00 2001 From: Hanno Rein Date: Sat, 4 Nov 2023 19:33:37 -0400 Subject: [PATCH] python cleanup --- examples/shearing_sheet/Makefile | 4 +- examples/shearing_sheet/problem.c | 1 - rebound/simulation.py | 83 +------------------------------ src/rebound.c | 5 ++ src/rebound.h | 6 --- 5 files changed, 9 insertions(+), 90 deletions(-) diff --git a/examples/shearing_sheet/Makefile b/examples/shearing_sheet/Makefile index e73959125..14d540669 100644 --- a/examples/shearing_sheet/Makefile +++ b/examples/shearing_sheet/Makefile @@ -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 diff --git a/examples/shearing_sheet/problem.c b/examples/shearing_sheet/problem.c index e991fd18f..cf4c071ed 100644 --- a/examples/shearing_sheet/problem.c +++ b/examples/shearing_sheet/problem.c @@ -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; diff --git a/rebound/simulation.py b/rebound/simulation.py index e57225325..d954ff3f4 100644 --- a/rebound/simulation.py +++ b/rebound/simulation.py @@ -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."), @@ -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): """ @@ -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 @@ -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() @@ -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 @@ -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), @@ -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), diff --git a/src/rebound.c b/src/rebound.c index 9d9010eae..67a75d507 100644 --- a/src/rebound.c +++ b/src/rebound.c @@ -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); diff --git a/src/rebound.h b/src/rebound.h index 3e5db9512..dca917c16 100644 --- a/src/rebound.h +++ b/src/rebound.h @@ -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. @@ -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;