Skip to content

Commit 301fdfa

Browse files
committed
Update rebound interface to Rebound release version 4.0.1
1 parent 47af808 commit 301fdfa

4 files changed

Lines changed: 225 additions & 120 deletions

File tree

src/amuse/community/rebound/Makefile

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,37 @@ OBJS = interface.o
2020

2121
CODELIB = src/librebound.a
2222
CODEDIR = src/rebound
23-
LIB_OBJ = $(CODEDIR)/src/rebound.o $(CODEDIR)/src/tree.o $(CODEDIR)/src/particle.o $(CODEDIR)/src/gravity.o \
24-
$(CODEDIR)/src/integrator.o $(CODEDIR)/src/integrator_whfast.o $(CODEDIR)/src/integrator_whfasthelio.o \
25-
$(CODEDIR)/src/integrator_ias15.o $(CODEDIR)/src/integrator_sei.o $(CODEDIR)/src/integrator_leapfrog.o \
26-
$(CODEDIR)/src/integrator_hermes.o $(CODEDIR)/src/boundary.o \
27-
$(CODEDIR)/src/collision.o $(CODEDIR)/src/tools.o \
28-
$(CODEDIR)/src/communication_mpi.o $(CODEDIR)/src/display.o $(CODEDIR)/src/derivatives.o \
29-
$(CODEDIR)/src/glad.o $(CODEDIR)/src/integrator_janus.o $(CODEDIR)/src/transformations.o \
30-
$(CODEDIR)/src/simulationarchive.o $(CODEDIR)/src/output.o \
31-
$(CODEDIR)/src/input.o \
23+
LIB_OBJ = \
24+
$(CODEDIR)/src/rebound.o \
25+
$(CODEDIR)/src/tree.o \
26+
$(CODEDIR)/src/particle.o \
27+
$(CODEDIR)/src/gravity.o \
28+
$(CODEDIR)/src/integrator.o \
29+
$(CODEDIR)/src/integrator_whfast.o \
30+
$(CODEDIR)/src/integrator_whfast512.o \
31+
$(CODEDIR)/src/integrator_saba.o \
32+
$(CODEDIR)/src/integrator_ias15.o \
33+
$(CODEDIR)/src/integrator_sei.o \
34+
$(CODEDIR)/src/integrator_bs.o \
35+
$(CODEDIR)/src/integrator_leapfrog.o \
36+
$(CODEDIR)/src/integrator_mercurius.o \
37+
$(CODEDIR)/src/integrator_eos.o \
38+
$(CODEDIR)/src/boundary.o \
39+
$(CODEDIR)/src/input.o \
40+
$(CODEDIR)/src/binarydiff.o \
41+
$(CODEDIR)/src/output.o \
42+
$(CODEDIR)/src/collision.o \
43+
$(CODEDIR)/src/communication_mpi.o \
44+
$(CODEDIR)/src/display.o \
45+
$(CODEDIR)/src/tools.o \
46+
$(CODEDIR)/src/rotations.o \
47+
$(CODEDIR)/src/derivatives.o \
48+
$(CODEDIR)/src/simulationarchive.o \
49+
$(CODEDIR)/src/glad.o \
50+
$(CODEDIR)/src/integrator_janus.o \
51+
$(CODEDIR)/src/transformations.o \
52+
$(CODEDIR)/src/fmemopen.o \
53+
$(CODEDIR)/src/server.o
3254

3355
DOWNLOAD_FROM_WEB = $(PYTHON) ./download.py
3456
PATCH_FILES = $(PYTHON) ./patch_files.py
@@ -39,25 +61,8 @@ AM_CFLAGS = -I$(AMUSE_DIR)/lib/amuse_mpi
3961

4062
all: rebound_worker
4163

42-
DOWNLOAD_CODES?=1
43-
44-
ifdef DOWNLOAD_CODES
4564
$(CODEDIR)/Makefile:
4665
make -C . download
47-
else
48-
$(CODEDIR)/Makefile:
49-
@echo ""
50-
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
51-
@echo ""
52-
@echo "DOWNLOAD_CODES is not set. Rebound will not be downloaded and built."
53-
@echo "If you do want Rebound, set DOWNLOAD_CODES to 1."
54-
@echo "bash> export DOWNLOAD_CODES=1"
55-
@echo "csh> setenv DOWNLOAD_CODES 1"
56-
@echo ""
57-
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
58-
@echo ""
59-
@make -s --no-print-directory -C . raise_error
60-
endif
6166

