diff --git a/phigrape.cpp b/phigrape.cpp index 1d18693..2976c59 100644 --- a/phigrape.cpp +++ b/phigrape.cpp @@ -163,7 +163,7 @@ public: { ind_act_loc.resize(n_loc); } - double get_minimum_time(const std::vector &t, std::vector &dt) + double get_minimum_time(const std::vector &t, const std::vector &dt) { double min_t_loc, min_t; #ifdef ETICS @@ -249,6 +249,29 @@ inline double aarseth_step(const double eta, const double dt, const double3 &a, return sqrt(eta*(a1abs*a2dot1abs+adot1abs*adot1abs)/(adot1abs*a3dot1abs+a2dot1abs*a2dot1abs)); } +inline double blockize_step(double dt, double dt_prev, double min_t, double dt_min, double dt_max) +{ + double dt_new = dt_prev; + if (dt < dt_min) dt_prev = dt_min; + if ((dt < dt_prev) && (dt > dt_min)) { + int power = log(dt)/M_LN2 - 1; + dt_new = pow(2.0, power); + } + if ((dt > 2*dt_new) && (fmod(min_t, 2*dt_new) == 0) && (2*dt_new <= dt_max)) dt_new *= 2; + return dt_new; +} + +inline void predictor(double min_t, const int n_act, const std::vector &ind_act, const std::vector &t, const std::vector &x, const std::vector &v, const std::vector &a, const std::vector &adot, std::vector &x_act_new, std::vector &v_act_new) +{ + for (int i=0; i0)) { int act_def_grapite_bh_count = 0; @@ -537,14 +562,7 @@ int main(int argc, char *argv[]) #endif /* predict the active particles positions etc... on all the nodes */ - for (int i=0; i 0) && (ind_act[i] < config.live_smbh_count)) eta_curr = config.eta/config.eta_bh_corr; else eta_curr = config.eta; - double dt_new = aarseth_step(eta_curr, dt_tmp, a_act_new[i], adot_act_new[i], a2, a3); + double dt_new = aarseth_step(eta_curr, dt_cur, a_act_new[i], adot_act_new[i], a2, a3); - //TODO the below should be moved to a function - if (dt_new < dt_min) dt_tmp = dt_min; - if ((dt_new < dt_tmp) && (dt_new > dt_min)) { - int power = log(dt_new)/log(2.0) - 1; - dt_tmp = pow(2.0, (double)power); // TODO why is this casting needed here? - } - - if ((dt_new > 2*dt_tmp) && (fmod(min_t, 2*dt_tmp) == 0) && (2*dt_tmp <= dt_max)) { - dt_tmp *= 2; - } + dt_new = blockize_step(dt_new, dt_cur, min_t, dt_min, dt_max); if (config.dt_min_warning && (myRank == 0)) { - if (dt_tmp == dt_min) { - printf("!!! Warning1: dt_act = dt_min = %.6E \t ind_act = %07d time_cur=%.16E\n", dt_tmp, ind_act[i], time_cur); + if (dt_new == dt_min) { + printf("!!! Warning1: dt_act = dt_min = %.6E \t ind_act = %07d time_cur=%.16E\n", dt_cur, ind_act[i], time_cur); fflush(stdout); } } - if (dt_tmp < min_dt) min_dt = dt_tmp; + if (dt_new < min_dt) min_dt = dt_new; x[j_act] = x_act_new[i]; v[j_act] = v_act_new[i]; t[j_act] = min_t; - dt[j_act] = dt_tmp; + dt[j_act] = dt_new; pot[j_act] = pot_act_new[i]; pot_ext[j_act] = pot_act_ext[i]; a[j_act] = a_act_new[i]; @@ -614,10 +623,8 @@ int main(int argc, char *argv[]) if (config.live_smbh_count==2) dt[1] = min_dt; } - if (config.binary_smbh_influence_sphere_output && (myRank == rootRank)) { - //TODO clean up this mass. We don't want to have all these _act arrays; they are only needed for this lame function. + if (config.binary_smbh_influence_sphere_output && (myRank == rootRank)) binary_smbh_influence_sphere_output(ind_act, n_act, timesteps, time_cur); - } /* load the new values for active particles to the local GRAPE's */ for (int i=0; i