Improved the new-style config file and its reader

This commit is contained in:
Yohai Meiron 2020-03-15 21:35:53 -04:00
parent 90f070d1fb
commit cd282cc406
3 changed files with 119 additions and 21 deletions

28
io.cpp
View file

@ -4,6 +4,16 @@
#include <iostream>
#include <fstream>
std::string strip(const std::string str)
{
std::string str_new = str;
auto pos = str_new.find_first_not_of(" \t");
if (pos != std::string::npos) str_new = str_new.substr(pos, str_new.size());
pos = str_new.find_last_not_of(" \t");
if (pos != std::string::npos) str_new = str_new.substr(0, pos+1);
return str_new;
}
int main()
{
std::unordered_map<std::string,std::string> dictionary;
@ -19,22 +29,22 @@ int main()
line_number++;
auto pos = str.find('#');
if (pos != std::string::npos) str = str.substr(0, pos);
pos = str.find_first_not_of(" \t");
if (pos != std::string::npos) str = str.substr(pos, str.size());
else continue;
pos = str.find_last_not_of(" \t");
if (pos != std::string::npos) str = str.substr(0, pos+1);
str = strip(str);
if (str.size() == 0) continue;
pos = str.find_first_of(" \t");
pos = str.find_first_of("=");
if (pos == std::string::npos) {
std::cerr << "Error: expected a key-value pair in line " << line_number << " of file " << file_name << std::endl;
exit(1);
}
std::string key = str.substr(0, pos);
std::string key = strip(str.substr(0, pos));
pos = str.find_first_not_of(" \t", pos+1);
std::string val = str.substr(pos, str.size());
std::string val = strip(str.substr(pos, str.size()));
dictionary[key] = val;
}
printf("dictionary[\"more\"] = %s\n", dictionary["eps"].c_str());
for (auto key_value : dictionary) {
auto key = key_value.first;
auto value = key_value.second;
printf("dictionary[\"%s\"] = \"%s\"\n", key.c_str(), value.c_str());
}
}

89
phigrape.conf Normal file
View file

@ -0,0 +1,89 @@
######################
# GENERAL PARAMETERS #
######################
# Plummer softening parameter (can be even 0)
eps = 1E-4
# End time of the calculation
t_end = 4.0
# Interval of snapshot files output (xxxxxx.dat)
dt_disk = 1.0
# Interval for the energy control output (contr.dat)
dt_contr = 0.125
# Interval for SMBH output (bh.dat, bh_neighbors.dat, and bh_inf.dat)
dt_bh = 0.125
# Parameter for timestep determination
eta = 0.01
# Name of the input file; use "data.con" in most cases
inp_data = data.con
##### NOT IMPLEMENTED #######################
output_format = HDF5
dt_min_warning = true
#############################################
###################################
# LIVE SUPERMASSIVE BLACK HOLE(S) #
###################################
# There is special treatment for particles representing supermassive black holes (SMBHs): they are integrated at every time step, they can have custom softening in SMBH-SMBH interactions, and post Newtonian terms can be added to the gravity.
# The number of SMBH particles. Can be 0 (no SMBH), 1, or 2. [default: 0]
live_smbh_count = 2
# Custom softening length for SMBH-SMBH interactions (can also be zero). If non-negative, the custom softening is applied. [default: -1]
live_smbh_custom_eps = 0
# Output additional diagnostics about live SMBHs. [default: false]
#TODO# dt_bh
live_smbh_output = true
# Output additional diagnostics about the SMBH's (or SMBHs') nearest neighbours (number could be set as shown below). [default: false]
live_smbh_neighbor_output = true
# Number of nearest neighbours to the SMBH (or SMBHs) to include in output. [default: 10]
live_smbh_neighbor_number = 10
##################################
# BINARY SUPERMASSIVE BLACK HOLE #
##################################
# The following parameters can be set when `live_smbh_count` is 2.
# Output additional diagnostics about the SMBH's sphere of influence (size could be set as shown below). [default: false]
binary_smbh_influence_sphere_output = true
# The influence sphere is centred at the binary SMBH's centre of mass, and its radius is the semi-major axis of the binary times the factor below. [default: 10.0]
binary_smbh_influence_radius_factor = 3.162277660168379497918067e+03
# Add post Newtonian terms to SMBH-SMBH gravity. [default: false]
binary_smbh_pn = true
####################################
# Negative powers of two #
####################################
# -1 1/2 0.5 #
# -2 1/4 0.25 #
# -3 1/8 0.125 #
# -4 1/16 0.0625 #
# -5 1/32 0.03125 #
# -6 1/64 0.015625 #
# -7 1/128 0.0078125 #
# -8 1/256 0.00390625 #
# -9 1/512 0.001953125 #
# -10 1/1024 0.0009765625 #
# -11 1/2048 0.00048828125 #
# -12 1/4096 0.000244140625 #
# -13 1/8192 0.0001220703125 #
# -14 1/16384 0.00006103515625 #
# -15 1/32768 0.000030517578125 #
# -16 1/65536 0.0000152587890625 #
####################################

