-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hanno Rein
committed
Jun 2, 2023
1 parent
e23edb8
commit 0985b9c
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export OPENGL=0 | ||
export OPT=-march=native | ||
include ../../src/Makefile.defs | ||
|
||
all: librebound | ||
@echo "" | ||
@echo "Compiling problem file ..." | ||
$(CC) -I../../src/ -Wl,-rpath,./ $(OPT) $(PREDEF) problem.c -L. -lrebound $(LIB) -o rebound | ||
@echo "" | ||
@echo "REBOUND compiled successfully." | ||
|
||
librebound: | ||
@echo "Compiling shared library librebound.so ..." | ||
$(MAKE) -C ../../src/ | ||
@-rm -f librebound.so | ||
@ln -s ../../src/librebound.so . | ||
|
||
clean: | ||
@echo "Cleaning up shared library librebound.so ..." | ||
@-rm -f librebound.so | ||
$(MAKE) -C ../../src/ clean | ||
@echo "Cleaning up local directory ..." | ||
@-rm -vf rebound |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <math.h> | ||
#include "rebound.h" | ||
|
||
double all_ss_pos[10][3] = { | ||
{-0.008816286905115728, -0.0010954664916791675, 0.0002143249385447027}, | ||
{-0.05942272929227954, -0.46308699693348293, -0.032897989948949075}, | ||
{-0.7276101005375593, 0.006575003332463933, 0.041795901908847084}, | ||
{-0.5789530452882667, -0.8361530119313055, 0.0002611520181901174}, | ||
{-1.45202492400084, 0.827519404194876, 0.052981833432457694}, | ||
{4.492983939852296, 2.0661626247490354, -0.10909246996001629}, | ||
{8.4974210980544, -4.8620394993693585, -0.2537835862373596}, | ||
{12.959111916929283, 14.760785302864473, -0.1130656917933948}, | ||
{29.787987348666505, -2.51460654509393, -0.6347108842010732} | ||
}; | ||
|
||
double all_ss_vel[10][3] = { | ||
{0.00014315746073017681, -0.0004912441820893999, 8.127678560998346e-07}, | ||
{1.2978664284760637, -0.09524541469911743, -0.12677574364801253}, | ||
{-0.019239782390457125, -1.1813975672919448, -0.01509392594251431}, | ||
{0.8098712561282222, -0.5682496529341624, 2.6169897281383047e-05}, | ||
{-0.37436417754222295, -0.6365841544564991, -0.004143932260467942}, | ||
{-0.18818907783656452, 0.41919544951404614, 0.0024710497024424977}, | ||
{0.14292308496870448, 0.2808676923735748, -0.010574288572728728}, | ||
{-0.1734971049470612, 0.14019515029516152, 0.0027683484887051457}, | ||
{0.014142947617173336, 0.18292110872737416, -0.004092845767710294} | ||
}; | ||
|
||
double all_ss_mass[10] = { | ||
0.9999999999950272, | ||
1.6601208254808336e-07, | ||
2.447838287784771e-06, | ||
3.0404326489511185e-06, | ||
3.2271560828978514e-07, | ||
0.0009547919099366768, | ||
0.0002858856700231729, | ||
4.366249613200406e-05, | ||
5.151383772628957e-05 | ||
}; | ||
|
||
double tmax = 5e5; | ||
|
||
void run(int faster){ | ||
struct timeval time_beginning; | ||
struct timeval time_end; | ||
|
||
struct reb_simulation* r = reb_create_simulation(); | ||
// Setup constants | ||
r->dt = 5e-2; | ||
////r->G = k * k; // These are the same units as used by the mercury6 code. | ||
r->G = 1.; | ||
//r->ri_whfast.safe_mode = 0; // Turn of safe mode. Need to call integrator_synchronize() before outputs. | ||
//r->ri_whfast.corrector = 11; // Turn on symplectic correctors (11th order). | ||
r->ri_whfast.faster = faster; | ||
r->ri_whfast.coordinates = REB_WHFAST_COORDINATES_DEMOCRATICHELIOCENTRIC; | ||
r->ri_whfast.safe_mode = 0; | ||
// Setup callbacks: | ||
r->force_is_velocity_dependent = 0; // Force only depends on positions. | ||
r->integrator = REB_INTEGRATOR_WHFAST; | ||
//r->integrator = REB_INTEGRATOR_IAS15; | ||
|
||
|
||
// Initial conditions | ||
for (int i = 0; i < 9; i++) { | ||
struct reb_particle p = {0}; | ||
p.x = all_ss_pos[i][0]; | ||
p.y = all_ss_pos[i][1]; | ||
p.z = all_ss_pos[i][2]; | ||
p.vx = all_ss_vel[i][0]; | ||
p.vy = all_ss_vel[i][1]; | ||
p.vz = all_ss_vel[i][2]; | ||
p.m = all_ss_mass[i]; | ||
reb_add(r, p); | ||
} | ||
|
||
reb_move_to_com(r); | ||
|
||
|
||
double e_initial = reb_tools_energy(r); | ||
|
||
// Start integration | ||
gettimeofday(&time_beginning,NULL); | ||
reb_integrate(r, tmax); | ||
gettimeofday(&time_end,NULL); | ||
|
||
double e_final = reb_tools_energy(r); | ||
double error = fabs((e_final - e_initial) / e_initial); | ||
|
||
double walltime = time_end.tv_sec-time_beginning.tv_sec+(time_end.tv_usec-time_beginning.tv_usec)/1e6; | ||
printf("%.8f \t %.4e\n", walltime, error); | ||
|
||
//for (int k=0; k<9; k++) | ||
// printf("%18.16E %18.16E %18.16E\n", r->particles[k].x, r->particles[k].y, r->particles[k].z); | ||
|
||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
run(0); | ||
run(512); | ||
} |