Paramotopy
parallel parameter homotopy through bertini
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
step1_funcs.cpp
Go to the documentation of this file.
1 #include "step1_funcs.hpp"
2 
3 
4 
5 void CallBertiniStep1(ProgSettings paramotopy_settings,
6  runinfo paramotopy_info){
7 
8  boost::filesystem::path startingfolder = boost::filesystem::current_path();//stackoverflow_getcwd(); //get the current directory
9 
10  boost::filesystem::path runfolder;
11  runfolder = paramotopy_info.location;
12  runfolder /= "step1";
13 
14  chdir(runfolder.c_str());
15 
16 
17  std::stringstream command;
18  if (paramotopy_settings.settings["parallelism"]["parallel"].intvalue==1) {
19  command << paramotopy_settings.settings["parallelism"]["architecture"].value() << " ";
20  if (paramotopy_settings.settings["parallelism"]["usemachine"].intvalue==1){
21  std::string homedir = getenv("HOME");
22  homedir.append("/");
23 
24 
25  command << " -machinefile "
26  << homedir
27  << paramotopy_settings.settings["parallelism"]["machinefile"].value()
28  << " ";
29  }
30  command << " -n " << paramotopy_settings.settings["parallelism"]["numprocs"].value();
31 
32  command << " " << paramotopy_settings.settings["system"]["bertinilocation"].value() << "/bertini";
33  }
34  else{
35 
36  command << " " << paramotopy_settings.settings["system"]["bertinilocation"].value() << "/bertini";
37  }
38 
39  std::cout << command.str().c_str() << std::endl;
40  system(command.str().c_str());
41 
42  chdir(startingfolder.c_str()); // return to the initial folder
43  return;
44 }
45 
46 
47 
48 
49 
50 
51 
52 //creates a step 1 input file for bertini, from the parsed paramotopy input file and saves preferences settings.
53 //prints results to screen and to a file
54 void WriteStep1(ProgSettings paramotopy_settings,
55  runinfo paramotopy_info){
56 
57 
58  std::string config = paramotopy_settings.WriteConfigStepOne();
59  std::string input = paramotopy_info.WriteInputStepOne(paramotopy_settings);
60 
61 
62 
63  boost::filesystem::path fname2 = paramotopy_info.location;
64  fname2 /= "step1/input";
65 
66  // open a file output stream to the input file used by bertini for step 1
67  std::ofstream fout(fname2.c_str());
68  if (!fout.is_open()) {
69  std::cout << fname2 << " failed to open for writing step1 input file.\n";
70  }
71  else {
72  fout << config << input << "\n";
73  }
74  fout.close();
75 
76  std::cout << "your input file:\n\n"
77  << config << input << "\n\n";
78 
79  return;
80 }
81 
82 
83 
84 
85 
86 
87 
88 //gets the config file opened elsewhere as fin, and writes it to fout.
89 // assuming we open the input file stream and the output filestream
90 void MakeConfig(std::ifstream & fin, std::ofstream & fout){
91  std::string token;
92  while (getline(fin,token)){
93  fout << token;
94  fout << "\n";
95  }
96 }
97 void MakeConfig(std::ifstream & fin, std::stringstream & fout){
98  std::string token;
99  while (getline(fin,token)){
100  fout << token;
101  fout << "\n";
102  }
103 }
104 
105 //a recursive call to write a mesh to a plain text file.
106 void WriteMeshToMonteCarlo(int level,
107  std::vector<std::vector<std::pair<double, double> > > Values,
108  std::string dirfilename,
109  std::string runningline){
110 
111  if (level==int(Values.size())-1){
112  // at the last end of the parameters ....
113  for (int i = 0; i < int(Values[level].size());++i){
114  std::stringstream ss;
115  ss << runningline;
116  ss << " ";
117  ss << Values[level][i].first;
118  ss << " ";
119  ss << Values[level][i].second;
120  ss << "\n";
121  std::ofstream fout(dirfilename.c_str(),std::ios::app);
122  fout << ss.str();
123  fout.close();
124  }
125  }
126  else{
127  for (int i= 0; i < int(Values[level].size());++i){
128  std::stringstream ss;
129  ss << runningline;
130  ss << " ";
131  ss << Values[level][i].first;
132  ss << " ";
133  ss << Values[level][i].second;
134  ss << " ";
135 
136  WriteMeshToMonteCarlo(level+1,Values,dirfilename,ss.str());
137  }
138  }
139 }
140 
void MakeConfig(std::ifstream &fin, std::ofstream &fout)
Definition: step1_funcs.cpp:90
void CallBertiniStep1(ProgSettings paramotopy_settings, runinfo paramotopy_info)
Definition: step1_funcs.cpp:5
std::string WriteInputStepOne(ProgSettings paramotopy_settings)
Definition: runinfo.cpp:174
std::string WriteConfigStepOne()
boost::filesystem::path location
Definition: runinfo.hpp:71
categorymap settings
A class that stores the general program settings of Paramotopy.
void WriteStep1(ProgSettings paramotopy_settings, runinfo paramotopy_info)
Definition: step1_funcs.cpp:54
void WriteMeshToMonteCarlo(int level, std::vector< std::vector< std::pair< double, double > > > Values, std::string dirfilename, std::string runningline)
A class for the input file parser.
Definition: runinfo.hpp:41