38 #include <boost/algorithm/string.hpp>
39 #include <boost/program_options.hpp>
52 int main(
int argc,
char *argv[])
57 po::options_description desc(
"Available 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 "
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.");
99 po::options_description hidden(
"Hidden options");
100 hidden.add_options()(
"input-file", po::value<vector<string>>(),
103 po::options_description cmdline_options;
104 cmdline_options.add(hidden).add(desc);
106 po::options_description visible(
"Allowed options");
109 po::positional_options_description
p;
110 p.add(
"input-file", -1);
112 po::variables_map vm;
116 po::store(po::command_line_parser(argc, argv)
117 .options(cmdline_options)
123 catch (
const std::exception &e)
125 cerr << e.what() << endl;
132 if (std::getenv(
"NEKTAR_DISABLE_BACKUPS") !=
nullptr)
134 vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
138 if (vm.count(
"modules-list"))
144 if (vm.count(
"modules-opt"))
147 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
148 boost::is_any_of(
":"));
150 if (tmp1.size() != 2)
152 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
153 <<
"together with the filename; for example in:vtk." << endl;
157 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
159 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
169 else if (tmp1[0] ==
"out")
173 else if (tmp1[0] ==
"proc")
181 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
186 if (vm.count(
"help") || vm.count(
"input-file") != 1)
188 cerr <<
"Usage: FieldConvert [options] "
189 "[inputfile.xml] inputfile.ext1 outputfile.ext2"
193 cout <<
"Example Usage: \n" << endl;
194 cout <<
"\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
196 cout <<
"(This will add vorticity to file file.fld and put it in a "
197 "new file file_vort.fld. \n file.xml is a Nektar XML input "
198 "file containing the geometry.) "
201 cout <<
"\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
202 cout <<
"(process file_vort.fld and make a tecplot output "
203 "file_vort.dat. file.xml is a\n Nektar XML input file "
204 "containing the geometry.) "
211 "Must specify input(s) and/or output file.");
212 vector<string> inout = vm[
"input-file"].as<vector<string>>();
235 if (vm.count(
"nparts"))
238 MPInprocs = MPIComm->GetSpaceComm()->GetSize();
239 MPIrank = MPIComm->GetSpaceComm()->GetRank();
241 nParts = vm[
"nparts"].as<
int>();
244 "Serial", argc, argv);
253 if (vm.count(
"nparts"))
255 nParts = vm[
"nparts"].as<
int>();
265 for (
auto &io : inout)
267 fs::path inpath = io;
268 fs::path outpath = inpath.parent_path();
269 if (outpath.extension() ==
".pit")
271 fs::path ftype = inpath.extension();
272 string filename = inpath.stem().string();
273 size_t start = filename.find_last_of(
"_") + 1;
275 atoi(filename.substr(start, filename.size()).c_str());
276 outpath /= filename.substr(0, start) +
277 std::to_string(index + f->m_comm->GetRank() %
278 vm[
"npt"].as<
int>()) +
280 io = outpath.string();
285 vector<ModuleSharedPtr> modules;
286 vector<string> modcmds;
290 if (vm.count(
"verbose"))
295 if (vm.count(
"module"))
297 modcmds = vm[
"module"].as<vector<string>>();
301 modcmds.insert(modcmds.begin(), inout.begin(), inout.end() - 1);
302 modcmds.push_back(*(inout.end() - 1));
304 int nInput = inout.size() - 1;
310 if (vm.count(
"part-only") || vm.count(
"part-only-overlapping"))
312 nInput = inout.size();
318 for (
int i = 0; i < modcmds.size(); ++i)
324 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
326 if (i < nInput || i == modcmds.size() - 1)
330 if (tmp1.size() > 1 && tmp1.back() ==
"out")
343 if (tmp1.size() == 1)
351 guess = InputModule::GuessFormat(tmp1[0]);
359 cout <<
"Using input module " << guess
360 <<
" for: " << tmp1[0] << endl;
363 module.second = guess;
364 tmp1.push_back(
string(
"infile=" + tmp1[0]));
368 int dot = tmp1[0].find_last_of(
'.') + 1;
369 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
373 if (ext.back() == fs::path::preferred_separator)
380 string tmp2 = tmp1[0].substr(0, dot - 1);
381 dot = tmp2.find_last_of(
'.') + 1;
382 ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
394 module.second = tmp1[1];
405 module.second = tmp1[0];
410 modules.push_back(mod);
414 inputModule = std::dynamic_pointer_cast<InputModule>(mod);
415 inputModule->AddFile(module.second, tmp1[0]);
419 outfilename = tmp1[0];
424 mod->RegisterConfig(
"writemultiplefiles");
428 for (
int j = offset; j < tmp1.size(); ++j)
431 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
433 if (tmp2.size() == 1)
435 mod->RegisterConfig(tmp2[0]);
437 else if (tmp2.size() == 2)
439 mod->RegisterConfig(tmp2[0], tmp2[1]);
443 cerr <<
"ERROR: Invalid module configuration: format is "
444 <<
"either :arg or :arg=val" << endl;
455 for (
int i = 0; i < modules.size(); ++i)
457 ++modulesCount[modules[i]->GetModulePriority()];
463 module.second = string(
"equispacedoutput");
465 modules.push_back(mod);
472 if (vm.count(
"range") && f->m_declareExpansionAsContField)
474 ASSERTL0(
false,
"Can't use range option with module requiring "
475 "a continuous expansion.");
478 bool verbose = (f->m_verbose && f->m_comm->TreatAsRankZero());
487 for (
int p = MPIrank;
p < nParts;
p += MPInprocs)
493 cout << endl <<
"Processing partition: " <<
p << endl;
497 partComm = std::shared_ptr<FieldConvertComm>(
510 f->m_comm = partComm;
518 for (
int i = 0; i < modules.size(); ++i)
520 if (modules[i]->GetModulePriority() == priority)
533 for (i = 0; i < modules.size(); ++i)
535 if (boost::iequals(modules[i]->GetModuleName(),
"OutputFld"))
541 if (i != modules.size())
545 MPIComm->GetSpaceComm()->Block();
551 module.second = string(
"info");
554 mod->RegisterConfig(
"nparts",
555 boost::lexical_cast<string>(nParts));
558 if (f->m_writeBndFld)
561 int dot = outfilename.find_last_of(
'.') + 1;
563 outfilename.substr(dot, outfilename.length() - dot);
564 string name = outfilename.substr(0, dot - 1);
566 for (
int b = 0; b < f->m_bndRegionsToWrite.size(); ++b)
568 string outfilenew =
name +
"_b" +
569 boost::lexical_cast<string>(
570 f->m_bndRegionsToWrite[b]) +
572 mod->RegisterConfig(
"outfile", outfilenew);
578 mod->RegisterConfig(
"outfile", outfilename);
591 ss << cpuTime <<
"s";
592 cout <<
"Total CPU Time: " << setw(8) << left << ss.str() << endl;
597 MPIComm->GetSpaceComm()->Block();
598 MPIComm->GetSpaceComm()->Finalise();
609 for (
int i = 0; i < modules.size(); ++i)
611 ++modulesCount[modules[i]->GetModulePriority()];
620 for (
int i = 0; i < modules.size(); ++i)
624 ss << modules[i]->GetModuleName() <<
" ";
627 ss <<
"require fld input.";
639 for (
int i = 0; i < modules.size(); ++i)
641 if (modules[i]->GetModulePriority() ==
eFillExp)
643 ss << modules[i]->GetModuleName() <<
" ";
646 ss <<
"require xml input without fld input.";
658 for (
int i = 0; i < modules.size(); ++i)
660 if (modules[i]->GetModulePriority() ==
eModifyExp ||
663 ss << modules[i]->GetModuleName() <<
" ";
666 ss <<
"require xml input.";
678 for (
int i = 0; i < modules.size(); ++i)
680 if (modules[i]->GetModulePriority() ==
eCreatePts)
682 ss << modules[i]->GetModuleName() <<
" ";
685 ss <<
"should not use xml or fld inputs.";
698 for (
int i = 0; i < modules.size(); ++i)
702 ss << modules[i]->GetModuleName() <<
" ";
705 ss <<
"require xml input.";
712 for (
int i = 0; i < modules.size(); ++i)
716 ss << modules[i]->GetModuleName() <<
" ";
719 ss <<
"is not compatible with module(s): ";
720 for (
int i = 0; i < modules.size(); ++i)
724 ss << modules[i]->GetModuleName() <<
" ";
736 cout <<
"Execution sequence:" << endl;
740 for (
int i = 0; i < modules.size(); ++i)
742 if (modules[i]->GetModulePriority() == priority)
746 cout <<
"\t" << modules[i]->GetModuleName();
751 cout <<
" -> " << modules[i]->GetModuleName();
766 cout << module->GetModuleName() <<
": "
767 << module->GetModuleDescription() << endl;
777 ss << cpuTime <<
"s";
778 cout << module->GetModuleName() <<
" CPU Time: " << setw(8) << left
#define ASSERTL0(condition, msg)
int main(int argc, char *argv[])
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.
The above copyright notice and this permission notice shall be included.