Skip to content

Commit ea0220f

Browse files
committed
example
1 parent d8ea290 commit ea0220f

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

examples/ray/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export OPENGL=0# Set this to 1 to enable OpenGL
2+
export SERVER=1# Set this to 1 to enable the visualization web server
3+
include ../../src/Makefile.defs
4+
5+
# CCPROBLEM is defined in Makefile.defs to allow for
6+
# a compact cross platform Makefile
7+
.PHONY: all librebound
8+
all: problem.c librebound
9+
@echo "Compiling $< ..."
10+
$(CCPROBLEM)
11+
@echo ""
12+
@echo "Compilation successful. To run REBOUND, execute the file '$(EXEREBOUND)'."
13+
@echo ""
14+
15+
librebound:
16+
@echo "Compiling shared library $(LIBREBOUND) ..."
17+
$(MAKE) -C ../../src/
18+
@-$(RM) $(LIBREBOUND)
19+
@$(LINKORCOPYLIBREBOUND)
20+
@echo ""
21+
22+
clean:
23+
@echo "Cleaning up shared library $(LIBREBOUND) ..."
24+
$(MAKE) -C ../../src/ clean
25+
@echo "Cleaning up local directory ..."
26+
@-$(RM) $(LIBREBOUND)
27+
@-$(RM) $(EXEREBOUND)
28+
29+
rebound_webgl.html: problem.c
30+
@echo "Compiling problem.c with emscripten (WebGL enabled)..."
31+
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
32+
33+
rebound_console.html: problem.c
34+
@echo "Compiling problem.c with emscripten (WebGL disabled)..."
35+
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

examples/ray/problem.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "rebound.h"
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <math.h>
5+
6+
int main(int argc, char* argv[]){
7+
struct reb_simulation* r = reb_simulation_create();
8+
// Setup constants
9+
r->dt = 0.1;
10+
reb_simulation_set_integrator(r, "whfast_hj");
11+
12+
// Initial conditions
13+
reb_simulation_add_fmt(r, "solar system"); // Built in dataset for testing.
14+
reb_simulation_move_to_com(r);
15+
16+
double E0 = reb_simulation_energy(r);
17+
reb_simulation_integrate(r, 100*M_PI*2);
18+
double E1 = reb_simulation_energy(r);
19+
printf("dE = %e\n", fabs((E0-E1)/E0));
20+
}
21+
22+

0 commit comments

Comments
 (0)