Now config file handles most parameters (but not external potential)

This commit is contained in:
Yohai Meiron 2020-03-17 12:24:53 -04:00
parent bb9a343763
commit 9296db0609
6 changed files with 188 additions and 165 deletions

View file

@ -53,8 +53,8 @@ Coded by : Peter Berczik
Version number : 19.04
Last redaction : 2019.04.16 12:55
*****************************************************************************/
#include "phigrape.h"
Parameters parameters;
#include "config.h"
Config *config;
// struct Parameters {
// double eps = 1E-4;
@ -665,7 +665,7 @@ fclose(out);
void write_bh_data()
{
if (parameters.live_smbh_count == 2) {
if (config->live_smbh_count == 2) {
out = fopen("bh.dat", "a");
@ -693,12 +693,12 @@ void write_bh_data()
tmp_a = sqrt( SQR(a[i][0]) + SQR(a[i][1]) + SQR(a[i][2]) );
tmp_adot = sqrt( SQR(adot[i][0]) + SQR(adot[i][1]) + SQR(adot[i][2]) );
if (parameters.live_smbh_custom_eps >= 0) {
if (config->live_smbh_custom_eps >= 0) {
tmp_a_bh = sqrt( SQR(a_bh[0]) + SQR(a_bh[1]) + SQR(a_bh[2]) );
tmp_adot_bh = sqrt( SQR(adot_bh[0]) + SQR(adot_bh[1]) + SQR(adot_bh[2]) );
if (parameters.binary_smbh_spin) {
if (config->binary_smbh_pn) {
tmp_a_bh_pn0 = sqrt( SQR(a_pn[0][0]) + SQR(a_pn[0][1]) + SQR(a_pn[0][2]) );
tmp_a_bh_pn1 = sqrt( SQR(a_pn[1][0]) + SQR(a_pn[1][1]) + SQR(a_pn[1][2]) );
tmp_a_bh_pn2 = sqrt( SQR(a_pn[2][0]) + SQR(a_pn[2][1]) + SQR(a_pn[2][2]) );
@ -766,7 +766,7 @@ void write_bh_data()
}
fprintf(out,"\n");
fclose(out);
} else if (parameters.live_smbh_count == 1) {
} else if (config->live_smbh_count == 1) {
out = fopen("bh.dat", "a");
tmp_r = sqrt( SQR(x[0][0]) + SQR(x[0][1]) + SQR(x[0][2]) );
tmp_v = sqrt( SQR(v[0][0]) + SQR(v[0][1]) + SQR(v[0][2]) );
@ -787,7 +787,7 @@ void write_bh_data()
void write_bh_nb_data()
{
int i_bh, nb = parameters.live_smbh_neighbor_number;
int i_bh, nb = config->live_smbh_neighbor_number;
double tmp, tmp_r, tmp_v;
out = fopen("bh_neighbors.dat", "a");
@ -796,7 +796,7 @@ void write_bh_nb_data()
i_bh = 0;
for (int i_bh=0; i_bh < parameters.live_smbh_count; i_bh++) {
for (int i_bh=0; i_bh < config->live_smbh_count; i_bh++) {
for (i=0; i<N; i++) var_sort[i] = (x[i]-x[i_bh]).norm();
std::iota(ind_sort, ind_sort+N, 0);
std::partial_sort(ind_sort, ind_sort + nb, ind_sort + N, [&](int i, int j) {return var_sort[i] < var_sort[j];});
@ -1511,12 +1511,20 @@ int main(int argc, char *argv[])
/* read the input parameters to the rootRank */
if (myRank == rootRank) {
inp = fopen("phi-GRAPE.cfg","r");
fscanf(inp,"%lE %lE %lE %lE %lE %lE %s", &eps, &t_end, &dt_disk, &dt_contr, &dt_bh, &eta, inp_fname);
fclose(inp);
config = new Config("phigrape.conf");
if (parameters.binary_smbh_influence_sphere_output) for (i=0; i<N; i++) inf_event[i] = 0;
if (myRank == rootRank) {
//TODO move it out of (myRank == rootRank) so you don't need to communicate them.
eps = config->eps;
t_end = config->t_end;
dt_disk = config->dt_disk;
dt_contr = config->dt_contr;
dt_bh = config->dt_bh;
eta = config->eta;
strcpy(inp_fname, config->input_file_name.c_str());
if (config->binary_smbh_influence_sphere_output) for (i=0; i<N; i++) inf_event[i] = 0; // WARNING N wasn't set yet!
/*
eps : Plummer softening parameter (can be even 0)
@ -1634,15 +1642,15 @@ int main(int argc, char *argv[])
fclose(out);
#endif
if (parameters.live_smbh_output && (parameters.live_smbh_count > 0)) {
if (config->live_smbh_output && (config->live_smbh_count > 0)) {
out = fopen("bh.dat", "w");
fclose(out);
}
if ((parameters.live_smbh_neighbor_output) && (parameters.live_smbh_count > 0)) {
if ((config->live_smbh_neighbor_output) && (config->live_smbh_count > 0)) {
out = fopen("bh_neighbors.dat", "w");
fclose(out);
}
if (parameters.binary_smbh_influence_sphere_output) {
if (config->binary_smbh_influence_sphere_output) {
out = fopen("bbh_inf.dat", "w");
fclose(out);
}
@ -1872,11 +1880,11 @@ int main(int argc, char *argv[])
/* Wait to all processors to finish his works... */
MPI_Barrier(MPI_COMM_WORLD);
if (parameters.live_smbh_count == 2) {
if (config->live_smbh_count == 2) {
i_bh1 = 0;
i_bh2 = 1;
if (parameters.live_smbh_custom_eps >= 0) {
if (config->live_smbh_custom_eps >= 0) {
m_bh1 = m[i_bh1];
m_bh2 = m[i_bh2];
@ -1912,7 +1920,7 @@ int main(int argc, char *argv[])
tmp_i = calc_force_n_BH(m_bh1, x_bh1, v_bh1,
m_bh2, x_bh2, v_bh2,
parameters.live_smbh_custom_eps,
config->live_smbh_custom_eps,
&pot_bh1, a_bh1, adot_bh1,
&pot_bh2, a_bh2, adot_bh2);
@ -1928,7 +1936,7 @@ int main(int argc, char *argv[])
}
}
if (parameters.binary_smbh_pn) {
if (config->binary_smbh_pn) {
// calculate and "plus" the new BH <-> BH : PN1, PN2, PN2.5, PN3, PN3.5 : acc, jerk
@ -2028,7 +2036,7 @@ int main(int argc, char *argv[])
dt[i] = dt_tmp;
if (parameters.dt_min_warning && (myRank == 0)) {
if (config->dt_min_warning && (myRank == 0)) {
if (dt[i] == dt_min) {
printf("!!! Warning0: dt = dt_min = %.6E \t ind = %07d \n", dt[i], ind[i]);
fflush(stdout);
@ -2037,9 +2045,9 @@ int main(int argc, char *argv[])
} /* i */
if (parameters.live_smbh_count > 0) {
if (config->live_smbh_count > 0) {
double min_dt = *std::min_element(dt, dt+N);
for (int i=0; i<parameters.live_smbh_count; i++) dt[i] = min_dt;
for (int i=0; i<config->live_smbh_count; i++) dt[i] = min_dt;
}
/* Wait to all processors to finish his works... */
@ -2067,10 +2075,10 @@ int main(int argc, char *argv[])
if (myRank == rootRank) {
/* Write BH data... */
if (parameters.live_smbh_output) write_bh_data();
if (config->live_smbh_output) write_bh_data();
/* Write BH NB data... */
if (parameters.live_smbh_neighbor_output) write_bh_nb_data();
if (config->live_smbh_neighbor_output) write_bh_nb_data();
} /* if (myRank == rootRank) */
@ -2207,7 +2215,7 @@ int main(int argc, char *argv[])
exit(1);
}
#else
if (parameters.live_smbh_count > 0) {
if (config->live_smbh_count > 0) {
i_bh1 = 0;
i_bh2 = 1;
}
@ -2288,8 +2296,8 @@ int main(int argc, char *argv[])
DT_ACT_REDUCE += (CPU_tmp_user - CPU_tmp_user0);
#endif
if (parameters.live_smbh_count == 2) {
if (parameters.live_smbh_custom_eps >= 0) {
if (config->live_smbh_count == 2) {
if (config->live_smbh_custom_eps >= 0) {
m_bh1 = m_act[i_bh1];
m_bh2 = m_act[i_bh2];
@ -2320,7 +2328,7 @@ int main(int argc, char *argv[])
tmp_i = calc_force_n_BH(m_bh1, x_bh1, v_bh1,
m_bh2, x_bh2, v_bh2,
parameters.live_smbh_custom_eps,
config->live_smbh_custom_eps,
&pot_bh1, a_bh1, adot_bh1,
&pot_bh2, a_bh2, adot_bh2);
@ -2334,7 +2342,7 @@ int main(int argc, char *argv[])
adot_act_new[i_bh2] += adot_bh2;
}
if (parameters.binary_smbh_pn) {
if (config->binary_smbh_pn) {
// calculate and "plus" the new BH <-> BH : PN1, PN2, PN2.5, PN3, PN3.5 : acc, jerk
dt_bh_tmp = dt[0];
@ -2400,7 +2408,7 @@ int main(int argc, char *argv[])
a2dot1abs = a2dot1.norm();
a3dot1abs = a3.norm();
if ((parameters.live_smbh_count > 0) && (ind_act[i] < parameters.live_smbh_count))
if ((config->live_smbh_count > 0) && (ind_act[i] < config->live_smbh_count))
dt_new = sqrt(eta_bh*(a1abs*a2dot1abs+adot1abs*adot1abs)/(adot1abs*a3dot1abs+a2dot1abs*a2dot1abs));
else
dt_new = sqrt(eta*(a1abs*a2dot1abs+adot1abs*adot1abs)/(adot1abs*a3dot1abs+a2dot1abs*a2dot1abs));
@ -2428,7 +2436,7 @@ int main(int argc, char *argv[])
a_act[i] = a_act_new[i];
adot_act[i] = adot_act_new[i];
if (parameters.dt_min_warning && (myRank == 0)) {
if (config->dt_min_warning && (myRank == 0)) {
if (dt_act[i] == dt_min) {
printf("!!! Warning1: dt_act = dt_min = %.6E \t ind_act = %07d \n", dt[i], ind_act[i]);
fflush(stdout);
@ -2439,13 +2447,13 @@ int main(int argc, char *argv[])
/* define the min. dt over all the act. part. and set it also for the BH... */
if (parameters.live_smbh_count > 0) {
if (config->live_smbh_count > 0) {
double min_dt = *std::min_element(dt_act, dt_act+n_act);
if (parameters.live_smbh_count>=1) dt_act[i_bh1] = min_dt;
if (parameters.live_smbh_count==2) dt_act[i_bh2] = min_dt;
if (config->live_smbh_count>=1) dt_act[i_bh1] = min_dt;
if (config->live_smbh_count==2) dt_act[i_bh2] = min_dt;
}
if (parameters.binary_smbh_influence_sphere_output) {
if (config->binary_smbh_influence_sphere_output) {
if (myRank == rootRank) {
out = fopen("bbh_inf.dat", "a");
@ -2476,7 +2484,7 @@ int main(int argc, char *argv[])
iii = ind_act[i];
if (tmp_r2 < SEMI_a2*SQR(parameters.binary_smbh_influence_radius_factor)) {
if (tmp_r2 < SEMI_a2*SQR(config->binary_smbh_influence_radius_factor)) {
if (inf_event[iii] == 0) {
@ -2586,10 +2594,10 @@ int main(int argc, char *argv[])
if (time_cur >= t_bh) {
if (myRank == rootRank) {
/* Write BH data... */
if (parameters.live_smbh_output) write_bh_data();
if (config->live_smbh_output) write_bh_data();
/* Write BH NB data... */
if (parameters.live_smbh_neighbor_output) write_bh_nb_data();
if (config->live_smbh_neighbor_output) write_bh_nb_data();
} /* if (myRank == rootRank) */