Skip to content

Commit 411ca13

Browse files
authored
Merge pull request #1086 from LourensVeen/issue-940-update-mpreal-h
Issue 940: update mpreal.h
2 parents 8f44615 + 4b6b016 commit 411ca13

File tree

12 files changed

+7517
-6477
lines changed

12 files changed

+7517
-6477
lines changed

src/amuse/community/adaptb/src/mpreal.h

Lines changed: 3377 additions & 3193 deletions
Large diffs are not rendered by default.

src/amuse/community/brutus/interface.cc

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Includes
33
////////////////////////////////////////////////////////
44
#include <iostream>
5-
using namespace std;
65

76
#include <fstream>
87
#include <cstdlib>
@@ -14,21 +13,21 @@ using namespace std;
1413
////////////////////////////////////////////////////////
1514
// Declare global variables
1615
////////////////////////////////////////////////////////
17-
ofstream odata;
16+
std::ofstream odata;
1817

1918
int particle_id_counter = 0;
2019

21-
int numBits = 64;
20+
int numBits = 64;
2221
int numDigits = numBits/4;
2322

24-
string out_directory;
23+
std::string out_directory;
2524
std::map<int, int> local_index_map;
2625

2726
/*
2827
* We need this result_strings array to ensure that
2928
* C++ strings are not reclaimed before the function ends
3029
*/
31-
string result_strings[10];
30+
std::string result_strings[10];
3231

3332
Brutus *brutus = NULL;
3433

@@ -38,15 +37,16 @@ mpreal t = "0";
3837

3938
mpreal epsilon = "1e-6"; // Bulirsch-Stoer tolerance
4039

41-
vector<mpreal> data, data_radius;
40+
std::vector<mpreal> data, data_radius;
4241