View file

@ -63,7 +63,6 @@ struct Parameters {
double binary_smbh_influence_radius_factor = 3.162277660168379497918067e+03; // R_INF
int live_smbh_neighbor_number = 10; // TODO make sure it's smaller than N? or just warn if it's not
bool binary_smbh_pn = true; // ADD_PN_BH
bool binary_smbh_spin = true; // ADD_SPIN_BH
bool dt_min_warning = true; // DT_MIN_WARNING
} parameters;
@ -659,7 +658,7 @@ void write_bh_data()
{
if (parameters.live_smbh_count == 2) {
out = fopen("bh.dat","a");
out = fopen("bh.dat", "a");
for (int i=0; i < 2; i++) {
// double (*a_pn)[3], (*adot_pn)[3], pot_bh, *a_bh, *adot_bh;
@ -759,7 +758,7 @@ void write_bh_data()
fprintf(out,"\n");
fclose(out);
} else if (parameters.live_smbh_count == 1) {
out = fopen("bh.dat","a");
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]) );
tmp_a = sqrt( SQR(a[0][0]) + SQR(a[0][1]) + SQR(a[0][2]) );
@ -782,7 +781,7 @@ void write_bh_nb_data()
int i_bh, nb = parameters.live_smbh_neighbor_number;
double tmp, tmp_r, tmp_v;
out = fopen("bh_nb.dat", "a");
out = fopen("bh_neighbors.dat", "a");
/* 1st BH */
@ -1453,7 +1452,7 @@ void energy_contr()
fflush(stdout);
out = fopen("contr.dat","a");
out = fopen("contr.dat", "a");
fprintf(out,"%.8E \t %.8E %.8E %.8E \t % .8E % .8E % .8E % .8E % .8E \t % .8E % .8E \t % .8E % .8E % .8E \t %.8E %.8E %.8E \n",
time_cur, timesteps, n_act_sum, g6_calls,
E_pot, E_kin, E_pot_ext,
@ -1515,7 +1514,7 @@ int main(int argc, char *argv[])
t_end : end time of calculation
dt_disk : interval of snapshot files output (0xxx.dat)
dt_contr : interval for the energy control output (contr.dat)
dt_bh : interval for BH output (bh.dat & bh_nb.dat)
dt_bh : interval for BH output (bh.dat & bh_neighbors.dat)
eta : parameter for timestep determination
inp_data : name of the input file (data.inp)
*/
@ -1618,11 +1617,11 @@ int main(int argc, char *argv[])
fflush(stdout);
if ((diskstep == 0) && (time_cur == 0.0)) {
out = fopen("contr.dat","w");
out = fopen("contr.dat", "w");
fclose(out);
#ifdef TIMING
out = fopen("timing.dat","w");
out = fopen("timing.dat", "w");
fclose(out);
#endif
@ -1631,11 +1630,11 @@ int main(int argc, char *argv[])
fclose(out);
}
if ((parameters.live_smbh_neighbor_output) && (parameters.live_smbh_count > 0)) {
out = fopen("bh_nb.dat", "w");
out = fopen("bh_neighbors.dat", "w");
fclose(out);
}
if (parameters.binary_smbh_influence_sphere_output) {
out = fopen("bbh.inf","w");
out = fopen("bbh_inf.dat", "w");
fclose(out);
}
@ -2440,7 +2439,7 @@ int main(int argc, char *argv[])
if (parameters.binary_smbh_influence_sphere_output) {
if (myRank == rootRank) {
out = fopen("bbh.inf","a");
out = fopen("bbh_inf.dat", "a");
m_bh1 = m_act[i_bh1];
m_bh2 = m_act[i_bh2];
@ -2600,7 +2599,7 @@ int main(int argc, char *argv[])
/* possible OUT for timing !!! */
#ifdef TIMING
out = fopen("timing.dat","a");
out = fopen("timing.dat", "a");
DT_TOT = DT_ACT_DEF1 + DT_ACT_DEF2 + DT_ACT_DEF3 + DT_ACT_PRED +
DT_ACT_GRAV + DT_EXT_GRAV + DT_GMC_GRAV +