31 #define OMPI_SKIP_MPICXX 1 32 #define MPICH_SKIP_MPICXX 42 #ifdef WB_USE_FP_EXCEPTIONS 51 return std::find(begin, end, option) != end;
54 int main(
int argc,
char **argv)
58 #ifdef WB_USE_FP_EXCEPTIONS 61 feclearexcept(FE_DIVBYZERO|FE_INVALID);
64 feenableexcept(FE_DIVBYZERO|FE_INVALID);
72 std::string data_file;
75 unsigned int compositions = 0;
76 unsigned int grain_compositions = 0;
78 bool convert_spherical =
false;
79 bool limit_debug_consistency_checks =
false;
80 bool output_json_files =
false;
84 std::cout <<
"This program allows to use the world builder library directly with a world builder file and a data file. " 85 "The data file will be filled with initial conditions from the world as set by the world builder file." << std::endl
86 <<
"Besides providing two files, where the first is the world builder file and the second is the data file, the available options are: " << std::endl
87 <<
"-h or --help to get this help screen." << std::endl;
92 limit_debug_consistency_checks =
true;
95 output_json_files =
true;
99 std::cout <<
"Error: There where no files passed to the World Builder, use --help for more " << std::endl
100 <<
"information on how to use the World Builder app." << std::endl;
107 std::cout <<
"Error: The World Builder app requires at least two files, a World Builder file " << std::endl
108 <<
"and a data file to convert." << std::endl;
112 if ((argc == 3 && limit_debug_consistency_checks && output_json_files) || (argc == 4 && !(!limit_debug_consistency_checks != !output_json_files)) || (argc == 5 && (!limit_debug_consistency_checks && !output_json_files)) || argc > 5)
114 std::cout <<
"Only exactly two command line arguments may be given, which should be the world builder file location and the data file location (in that order) " 115 <<
"or exactly three command line arguments, which should be the world builder file location, the data file location and --limit-debug-consistency-checks or --output-json-files (in that order)," 116 "or exactly four command line arguments, which should be the world builder file location, the data file location and --limit-debug-consistency-checks and --output-json-files (in that order)," 117 <<
", argc = " << argc <<
", limit_debug_consistency_checks = " << (limit_debug_consistency_checks ?
"true" :
"false") <<
", output_json_files = " << (output_json_files ?
"true" :
"false") << std::endl;
124 MPI_Init(&argc,&argv);
125 MPI_Comm_rank(MPI_COMM_WORLD, &MPI_RANK);
126 MPI_Comm_size(MPI_COMM_WORLD, &MPI_SIZE);
137 std::unique_ptr<WorldBuilder::World> world;
140 const std::string output_dir = wb_file.substr(0,wb_file.find_last_of(
"/\\") + 1);
141 world = std::make_unique<WorldBuilder::World>(wb_file, output_json_files, output_dir,1,limit_debug_consistency_checks);
158 std::ifstream data_stream(data_file);
161 std::vector<std::vector<std::string> > data;
164 while (std::getline(data_stream, temp))
166 std::istringstream buffer(temp);
167 std::vector<std::string> line((std::istream_iterator<std::string>(buffer)),
168 std::istream_iterator<std::string>());
172 for (
auto &line_i : line)
173 line_i.erase(std::remove(line_i.begin(), line_i.end(),
','), line_i.end());
175 data.push_back(line);
179 for (
auto &line_i : data)
181 if (!line_i.empty() && line_i[0] ==
"#" && line_i[1] ==
"dim" && line_i[2] ==
"=")
186 if (!line_i.empty() && line_i[0] ==
"#" && line_i[1] ==
"compositions" && line_i[2] ==
"=")
189 if (!line_i.empty() && line_i[0] ==
"#" && line_i[1] ==
"grain" && line_i[2] ==
"compositions" && line_i[3] ==
"=")
192 if (!line_i.empty() && line_i[0] ==
"#" && line_i[1] ==
"number" && line_i[2] ==
"of" && line_i[3] ==
"grains" && line_i[4] ==
"=")
195 if (!line_i.empty() && line_i[0] ==
"#" && line_i[1] ==
"convert" && line_i[2] ==
"spherical" && line_i[3] ==
"=" && line_i[4] ==
"true")
196 convert_spherical =
true;
200 std::vector<std::array<unsigned ,3>> properties;
201 properties.push_back({{1,0,0}});
203 properties.push_back({{5,0,0}});
205 for (
size_t c = 0; c < compositions; ++c)
206 properties.push_back({{2,static_cast<unsigned int>(c),0}});
209 for (
size_t gc = 0; gc < grain_compositions; ++gc)
210 properties.push_back({{3,static_cast<unsigned int>(gc),static_cast<unsigned int>(n_grains)}});
212 properties.push_back({{4,0,0}});
218 WBAssertThrow(!convert_spherical,
"Converting to spherical values is only available in 3D.");
220 std::cout <<
"# x z d T vx vz ";
222 for (
unsigned int c = 0; c < compositions; ++c)
223 std::cout <<
'c' << c <<
' ';
225 for (
unsigned int gc = 0; gc < grain_compositions; ++gc)
226 for (
size_t g = 0; g < n_grains; g++)
227 std::cout <<
"gs" << gc <<
'-' << g <<
' ' 228 <<
"gm" << gc <<
'-' << g <<
"[0:0] " <<
"gm" << gc <<
'-' << g <<
"[0:1] " <<
"gm" << gc <<
'-' << g <<
"[0:2] " 229 <<
"gm" << gc <<
'-' << g <<
"[1:0] " <<
"gm" << gc <<
'-' << g <<
"[1:1] " <<
"gm" << gc <<
'-' << g <<
"[1:2] " 230 <<
"gm" << gc <<
'-' << g <<
"[2:0] " <<
"gm" << gc <<
'-' << g <<
"[2:1] " <<
"gm" << gc <<
'-' << g <<
"[2:2] ";
233 std::cout <<std::endl;
236 for (
unsigned int i = 0; i < data.size(); ++i)
237 if (data[i].size() > 0 && data[i][0] !=
"#")
240 WBAssertThrow(data[i].size() == dim + 1,
"The file needs to contain dim + 1 entries, but contains " << data[i].size() <<
" entries " 241 " on line " << i+1 <<
" of the data file (" << data_file <<
"). Dim is " << dim <<
'.');
242 const std::array<double,2> coords = {{
247 std::cout << data[i][0] <<
' ' << data[i][1] <<
' ' << data[i][2] <<
' ';
248 std::vector<double> output = world->properties(coords,
string_to_double(data[i][2]),properties);
249 std::cout << output[0] <<
' ';
251 std::cout << output[1] <<
' ' << output[2] <<
' ';
253 for (
unsigned int c = 0; c < compositions; ++c)
255 std::cout << output[3+c] <<
' ';
258 for (
unsigned int gc = 0; gc < grain_compositions; ++gc)
260 const size_t start = 3+compositions+gc*n_grains*10;
261 for (
unsigned int g = 0; g < n_grains; ++g)
263 std::cout << output[start+g] <<
' ' 264 << output[start+n_grains+g*9] <<
' ' << output[start+n_grains+g*9+1] <<
' ' << output[start+n_grains+g*9+2] <<
' ' 265 << output[start+n_grains+g*9+3] <<
' ' << output[start+n_grains+g*9+4] <<
' ' << output[start+n_grains+g*9+5] <<
' ' 266 << output[start+n_grains+g*9+6] <<
' ' << output[start+n_grains+g*9+7] <<
' ' << output[start+n_grains+g*9+8] <<
' ';
270 std::cout <<
" " << output[output.size()-1] << std::endl;
276 std::cout <<
"# x y z d g T vx vy vz ";
278 for (
unsigned int c = 0; c < compositions; ++c)
279 std::cout <<
'c' << c <<
' ';
281 for (
unsigned int gc = 0; gc < grain_compositions; ++gc)
282 for (
size_t g = 0; g < n_grains; g++)
283 std::cout <<
"gs" << gc <<
'-' << g <<
' ' 284 <<
"gm" << gc <<
'-' << g <<
"[0:0] " <<
"gm" << gc <<
'-' << g <<
"[0:1] " <<
"gm" << gc <<
'-' << g <<
"[0:2] " 285 <<
"gm" << gc <<
'-' << g <<
"[1:0] " <<
"gm" << gc <<
'-' << g <<
"[1:1] " <<
"gm" << gc <<
'-' << g <<
"[1:2] " 286 <<
"gm" << gc <<
'-' << g <<
"[2:0] " <<
"gm" << gc <<
'-' << g <<
"[2:1] " <<
"gm" << gc <<
'-' << g <<
"[2:2] ";
289 std::cout <<std::endl;
292 for (
unsigned int i = 0; i < data.size(); ++i)
293 if (data[i].size() > 0 && data[i][0] !=
"#")
295 WBAssertThrow(data[i].size() == dim + 1,
"The file needs to contain dim + 1 entries, but contains " << data[i].size() <<
" entries " 296 " on line " << i+1 <<
" of the data file (" << data_file <<
"). Dim is " << dim <<
'.');
297 std::array<double,3> coords = {{
304 if (convert_spherical)
309 std::cout << data[i][0] <<
' ' << data[i][1] <<
' ' << data[i][2] <<
' ' << data[i][3] <<
' ';
310 std::vector<double> output = world->properties(coords,
string_to_double(data[i][3]),properties);
311 std::cout << output[0] <<
' ';
313 std::cout << output[1] <<
' ' << output[2] <<
' ' << output[3] <<
' ';
315 for (
unsigned int c = 0; c < compositions; ++c)
317 std::cout << output[4+c] <<
' ';
320 for (
unsigned int gc = 0; gc < grain_compositions; ++gc)
322 const size_t start = 4+compositions+gc*n_grains*10;
323 for (
unsigned int g = 0; g < n_grains; ++g)
325 std::cout << output[start+g] <<
' ' 326 << output[start+n_grains+g*9] <<
' ' << output[start+n_grains+g*9+1] <<
' ' << output[start+n_grains+g*9+2] <<
' ' 327 << output[start+n_grains+g*9+3] <<
' ' << output[start+n_grains+g*9+4] <<
' ' << output[start+n_grains+g*9+5] <<
' ' 328 << output[start+n_grains+g*9+6] <<
' ' << output[start+n_grains+g*9+7] <<
' ' << output[start+n_grains+g*9+8] <<
' ';
332 std::cout << output[output.size()-1] << std::endl;
337 std::cout <<
"The World Builder can only be run in 2d and 3d but a different space dimension " << std::endl
338 <<
"is given: dim = " << dim <<
'.';
Point< 3 > spherical_to_cartesian_coordinates(const std::array< double, 3 > &scoord)
const std::array< double, dim > & get_array() const
bool find_command_line_option(char **begin, char **end, const std::string &option)
int main(int argc, char **argv)
#define WBAssertThrow(condition, message)
double string_to_double(const std::string &string)
unsigned int string_to_unsigned_int(const std::string &string)