4342
////////////////////////////////////////////////////////
4443
// Amuse interface functions
4544
////////////////////////////////////////////////////////
45+
4646
int initialize_code() {
4747
odata.open("temp.log");
4848

49-
mpreal::set_default_prec(numBits);
49+
mpreal::set_default_prec(numBits);
5050

5151
brutus = new Brutus();
5252

@@ -62,7 +62,7 @@ int initialize_code() {
6262

6363
// functions with "_string" assign strings to mpreals, and without "_string" assign doubles to mpreals
6464

65-
int new_particle_string(int *particle_identifier, char* mass,
65+
int new_particle_string(int *particle_identifier, char* mass,
6666
char* x, char* y, char* z, char* vx, char* vy, char* vz, char* radius) {
6767

6868
data.push_back(mass);
@@ -80,7 +80,7 @@ int new_particle_string(int *particle_identifier, char* mass,
8080

8181
return 0;
8282
}
83-
int new_particle_float64(int *particle_identifier, double mass,
83+
int new_particle_float64(int *particle_identifier, double mass,
8484
double x, double y, double z, double vx, double vy, double vz, double radius) {
8585

8686
data.push_back( (mpreal)mass );
@@ -139,7 +139,7 @@ int get_begin_time(double * output) {
139139
// Timestep parameter, eta
140140
int set_eta_string(char* myeta) {
141141
eta = myeta;
142-
brutus->set_eta(eta);
142+
brutus->set_eta(eta);
143143
return 0;
144144
}
145145
int get_eta_string(char **myeta) {
@@ -200,12 +200,12 @@ int get_bs_tolerance_string(char **bs_tolerance) {
200200
}
201201
int set_bs_tolerance(double bs_tolerance) {
202202

203-
odata << t << ": changing e from " << epsilon << ", to " << bs_tolerance << endl;
203+
odata << t << ": changing e from " << epsilon << ", to " << bs_tolerance << std::endl;
204204

205205
epsilon = (mpreal) bs_tolerance;
206206
brutus->set_tolerance(epsilon);
207207

208-
odata << epsilon << " " << brutus->get_tolerance() << endl;
208+
odata << epsilon << " " << brutus->get_tolerance() << std::endl;
209209

210210
return 0;
211211
}
@@ -215,14 +215,14 @@ int get_bs_tolerance(double *bs_tolerance) {
215215
}
216216
// Word-length, numBits in mantissa
217217
int set_word_length(int mynumBits) {
218-
odata << t << ": changing L from " << numBits << ", to " << mynumBits << endl;
218+
odata << t << ": changing L from " << numBits << ", to " << mynumBits << std::endl;
219219

220220
numBits = mynumBits;
221221
mpreal::set_default_prec(numBits);
222222
numDigits = (int)abs(log10( pow("2.0", -numBits) )).toLong();
223223
brutus->set_numBits(numBits);
224224

225-
odata << numBits << " " << brutus->get_numBits() << endl;
225+
odata << numBits << " " << brutus->get_numBits() << std::endl;
226226

227227
return 0;
228228
}
@@ -263,7 +263,7 @@ int get_mass_string(int id, char **mass) {
263263
mass_string = data[id*7+0].toString();
264264
*mass = (char*) mass_string.c_str();
265265
return 0;
266-
}
266+
}
267267
int set_mass_string(int id, char *mass) {
268268
if (id < 0 || id >= particle_id_counter){
269269
return -1;
@@ -277,7 +277,7 @@ int get_mass(int id, double* mass) {
277277
}
278278
*mass = data[id*7+0].toDouble();
279279
return 0;
280-
}
280+
}
281281
int set_mass(int id, double mass) {
282282
if (id < 0 || id >= particle_id_counter){
283283
return -1;
@@ -379,7 +379,7 @@ std::string get_state_strings_vx;
379379
std::string get_state_strings_vy;
380380
std::string get_state_strings_vz;
381381
std::string get_state_strings_r;
382-
int get_state_string(int id, char** m, char** x, char** y, char** z, char** vx, char** vy, char** vz, char** radius) {
382+
int get_state_string(int id, char** m, char** x, char** y, char** z, char** vx, char** vy, char** vz, char** radius) {
383383
if (id < 0 || id >= particle_id_counter){
384384
return -1;
385385
}
@@ -445,7 +445,7 @@ int set_state(int id, double m, double x, double y, double z, double vx, double
445445
}
446446

447447
std::string radius_string;
448-
int get_radius_string(int id, char** radius){
448+
int get_radius_string(int id, char** radius){
449449
if (id < 0 || id >= particle_id_counter){
450450
return -1;
451451
}
@@ -460,7 +460,7 @@ int set_radius_string(int id, char* radius) {
460460
data_radius[id] = radius;
461461
return 0;
462462
}
463-
int get_radius(int id, double* radius){
463+
int get_radius(int id, double* radius){
464464
if (id < 0 || id >= particle_id_counter){
465465
return -1;
466466
}
@@ -523,7 +523,7 @@ int get_index_of_first_particle(int* id){return -2;}
523523
int get_index_of_next_particle(int id, int* idnext){return -2;}
524524

525525
std::string total_mass_string;
526-
int get_total_mass_string(char **M){
526+
int get_total_mass_string(char **M){
527527
int N = data.size()/7;
528528
mpreal Mtot = "0";
529529
for(int i=0; i<N; i++) {
@@ -534,7 +534,7 @@ int get_total_mass_string(char **M){
534534
return 0;
535535
}
536536

537-
int get_total_mass(double* M){
537+
int get_total_mass(double* M){
538538
int N = data.size()/7;
539539
mpreal Mtot = "0";
540540
for(int i=0; i<N; i++) {
@@ -564,7 +564,7 @@ int get_potential_energy_m(mpreal* ep) {
564564

565565
eptot -= mi*mj/sqrt(dr2);
566566
}
567-
}
567+
}
568568

569569
*ep = eptot;
570570
return 0;
@@ -608,8 +608,8 @@ int get_kinetic_energy_string( char **ep) {
608608
std::string total_energy_string;
609609

610610
int get_total_energy_string( char **ep) {
611-
mpreal ektot = "0";
612-
mpreal eptot = "0";
611+
mpreal ektot = "0";
612+
mpreal eptot = "0";
613613
mpreal etot = "0";
614614
get_potential_energy_m(&eptot);
615615
get_kinetic_energy_m(&ektot);
@@ -633,40 +633,40 @@ int get_kinetic_energy(double* ek) {
633633
return 0;
634634
}
635635

636-
int get_center_of_mass_position(double* x , double* y, double* z){
636+
int get_center_of_mass_position(double* x , double* y, double* z){
637637
int N = data.size()/7;
638638
mpreal Mtot = "0";
639639
for(int i=0; i<N; i++) {
640640
Mtot += data[i*7];
641641
}
642642

643-
vector<mpreal> rcm(3,"0");
643+
std::vector<mpreal> rcm(3,"0");
644644
for(int i=0; i<N; i++) {
645645
for(int j=0; j<3; j++) {
646646
rcm[j] += data[i*7]*data[i*7+(j+1)];
647647
}
648648
}
649-
for(int i=0; i<3; i++) rcm[i] /= Mtot;
649+
for(int i=0; i<3; i++) rcm[i] /= Mtot;
650650

651651
*x = rcm[0].toDouble();
652652
*y = rcm[1].toDouble();
653653
*z = rcm[2].toDouble();
654654
return 0;
655655
}
656-
int get_center_of_mass_velocity(double* vx, double* vy, double* vz){
656+
int get_center_of_mass_velocity(double* vx, double* vy, double* vz){
657657
int N = data.size()/7;
658658
mpreal Mtot = "0";
659659
for(int i=0; i<N; i++) {
660660
Mtot += data[i*7];
661661
}
662662

663-
vector<mpreal> vcm(3,"0");
663+
std::vector<mpreal> vcm(3,"0");
664664
for(int i=0; i<N; i++) {
665665
for(int j=0; j<3; j++) {
666666
vcm[j] += data[i*7]*data[i*7+(j+4)];
667667
}
668668
}
669-
for(int i=0; i<3; i++) vcm[i] /= Mtot;
669+
for(int i=0; i<3; i++) vcm[i] /= Mtot;
670670

671671
*vx = vcm[0].toDouble();
672672
*vy = vcm[1].toDouble();
@@ -675,3 +675,5 @@ int get_center_of_mass_velocity(double* vx, double* vy, double* vz){
675675
}
676676

677677
int get_acceleration(int id, double* ax, double* ay, double* az){return -2;}
678+
int set_acceleration(int id, double ax, double ay, double az){return -2;}
679+

0 commit comments

Comments
 (0)