6267
download:
6368
$(RM) -Rf .pc
@@ -85,7 +90,7 @@ distclean:
8590
$(RM) -Rf .pc
8691

8792
$(CODELIB): $(CODEDIR)/Makefile
88-
make -C $(CODEDIR) all CC=$(CC)
93+
make -C $(CODEDIR) librebound CC=$(CC)
8994
ar rv $(CODELIB) $(LIB_OBJ)
9095
ranlib $(CODELIB)
9196

src/amuse/community/rebound/download.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,91 @@
22

33
import subprocess
44
import os
5-
import sys
6-
import time
5+
import argparse
76
import urllib.request
87
import urllib.parse
98
import urllib.error
10-
from optparse import OptionParser
9+
from shutil import which
1110

1211

13-
class GetCodeFromHttp(object):
14-
url_template = "https://github.com/hannorein/rebound/archive/{version}.tar.gz"
12+
class GetCodeFromHttp:
1513
filename_template = "{version}.tar.gz"
16-
version = ""
14+
name = ["rebound"]
15+
url_template = [
16+
"https://github.com/hannorein/rebound/archive/{version}.tar.gz"
17+
]
18+
version = [
19+
"",
20+
]
1721

1822
def directory(self):
1923
return os.path.abspath(os.path.dirname(__file__))
2024

2125
def src_directory(self):
2226
return os.path.join(self.directory(), "src")
2327

24-
def unpack_downloaded_file(self, filename):
25-
print("unpacking", filename)
28+
def unpack_downloaded_file(self, filename, name, version):
29+
print(f"unpacking {filename}")
2630
arguments = ["tar", "-xf"]
2731
arguments.append(filename)
2832
subprocess.call(arguments, cwd=os.path.join(self.src_directory()))
2933
subprocess.call(
30-
["mv", "rebound-{version}".format(version=self.version), "rebound"],
34+
["mv", f"{name}-{version}", name],
3135
cwd=os.path.join(self.src_directory()),
3236
)
3337
print("done")
3438

3539
def start(self):
3640
if os.path.exists("src"):
3741
counter = 0
38-
while os.path.exists("src.{0}".format(counter)):
42+
while os.path.exists(f"src.{counter}"):
3943
counter += 1
4044
if counter > 100:
4145
print("too many backup directories")
4246
break
43-
os.rename("src", "src.{0}".format(counter))
47+
os.rename("src", f"src.{counter}")
4448

4549
os.mkdir("src")
4650

47-
url = self.url_template.format(version=self.version)
48-
filename = self.filename_template.format(version=self.version)
49-
filepath = os.path.join(self.src_directory(), filename)
50-
print("downloading version", self.version, "from", url, "to", filename)
51-
urllib.request.urlretrieve(url, filepath)
52-
print("downloading finished")
53-
self.unpack_downloaded_file(filename)
51+
for i, url_template in enumerate(self.url_template):
52+
url = url_template.format(version=self.version[i])
53+
filename = self.filename_template.format(version=self.version[i])
54+
filepath = os.path.join(self.src_directory(), filename)
55+
print(f"downloading version {self.version[i]} from {url} to {filename}")
56+
if which("wget") is not None:
57+
arguments = ["wget", url]
58+
subprocess.call(arguments, cwd=os.path.join(self.src_directory()))
59+
elif which("curl") is not None:
60+
arguments = ["curl", "-L", "-O", url]
61+
subprocess.call(arguments, cwd=os.path.join(self.src_directory()))
62+
else:
63+
urllib.request.urlretrieve(url, filepath)
64+
print("downloading finished")
65+
self.unpack_downloaded_file(filename, self.name[i], self.version[i])
66+
67+
68+
def new_argument_parser():
69+
result = argparse.ArgumentParser()
70+
result.add_argument(
71+
"--rebound-version",
72+
default="111bcd50de54e4cc70e1d4915918226a4adbe188",
73+
# default="4df2b4603058e7d767aee9c26b586b55a5f4de65",
74+
dest="rebound_version",
75+
help="Rebound commit hash to download",
76+
type=str,
77+
)
78+
return result
5479

5580

5681
def main(version=""):
82+
arguments = new_argument_parser().parse_args()
83+
version = [
84+
arguments.rebound_version,
85+
]
5786
instance = GetCodeFromHttp()
5887
instance.version = version
5988
instance.start()
6089

6190

