Skip to content

Commit

Permalink
Fix problem to use find.dt for restart files; Use appending mode of w…
Browse files Browse the repository at this point in the history
…riting as default, make -a as an argument option in petar; use __NONE__ as name for filename without given values
  • Loading branch information
lwang-astro committed Aug 8, 2020
1 parent 27026fd commit 0592d70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
12 changes: 6 additions & 6 deletions galpy-interface/galpy_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class IOParamsGalpy{
bool print_flag;

IOParamsGalpy(): input_par_store(),
type_args (input_par_store, "None", "Description of potential type and arguments"),
pre_define_type (input_par_store, "None", "Add additional Pre-defined potential type to the potential list, options are: MWPotential2014"),
config_filename(input_par_store, "None", "A configure file that store the types and arguments of potential, will be added to the potential list"),
type_args (input_par_store, "__NONE__", "Description of potential type and arguments"),
pre_define_type (input_par_store, "__NONE__", "Add additional Pre-defined potential type to the potential list, options are: MWPotential2014"),
config_filename(input_par_store, "__NONE__", "A configure file that store the types and arguments of potential, will be added to the potential list"),
rscale(input_par_store, 1.0, "Radius scale factor from unit of the input particle data (IN) to Galpy distance unit (r[Galpy]=r[IN]*rscale)"),
tscale(input_par_store, 1.0, "Time scale factor from unit of the input particle data (IN) to Galpy time (time[Galpy]=time[IN]*tscale)"),
vscale(input_par_store, 1.0, "Velocity scale factor from unit of the input particle data (IN) to Galpy velocity unit (v[Galpy]=v[IN]*vscale)"),
Expand Down Expand Up @@ -215,10 +215,10 @@ class GalpyManager{
// add pre-defined type-argu groups
std::string type_args = _input.type_args.value;
if (_input.pre_define_type.value=="MWPotential2014") {
if (type_args=="None") type_args="15:0.0299946,1.8,0.2375|5:0.7574802,0.375,0.035|9:4.85223053,2.0";
if (type_args=="__NONE__") type_args="15:0.0299946,1.8,0.2375|5:0.7574802,0.375,0.035|9:4.85223053,2.0";
else type_args += "|15:0.0299946,1.8,0.2375|5:0.7574802,0.375,0.035|9:4.85223053,2.0";
}
if (type_args=="None") type_args="";
if (type_args=="__NONE__") type_args="";

std::vector<std::string> type_args_pair;
std::vector<int> pot_type;
Expand Down Expand Up @@ -283,7 +283,7 @@ class GalpyManager{
npot = pot_type.size();

// add type arguments from configure file if exist
if (_input.config_filename.value!="None") {
if (_input.config_filename.value!="__NONE__") {
std::ifstream fin;
fin.open(_input.config_filename.value.c_str(), std::ifstream::in);
int nadd=0;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char *argv[]){

auto& inp = petar.input_parameters;

if (inp.fname_inp.value=="__Plummer"||inp.fname_inp.value=="") petar.generatePlummer();
if (inp.fname_inp.value=="__Plummer"||inp.fname_inp.value=="__NONE__") petar.generatePlummer();
//else if (inp.fname_inp.value!="__KeplerDisk") petar.generateKeplerDisk();
else petar.readDataFromFile();

Expand Down
27 changes: 15 additions & 12 deletions src/petar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ class IOParamsPeTar{
#ifdef ADJUST_GROUP_PRINT
IOParams<PS::S32> adjust_group_write_option;
#endif
IOParams<PS::S32> append_switcher;
IOParams<std::string> fname_snp;
IOParams<std::string> fname_par;
IOParams<std::string> fname_inp;

// flag
bool app_flag; // appending data flag
bool print_flag;

IOParamsPeTar(): input_par_store(),
Expand All @@ -166,7 +166,7 @@ class IOParamsPeTar{
eta (input_par_store, 0.1, "Hermite time step coefficient eta"),
gravitational_constant(input_par_store, 1.0, "Gravitational constant"),
unit_set (input_par_store, 0, "Input data unit, 0: unknown, referring to G; 1: mass:Msun, length:pc, time:Myr, velocity:pc/Myr"),
n_glb (input_par_store, 100000, "Total number of particles, only used to generate particles if needed"),
n_glb (input_par_store, 100000, "Total number of particles, only used to generate particles if no input datafile exists"),
id_offset (input_par_store, -1, "Starting id for artificial particles, total number of real particles must be always smaller than this","n_glb+1"),
dt_soft (input_par_store, 0.0, "Tree timestep","0.1*r_out/sigma_1D"),
dt_snap (input_par_store, 1.0, "Output time interval of particle dataset snapshot"),
Expand Down Expand Up @@ -205,10 +205,11 @@ class IOParamsPeTar{
#ifdef ADJUST_GROUP_PRINT
adjust_group_write_option(input_par_store, 1, "print new and end of groups: 0: no print; 1: print to file [data filename prefix].group.[MPI rank] if -w >0"),
#endif
append_switcher(input_par_store, 1, "data output style, 0: create new output files and overwrite existing ones except snapshots; 1: append new data to existing files"),
fname_snp(input_par_store, "data","Prefix filename of dataset: [prefix].[File ID]"),
fname_par(input_par_store, "input.par", "Input parameter file (this option should be used first before any other options)"),
fname_inp(input_par_store, "", "Input data file"),
app_flag(false), print_flag(false) {}
fname_inp(input_par_store, "__NONE__", "Input data file"),
print_flag(false) {}


//! reading parameters from GNU option API
Expand Down Expand Up @@ -414,8 +415,10 @@ class IOParamsPeTar{
opt_used += 2;
break;
case 'a':
app_flag=true;
opt_used ++;
append_switcher.value=atoi(optarg);
if(print_flag) append_switcher.print(std::cout);
assert(append_switcher.value>=0&&append_switcher.value<=1);
opt_used += 2;
break;
case 't':
time_end.value = atof(optarg);
Expand Down Expand Up @@ -514,7 +517,7 @@ class IOParamsPeTar{
std::cout<<" [formatted] indicates that the value is only for save, cannot be directly read"<<std::endl;
std::cout<<"Options: defaulted values are shown after ':'"<<std::endl;
std::cout<<" -i: [I] "<<data_format<<std::endl;
std::cout<<" -a: data output style (except snapshot) becomes appending, defaulted: replace"<<std::endl;
std::cout<<" -a: [I] "<<append_switcher<<std::endl;
std::cout<<" -t: [F] "<<time_end<<std::endl;
std::cout<<" -s: [F] "<<dt_soft<<std::endl;
std::cout<<" -o: [F] "<<dt_snap<<std::endl;
Expand Down Expand Up @@ -2326,7 +2329,7 @@ class PeTar {
// open profile file
if(write_style>0) {
std::string fproname=input_parameters.fname_snp.value+".prof.rank."+std::to_string(my_rank);
if(input_parameters.app_flag) fprofile.open(fproname.c_str(),std::ofstream::out|std::ofstream::app);
if(input_parameters.append_switcher.value==1) fprofile.open(fproname.c_str(),std::ofstream::out|std::ofstream::app);
else {
fprofile.open(fproname.c_str(),std::ofstream::out);

Expand All @@ -2353,7 +2356,7 @@ class PeTar {
// status information output
std::string& fname_snp = input_parameters.fname_snp.value;
if(write_style>0&&my_rank==0) {
if(input_parameters.app_flag)
if(input_parameters.append_switcher.value==1)
fstatus.open((fname_snp+".status").c_str(),std::ofstream::out|std::ofstream::app);
else {
fstatus.open((fname_snp+".status").c_str(),std::ofstream::out);
Expand All @@ -2371,7 +2374,7 @@ class PeTar {
// open escaper file
std::string my_rank_str = std::to_string(my_rank);
std::string fname_esc = fname_snp + ".esc." + my_rank_str;
if(input_parameters.app_flag)
if(input_parameters.append_switcher.value==1)
fesc.open(fname_esc.c_str(), std::ofstream::out|std::ofstream::app);
else {
fesc.open(fname_esc.c_str(), std::ofstream::out);
Expand All @@ -2385,7 +2388,7 @@ class PeTar {
// open SSE/BSE file
std::string fsse_name = fname_snp + ".sse." + my_rank_str;
std::string fbse_name = fname_snp + ".bse." + my_rank_str;
if(input_parameters.app_flag) {
if(input_parameters.append_switcher.value==1) {
hard_manager.ar_manager.interaction.fout_sse.open(fsse_name.c_str(), std::ofstream::out|std::ofstream::app);
hard_manager.ar_manager.interaction.fout_bse.open(fbse_name.c_str(), std::ofstream::out|std::ofstream::app);
}
Expand All @@ -2399,7 +2402,7 @@ class PeTar {
// open file for new/end group information
if (input_parameters.adjust_group_write_option.value==1) {
std::string fgroup_name = fname_snp + ".group." + my_rank_str;
if(input_parameters.app_flag)
if(input_parameters.append_switcher.value==1)
hard_manager.h4_manager.fgroup.open(fgroup_name.c_str(), std::ofstream::out|std::ofstream::app);
else
hard_manager.h4_manager.fgroup.open(fgroup_name.c_str(), std::ofstream::out);
Expand Down
6 changes: 4 additions & 2 deletions tools/find_dt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ fi

tperf_pre=1e10
tzero=`head -1 $fname|awk '{print $3}'`
echo 'time start: '$tzero
dt=$dt_base
dt_min=$dt
check_flag=true
tcum=10000 # sec
while [[ $check_flag == true ]]
do
dt=`echo $dt|awk '{OFMT="%.14g"; print $1*2.0}'`
tend=`echo $dt |awk -v tzero=$tzero '{print tzero+$1*6.01}' `
${prefix} timeout $tcum $pbin -w 0 -t $tend $opts -s $dt -o $dt $fname &>.check.perf.$dt.log
tend=`echo $dt |awk -v tzero=$tzero '{OFMT="%.14g"; print tzero+$1*6.01}' `
echo 'test ending time '$tend' dt '$dt
${prefix} timeout $tcum $pbin $opts -w 0 -t $tend -s $dt -o $dt $fname &>.check.perf.$dt.log
egrep 'Wallclock' -A 3 .check.perf.$dt.log |sed -n '/^\ *[0-9]/ p'|awk '{if (NR>1 && NR%2==0) print $1,$2+$3+$4+$8,$7+$9,$6+$10+$11,$12+$13}' >.check.perf.$dt.tperf
if [[ `wc -l .check.perf.$dt.tperf|awk '{print $1}'` -ge 6 ]]; then
dt_reg=`egrep dt_soft .check.perf.$dt.log|awk '{OFMT="%.14g"; print $3}'`
Expand Down

0 comments on commit 0592d70

Please sign in to comment.