53{
56
57 po::options_description desc("Available options");
58
59
60 desc.add_options()
61 ("help,h", "Produce this help message.")
62 ("modules-list,l", "Print the list of available modules.")
63 ("output-points,n", po::value<int>(),
64 "Output at n equipspaced points along the "
65 "collapsed coordinates (for .dat, .vtu).")
66 ("output-points-hom-z", po::value<int>(),
67 "Number of planes in the z-direction for output of "
68 "Homogeneous 1D expansion(for .dat, .vtu).")
69 ("error,e", "Write error of fields for regression checking")
70 ("forceoutput,f", "Force the output to be written without any checks")
71 ("range,r", po::value<string>(),
72 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
73 "in which any vertex is contained.")
74 ("noequispaced", "Do not use equispaced output.")
75 ("nparts", po::value<int>(),
76 "Define nparts if running serial problem to mimic "
77 "parallel run with many partitions.")
78 ("npz", po::value<int>(),
79 "Used to define number of partitions in z for Homogeneous1D "
80 "expansions for parallel runs.")
81 ("npt", po::value<int>(),
82 "Used to define number of partitions in time for Parareal runs. ")
83 ("onlyshape", po::value<string>(),
84 "Only use element with defined shape type i.e. -onlyshape "
85 " Tetrahedron")
86 ("part-only", po::value<int>(),
87 "Partition into specified npart partitions and exit")
88 ("part-only-overlapping", po::value<int>(),
89 "Partition into specified npart overlapping partitions and exit")
90 ("modules-opt,p", po::value<string>(),
91 "Print options for a module.")
92 ("module,m", po::value<vector<string>>(),
93 "Specify modules which are to be used.")
94 ("useSessionVariables", "Use variables defined in session for output")
95 ("useSessionExpansion", "Use expansion defined in session.")
96 ("verbose,v", "Enable verbose mode.");
97
98
99 po::options_description hidden("Hidden options");
100 hidden.add_options()("input-file", po::value<vector<string>>(),
101 "Input filename");
102
103 po::options_description cmdline_options;
104 cmdline_options.add(hidden).add(desc);
105
106 po::positional_options_description
p;
107 p.add(
"input-file", -1);
108
109 po::variables_map vm;
110
111 try
112 {
113 po::store(po::command_line_parser(argc, argv)
114 .options(cmdline_options)
117 vm);
118 po::notify(vm);
119 }
120 catch (const std::exception &e)
121 {
122 cerr << e.what() << endl;
123 cerr << desc;
124 return 1;
125 }
126
127
128
129 if (std::getenv("NEKTAR_DISABLE_BACKUPS") != nullptr)
130 {
131 vm.insert(std::make_pair("forceoutput", po::variable_value()));
132 }
133
134
135 if (vm.count("modules-list"))
136 {
138 return 1;
139 }
140
141 if (vm.count("modules-opt"))
142 {
143 vector<string> tmp1;
144 boost::split(tmp1, vm["modules-opt"].as<string>(),
145 boost::is_any_of(":"));
146
147 if (tmp1.size() != 2)
148 {
149 cerr << "ERROR: To specify a module, use one of in, out or proc "
150 << "together with the filename; for example in:vtk." << endl;
151 return 1;
152 }
153
154 if (tmp1[0] != "in" && tmp1[0] != "out" && tmp1[0] != "proc")
155 {
156 cerr << "ERROR: Invalid module type (in, out, or proc): " << tmp1[0]
157 << endl;
158 return 1;
159 }
160
162
163 if (tmp1[0] == "in")
164 {
166 }
167 else if (tmp1[0] == "out")
168 {
170 }
171 else if (tmp1[0] == "proc")
172 {
174 }
175
179 cerr << "Options for module " << tmp1[1] << ":" << endl;
180 mod->PrintConfig();
181 return 1;
182 }
183
184
185 if (vm.count("help") || vm.count("input-file") != 1)
186 {
187 cerr << "Usage: FieldConvert [options] "
188 "[inputfile.xml] inputfile.ext1 outputfile.ext2"
189 << endl;
190 cout << desc;
191 cout << endl;
192 cout << "Example Usage: \n" << endl;
193 cout << "\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
194 << endl;
195 cout << "(This will add vorticity to file file.fld and put it in a "
196 "new file file_vort.fld. \n file.xml is a Nektar XML input "
197 "file containing the geometry.) "
198 << endl;
199 cout << endl;
200 cout << "\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
201 cout << "(process file_vort.fld and make a tecplot output "
202 "file_vort.dat. file.xml is a\n Nektar XML input file "
203 "containing the geometry.) "
204 << endl;
205
206 return 1;
207 }
208
210 "Must specify input(s) and/or output file.");
211 vector<string> inout = vm["input-file"].as<vector<string>>();
212
213
214
215
216
217
218
219
220
221
223 int nParts = 1;
224 int MPInprocs = 1;
225 int MPIrank = 0;
227
229 {
230
232 argc, argv);
233
234 if (vm.count("nparts"))
235 {
236
237 MPInprocs = MPIComm->GetSpaceComm()->GetSize();
238 MPIrank = MPIComm->GetSpaceComm()->GetRank();
239
240 nParts = vm["nparts"].as<int>();
241
243 "Serial", argc, argv);
244 }
245 else
246 {
247 f->m_comm = MPIComm;
248 }
249 }
250 else
251 {
252 if (vm.count("nparts"))
253 {
254 nParts = vm["nparts"].as<int>();
255 }
256
257 f->m_comm =
259 }
260
261
262 if (vm.count("npt"))
263 {
264 for (auto io = inout.end() - 2; io != inout.end(); io++)
265 {
266
267 vector<string> tmp;
268 boost::split(tmp, *io, boost::is_any_of(":"));
269
270
271 fs::path path = tmp[0];
272 fs::path dir = path.parent_path();
273 string ftype = path.extension().string();
274 string filename = path.stem().string();
275
276
277 auto start = filename.find_last_of("_") + 1;
278 auto index = atoi(filename.substr(start, filename.size()).c_str());
279
280
281 if (f->m_comm->TreatAsRankZero() && !fs::is_directory(dir) &&
282 io == inout.end() - 1)
283 {
284 fs::create_directory(dir);
285 }
286
287
288
289 auto index_new = index + f->m_comm->GetRank() % vm["npt"].as<int>();
290 fs::path path_new = dir;
291 path_new /=
292 filename.substr(0, start) + std::to_string(index_new) + ftype;
293
294
295
296 *io = path_new.string();
297 for (auto i = 1; i < tmp.size(); i++)
298 {
299 *io += ":" + tmp[i];
300 }
301 }
302 }
303
304 vector<ModuleSharedPtr> modules;
305 vector<string> modcmds;
308
309 if (vm.count("verbose"))
310 {
311 f->m_verbose = true;
312 }
313
314 if (vm.count("module"))
315 {
316 modcmds = vm["module"].as<vector<string>>();
317 }
318
319
320 modcmds.insert(modcmds.begin(), inout.begin(), inout.end() - 1);
321 modcmds.push_back(inout.back());
322
323 int nInput = inout.size() - 1;
324
325
326
327
328
329 if (vm.count("part-only") || vm.count("part-only-overlapping"))
330 {
331 nInput = inout.size();
332 }
333
335 string outfilename;
336
337 for (int i = 0; i < modcmds.size(); ++i)
338 {
339
340 vector<string> tmp1;
341 int offset = 1;
342
343 boost::split(tmp1, modcmds[i], boost::is_any_of(":"));
344
345 if (i < nInput || i == modcmds.size() - 1)
346 {
347
349 if (tmp1.size() > 1 && tmp1.back() == "out")
350 {
352 tmp1.pop_back();
353 }
354
355
356
357
358
359
360
361
362 if (tmp1.size() == 1)
363 {
364
365
366 string guess;
367
369 {
370 guess = InputModule::GuessFormat(tmp1[0]);
371 }
372
373
374 if (guess != "")
375 {
376 if (f->m_verbose)
377 {
378 cout << "Using input module " << guess
379 << " for: " << tmp1[0] << endl;
380 }
381
382 module.second = guess;
383 tmp1.push_back(string("infile=" + tmp1[0]));
384 }
385 else
386 {
387 int dot = tmp1[0].find_last_of('.') + 1;
388 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
389
390
391
392 if (ext.back() == fs::path::preferred_separator)
393 {
394 ext.pop_back();
395 }
396
397 if (ext == "gz")
398 {
399 string tmp2 = tmp1[0].substr(0, dot - 1);
400 dot = tmp2.find_last_of('.') + 1;
401 ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
402 }
403
404 module.second = ext;
406 ? "infile="
407 : "outfile=") +
408 tmp1[0]);
409 }
410 }
411 else
412 {
413 module.second = tmp1[1];
415 ? "infile="
416 : "outfile=") +
417 tmp1[0]);
418 offset++;
419 }
420 }
421 else
422 {
424 module.second = tmp1[0];
425 }
426
427
429 modules.push_back(mod);
430
432 {
433 inputModule = std::dynamic_pointer_cast<InputModule>(mod);
434 inputModule->AddFile(module.second, tmp1[0]);
435 }
437 {
438 outfilename = tmp1[0];
439 if (nParts > 1)
440 {
441
442
443 mod->RegisterConfig("writemultiplefiles");
444 }
445 }
446
447
448 for (int j = offset; j < tmp1.size(); ++j)
449 {
450 vector<string> tmp2;
451 boost::split(tmp2, tmp1[j], boost::is_any_of("="));
452
453 if (tmp2.size() == 1)
454 {
455 mod->RegisterConfig(tmp2[0]);
456 }
457 else if (tmp2.size() == 2)
458 {
459 mod->RegisterConfig(tmp2[0], tmp2[1]);
460 }
461 else
462 {
463 cerr << "ERROR: Invalid module configuration: format is "
464 << "either :arg or :arg=val" << endl;
465 abort();
466 }
467 }
468
469
470 mod->SetDefaults();
471 }
472
473
475 for (int i = 0; i < modules.size(); ++i)
476 {
477 ++modulesCount[modules[i]->GetModulePriority()];
478 }
481 {
483 module.second = string("equispacedoutput");
485 modules.push_back(mod);
486 mod->SetDefaults();
487 }
488
489
491
492 if (vm.count("range") && f->m_declareExpansionAsContField)
493 {
494 ASSERTL0(
false,
"Can't use range option with module requiring "
495 "a continuous expansion.");
496 }
497
498 bool verbose = (f->m_verbose && f->m_comm->TreatAsRankZero());
499 if (verbose)
500 {
502 }
503
504
507 for (
int p = MPIrank;
p < nParts;
p += MPInprocs)
508 {
509
510
511 if (nParts > 1)
512 {
513 cout << endl <<
"Processing partition: " <<
p << endl;
514
516 f->ClearField();
517 partComm = std::shared_ptr<FieldConvertComm>(
519 }
520
521
523 {
525
526 if (nParts > 1)
527 {
529 {
530 f->m_comm = partComm;
531 }
532 else
533 {
534 f->m_comm = defComm;
535 }
536 }
537
538 for (int i = 0; i < modules.size(); ++i)
539 {
540 if (modules[i]->GetModulePriority() == priority)
541 {
543 }
544 }
545 }
546 }
547
548
549 if (nParts > 1)
550 {
551 int i;
552
553 for (i = 0; i < modules.size(); ++i)
554 {
555 if (boost::iequals(modules[i]->GetModuleName(), "OutputFld"))
556 {
557 break;
558 }
559 }
560
561 if (i != modules.size())
562 {
563 if (MPInprocs > 1)
564 {
565 MPIComm->GetSpaceComm()->Block();
566 }
567
568 if (MPIrank == 0)
569 {
571 module.second = string("info");
573
574 mod->RegisterConfig("nparts",
575 boost::lexical_cast<string>(nParts));
576 mod->SetDefaults();
577
578 if (f->m_writeBndFld)
579 {
580
581 int dot = outfilename.find_last_of('.') + 1;
582 string ext =
583 outfilename.substr(dot, outfilename.length() - dot);
584 string name = outfilename.substr(0, dot - 1);
585
586 for (int b = 0; b < f->m_bndRegionsToWrite.size(); ++b)
587 {
588 string outfilenew =
name +
"_b" +
589 boost::lexical_cast<string>(
590 f->m_bndRegionsToWrite[b]) +
591 "." + ext;
592 mod->RegisterConfig("outfile", outfilenew);
594 }
595 }
596 else
597 {
598 mod->RegisterConfig("outfile", outfilename);
600 }
601 }
602 }
603 }
604
606
607 if (verbose)
608 {
610
611 stringstream ss;
612 ss << cpuTime << "s";
613 cout << "Total CPU Time: " << setw(8) << left << ss.str() << endl;
614 }
615
616 if (MPInprocs > 1)
617 {
618 MPIComm->GetSpaceComm()->Block();
619 MPIComm->GetSpaceComm()->Finalise();
620 }
621
622 return 0;
623}
void PrintExecutionSequence(vector< ModuleSharedPtr > &modules)
void RunModule(ModuleSharedPtr module, po::variables_map &vm, bool verbose)
void CheckModules(vector< ModuleSharedPtr > &modules)
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< InputModule > InputModuleSharedPtr
std::shared_ptr< Module > ModuleSharedPtr
ModuleFactory & GetModuleFactory()
CommFactory & GetCommFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.