Skip to content

Commit

Permalink
Merge branch 'main' into newTRACE4_FULL
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Feb 11, 2024
2 parents 5ac8fa3 + 26f2c67 commit cbe5611
Show file tree
Hide file tree
Showing 27 changed files with 1,330 additions and 354 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Version](https://img.shields.io/badge/rebound-v4.1.1-green.svg?style=flat)](https://rebound.readthedocs.org)
[![Version](https://img.shields.io/badge/rebound-v4.3.0-green.svg?style=flat)](https://rebound.readthedocs.org)
[![PyPI](https://badge.fury.io/py/rebound.svg)](https://badge.fury.io/py/rebound)
[![GPL](https://img.shields.io/badge/license-GPL-green.svg?style=flat)](https://github.com/hannorein/rebound/blob/main/LICENSE)
[![Paper](https://img.shields.io/badge/arXiv-1110.4876-green.svg?style=flat)](https://arxiv.org/abs/1110.4876)
Expand Down
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This changelog only includes the most important changes in recent updates. For a

## Version 4.x

### Version 4.3.0
* Take screenshots of WebGL based visualizations using the `reb_simulation_output_screenshot()` function. You need to connect one web browser to the simulation in order to take screenshots.
* Improved synchronization of visualization and simulation on Windows with mutex.
* Fixes an issue that might lead to NaN values when less than the maximum number of planets are used in WHFast512.

### Version 4.2.0
* It is now possible to programmatically change all aspects of a REBOUND visualization. This can be used to set up default viewing options or to render animations. See the C examples in `animation_solar_system` and `animation_saturn_rings`.
* Reworked matrix operations in visualization routines to follow the Model-View-Projection paradigm.
* Fixed an issues where unit tests would fail because a binary file was not deleted.

### Version 4.1.1
* Fixed python wheels for windows.

Expand Down
2 changes: 2 additions & 0 deletions docs/c_examples/generate_c_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def run(*args, **kwargs):
# Manual exception for file viewer
if "_viewer" in cname:
livepreview=0
if "screenshots" in cname:
livepreview=0
try:
with open("examples/"+cname+"/Makefile","r") as mfd:
Makefile = mfd.read()
Expand Down
35 changes: 35 additions & 0 deletions examples/animation_saturns_rings/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export OPENGL=0# Set this to 1 to enable OpenGL
export SERVER=1# Set this to 1 to enable the visualization web server
include ../../src/Makefile.defs

# CCPROBLEM is defined in Makefile.defs to allow for
# a compact cross platform Makefile
.PHONY: all librebound
all: problem.c librebound
@echo "Compiling $< ..."
$(CCPROBLEM)
@echo ""
@echo "Compilation successful. To run REBOUND, execute the file '$(EXEREBOUND)'."
@echo ""

librebound:
@echo "Compiling shared library $(LIBREBOUND) ..."
$(MAKE) -C ../../src/
@-$(RM) $(LIBREBOUND)
@$(LINKORCOPYLIBREBOUND)
@echo ""

clean:
@echo "Cleaning up shared library $(LIBREBOUND) ..."
$(MAKE) -C ../../src/ clean
@echo "Cleaning up local directory ..."
@-$(RM) $(LIBREBOUND)
@-$(RM) $(EXEREBOUND)

rebound_webgl.html: problem.c
@echo "Compiling problem.c with emscripten (WebGL enabled)..."
emcc -O3 -I../../src/ ../../src/*.c problem.c -DSERVERHIDEWARNING -DOPENGL=1 -sSTACK_SIZE=655360 -s USE_GLFW=3 -s FULL_ES3=1 -sASYNCIFY -sALLOW_MEMORY_GROWTH -sSINGLE_FILE -sEXPORTED_RUNTIME_METHODS="callMain" --shell-file ../../web_client/shell_rebound_webgl.html -o rebound_webgl.html

rebound_console.html: problem.c
@echo "Compiling problem.c with emscripten (WebGL disabled)..."
emcc -O3 -I../../src/ ../../src/*.c problem.c -DSERVERHIDEWARNING -sSTACK_SIZE=655360 -sASYNCIFY -sALLOW_MEMORY_GROWTH -sSINGLE_FILE -sEXPORTED_RUNTIME_METHODS="callMain" --shell-file ../../web_client/shell_rebound_console.html -o rebound_console.html
97 changes: 97 additions & 0 deletions examples/animation_saturns_rings/problem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Animation of the Saturn's Rings
*
* This examples show how to use display_settings to
* programmatically change the visualization of a
* REBOUND simulation. Here, we visualize a simulation of
* Saturn's rings and rotate the viewwing angle programatically.
* To understand what a 4x4 view matrix is, you can read
* up on linear algebra for computer graphics, specifically
* the Model-View-Projection (MVP) paradigm.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "rebound.h"

double coefficient_of_restitution_bridges(const struct reb_simulation* const r, double v);

// The heartbeat function is called once a timestep
void heartbeat(struct reb_simulation* const r){
// Construct a rotation.
struct reb_vec3d axis = {.y=1., .z=0.2};
struct reb_rotation rot = reb_rotation_init_angle_axis(0.003, axis); // small increment every timestep

// Convert quaternion to rotation matrix
struct reb_mat4df rm = reb_rotation_to_mat4df(rot);

// Apply incremental rotation to view matrix.
r->display_settings->view = reb_mat4df_multiply(rm, r->display_settings->view);
}


int main(int argc, char* argv[]) {
struct reb_simulation* r = reb_simulation_create();

// The heartbeat function handles the visualization in this example.
r->heartbeat = heartbeat;

// Setup problem. For more details, see the shearing sheet example.
r->opening_angle2 = .5;
r->integrator = REB_INTEGRATOR_SEI;
r->boundary = REB_BOUNDARY_SHEAR;
r->gravity = REB_GRAVITY_TREE;
r->collision = REB_COLLISION_TREE;
r->collision_resolve = reb_collision_resolve_hardsphere;
r->coefficient_of_restitution = coefficient_of_restitution_bridges;
r->ri_sei.OMEGA = 0.00013143527; // 1/s
r->minimum_collision_velocity = r->ri_sei.OMEGA*0.001;
r->G = 6.67428e-11; // N / (1e-5 kg)^2 m^2
r->softening = 0.1; // m
r->dt = 1e-3*2.*M_PI/r->ri_sei.OMEGA; // s

reb_simulation_configure_box(r, 100, 2, 2, 1); // 100m box
r->N_ghost_x = 2; r->N_ghost_y = 2; r->N_ghost_z = 0;

// Add all ring paricles
double mass = 0;
while(mass < 400*r->boxsize.x*r->boxsize.y){ // 400kg/m^2 surface density
struct reb_particle pt = {0};
pt.x = reb_random_uniform(r, -r->boxsize.x/2.,r->boxsize.x/2.);
pt.y = reb_random_uniform(r, -r->boxsize.y/2.,r->boxsize.y/2.);
pt.z = reb_random_normal(r, 1.); // m
pt.vy = -1.5*pt.x*r->ri_sei.OMEGA;
double radius = reb_random_powerlaw(r, 1., 4.,-3);
pt.r = radius; // m
double particle_mass = 400.0*4./3.*M_PI*radius*radius*radius; // 400kg/m^3 particle density
pt.m = particle_mass; // kg
reb_simulation_add(r, pt);
mass += particle_mass;
}

// Normally the visualization settings are determined by the
// user interface. If we add the display_settings struct to
// the simulation itself, it will overwrite any change the
// user has made and allows us to programatically change any
// settings such as the orientation, zoom, etc.
reb_simulation_add_display_settings(r);

// This allows you to connect to the simulation using
// a web browser. Simply go to http://localhost:1234
reb_simulation_start_server(r, 1234);

// Integrate forever
reb_simulation_integrate(r, INFINITY);
reb_simulation_free(r);
}

// This example is using a custom velocity dependend coefficient of restitution
double coefficient_of_restitution_bridges(const struct reb_simulation* const r, double v){
// assumes v in units of [m/s]
double eps = 0.32*pow(fabs(v)*100.,-0.234);
if (eps>1) eps=1;
if (eps<0) eps=0;
return eps;
}

35 changes: 35 additions & 0 deletions examples/animation_solar_system/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export OPENGL=0# Set this to 1 to enable OpenGL
export SERVER=1# Set this to 1 to enable the visualization web server
include ../../src/Makefile.defs

# CCPROBLEM is defined in Makefile.defs to allow for
# a compact cross platform Makefile
.PHONY: all librebound
all: problem.c librebound
@echo "Compiling $< ..."
$(CCPROBLEM)
@echo ""
@echo "Compilation successful. To run REBOUND, execute the file '$(EXEREBOUND)'."
@echo ""

librebound:
@echo "Compiling shared library $(LIBREBOUND) ..."
$(MAKE) -C ../../src/
@-$(RM) $(LIBREBOUND)
@$(LINKORCOPYLIBREBOUND)
@echo ""

clean:
@echo "Cleaning up shared library $(LIBREBOUND) ..."
$(MAKE) -C ../../src/ clean
@echo "Cleaning up local directory ..."
@-$(RM) $(LIBREBOUND)
@-$(RM) $(EXEREBOUND)

rebound_webgl.html: problem.c
@echo "Compiling problem.c with emscripten (WebGL enabled)..."
emcc -O3 -I../../src/ ../../src/*.c problem.c -DSERVERHIDEWARNING -DOPENGL=1 -sSTACK_SIZE=655360 -s USE_GLFW=3 -s FULL_ES3=1 -sASYNCIFY -sALLOW_MEMORY_GROWTH -sSINGLE_FILE -sEXPORTED_RUNTIME_METHODS="callMain" --shell-file ../../web_client/shell_rebound_webgl.html -o rebound_webgl.html

rebound_console.html: problem.c
@echo "Compiling problem.c with emscripten (WebGL disabled)..."
emcc -O3 -I../../src/ ../../src/*.c problem.c -DSERVERHIDEWARNING -sSTACK_SIZE=655360 -sASYNCIFY -sALLOW_MEMORY_GROWTH -sSINGLE_FILE -sEXPORTED_RUNTIME_METHODS="callMain" --shell-file ../../web_client/shell_rebound_console.html -o rebound_console.html
Loading

0 comments on commit cbe5611

Please sign in to comment.