62-
def new_option_parser():
63-
result = OptionParser()
64-
result.add_option(
65-
"--version",
66-
default="31d117bdc92182073d0941c331f76e95f515bfc6",
67-
dest="version",
68-
help="version number to download",
69-
type="string",
70-
)
71-
return result
72-
73-
7491
if __name__ == "__main__":
75-
options, arguments = new_option_parser().parse_args()
76-
main(**options.__dict__)
92+
main()

src/amuse/community/rebound/interface.cc

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static inline particle_location get_particle_from_identity(int index_of_the_part
7171
for( ReboundSimulationVector::iterator i = codes.begin(); i != codes.end(); i++) {
7272
code_state cs = *i;
7373
particle.code = cs.code;
74-
particle.p = reb_get_particle_by_hash(particle.code, index_of_the_particle);
74+
particle.p = reb_simulation_particle_by_hash(particle.code, index_of_the_particle);
7575
if (particle.p != NULL) break;
7676
//*i = cs;
7777
}
@@ -124,7 +124,7 @@ int set_mass(int index_of_the_particle, double mass){
124124

125125
if(p->m==0){
126126
if(mass>0){
127-
int index_old=reb_get_particle_index(p);
127+
int index_old=reb_simulation_particle_index(p);
128128
if(index_old!=code->N_active){
129129
struct reb_particle tmp = code->particles[index_old];
130130
for(int j=index_old; j>code->N_active; j--){
@@ -137,7 +137,7 @@ int set_mass(int index_of_the_particle, double mass){
137137
}
138138
else {
139139
if(mass==0){
140-
int index_old=reb_get_particle_index(p);
140+
int index_old=reb_simulation_particle_index(p);
141141
code->N_active--;
142142

143143
if(index_old!=code->N_active){
@@ -178,7 +178,7 @@ int new_particle(int * index_of_the_particle, double mass, double x,
178178
pt.m = mass;
179179
pt.r = radius;
180180
pt.hash = new_hash;
181-
reb_add(codes[code_index].code, pt);
181+
reb_simulation_add(codes[code_index].code, pt);
182182
//std::cout<<"new particle :"<<pt.id<< " << "<<code_index<<" << "<<pt.x<<std::endl;
183183
*index_of_the_particle = new_hash;
184184

@@ -275,10 +275,10 @@ int _evolve_code(double _tmax, code_state * cs){
275275
return(1);
276276
}
277277

278-
reb_step(code); // 0 to not do timing within step
278+
reb_simulation_step(code); // 0 to not do timing within step
279279

280280
if ((code->t+code->dt)*dtsign>=tmax*dtsign && exact_finish_time==1){
281-
reb_integrator_synchronize(code);
281+
reb_simulation_synchronize(code);
282282
code->dt = tmax-code->t;
283283
last_step++;
284284
}else{
@@ -383,7 +383,7 @@ int _evolve_code(double _tmax, code_state * cs){
383383
}
384384
}
385385
}
386-
reb_integrator_synchronize(code);
386+
reb_simulation_synchronize(code);
387387
code->dt = code->dt_last_done;
388388
get_kinetic_energy(cs->subset, &ke1);
389389
//printf("Code time: %d , %f -> %f (%f,%f)\n",cs->subset , code->t, tmax, ke1, (ke1-ke)/ke);
@@ -437,7 +437,7 @@ int _delete_particle(int index_of_the_particle, int code_index){
437437
if(code_index < 0 || code_index >= (signed) codes.size()){
438438
return -10;
439439
}
440-
reb_remove_by_hash(codes[code_index].code, index_of_the_particle, keepSorted);
440+
reb_simulation_remove_particle_by_hash(codes[code_index].code, index_of_the_particle, keepSorted);
441441
return 0;
442442
}
443443

@@ -495,7 +495,7 @@ int get_state(int index_of_the_particle, double * mass, double * x,
495495
#endif // COLLISIONS_NONE
496496
for( ReboundSimulationVector::iterator i = codes.begin(); i != codes.end(); i++) {
497497
code_state cs = *i;
498-
p = reb_get_particle_by_hash(cs.code, index_of_the_particle);
498+
p = reb_simulation_particle_by_hash(cs.code, index_of_the_particle);
499499
if (p != NULL) {
500500
*subset = cs.subset;
501501
break;
@@ -608,7 +608,7 @@ int get_subset(int index_of_the_particle, int * subset){
608608
struct reb_particle* p=NULL;
609609
for( ReboundSimulationVector::iterator i = codes.begin(); i != codes.end(); i++) {
610610
code_state cs = *i;
611-
p = reb_get_particle_by_hash(cs.code, index_of_the_particle);
611+
p = reb_simulation_particle_by_hash(cs.code, index_of_the_particle);
612612
if (p != NULL) {
613613
*subset = cs.subset;
614614
break;
@@ -638,7 +638,7 @@ int set_subset(int index_of_the_particle, int subset){
638638
struct reb_particle* p=NULL;
639639
for( ReboundSimulationVector::iterator i = codes.begin(); i != codes.end(); i++) {
640640
code_state cs = *i;
641-
p = reb_get_particle_by_hash(cs.code, index_of_the_particle);
641+
p = reb_simulation_particle_by_hash(cs.code, index_of_the_particle);
642642
if (p != NULL) {
643643
if(cs.subset != subset) {return -2;}
644644
break;
@@ -653,8 +653,8 @@ int cleanup_code() {
653653
for( ReboundSimulationVector::iterator i = codes.begin(); i != codes.end(); i++) {
654654
code_state cs = *i;
655655
if(cs.code){
656-
reb_remove_all(cs.code);
657-
reb_free_simulation(cs.code);
656+
reb_simulation_remove_all_particles(cs.code);
657+
reb_simulation_free(cs.code);
658658
cs.code = 0;
659659
*i = cs;
660660
}
@@ -679,7 +679,7 @@ int initialize_code(){
679679
int nt = omp_get_max_threads();
680680
omp_set_num_threads(nt);
681681
#endif
682-
reb_simulation * code = reb_create_simulation();
682+
reb_simulation * code = reb_simulation_create();
683683
codes.push_back(code_state(code));
684684
code->integrator = reb_simulation::REB_INTEGRATOR_IAS15;
685685
code->N_active = 0;
@@ -789,8 +789,8 @@ int set_velocity(int index_of_the_particle, double vx, double vy,
789789
}
790790

791791
int new_subset(int * index, double time_offset) {
792-
reb_simulation * code = reb_create_simulation();
793-
reb_integrator_reset(code);
792+
reb_simulation * code = reb_simulation_create();
793+
reb_simulation_reset_integrator(code);
794794
code->dt = timestep;
795795
if(time_offset < 0) {time_offset = _time;}
796796
code->integrator = reb_simulation::REB_INTEGRATOR_IAS15;
@@ -811,8 +811,8 @@ int stop_subset(int code_index) {
811811
code_state cs = codes[code_index];
812812
if(cs.code) {
813813
reb_simulation * code = cs.code;
814-
reb_remove_all(code);
815-
reb_free_simulation(code);
814+
reb_simulation_remove_all_particles(code);
815+
reb_simulation_free(code);
816816
cs.code = 0;
817817
codes[code_index] = cs;
818818
}
@@ -845,17 +845,34 @@ int _set_integrator(int value, int code_index){
845845
code->integrator = reb_simulation::REB_INTEGRATOR_LEAPFROG;
846846
break;
847847
case 5:
848-
code->integrator = reb_simulation::REB_INTEGRATOR_HERMES;
848+
// This integrator was removed
849+
return -1;
849850
break;
850851
case 6:
851-
code->integrator = reb_simulation::REB_INTEGRATOR_WHFASTHELIO;
852+
// This integrator was removed
853+
return -1;
852854
break;
853855
case 7:
854856
code->integrator = reb_simulation::REB_INTEGRATOR_NONE;
855857
break;
856858
case 8:
857859
code->integrator = reb_simulation::REB_INTEGRATOR_JANUS;
858860
break;
861+
case 9:
862+
code->integrator = reb_simulation::REB_INTEGRATOR_WHFAST512;
863+
break;
864+
case 10:
865+
code->integrator = reb_simulation::REB_INTEGRATOR_SABA;
866+
break;
867+
case 11:
868+
code->integrator = reb_simulation::REB_INTEGRATOR_MERCURIUS;
869+
break;
870+
case 12:
871+
code->integrator = reb_simulation::REB_INTEGRATOR_EOS;
872+
break;
873+
case 13:
874+
code->integrator = reb_simulation::REB_INTEGRATOR_BS;
875+
break;
859876
default:
860877
code->integrator = reb_simulation::REB_INTEGRATOR_NONE;
861878
return -1;
@@ -1014,7 +1031,7 @@ int set_boundary_size(double boundary_size, int code_index){
10141031
return -11;
10151032
}
10161033
reb_simulation * code = codes[code_index].code;
1017-
reb_configure_box(code,boundary_size,1,1,1);
1034+
reb_simulation_configure_box(code,boundary_size,1,1,1);
10181035
return 0;
10191036
}
10201037

0 commit comments

Comments
 (0)