38#include <boost/algorithm/string.hpp>
39#include <boost/program_options.hpp>
52int 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::positional_options_description
p;
107 p.add(
"input-file", -1);
109 po::variables_map vm;
113 po::store(po::command_line_parser(argc, argv)
114 .options(cmdline_options)
120 catch (
const std::exception &e)
122 cerr << e.what() << endl;
129 if (std::getenv(
"NEKTAR_DISABLE_BACKUPS") !=
nullptr)
131 vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
135 if (vm.count(
"modules-list"))
141 if (vm.count(
"modules-opt"))
144 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
145 boost::is_any_of(
":"));
147 if (tmp1.size() != 2)
149 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
150 <<
"together with the filename; for example in:vtk." << endl;
154 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
156 cerr <<
"ERROR: Invalid module type (in, out, or proc): " << tmp1[0]
167 else if (tmp1[0] ==
"out")
171 else if (tmp1[0] ==
"proc")
179 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
185 if (vm.count(
"help") || vm.count(
"input-file") != 1)
187 cerr <<
"Usage: FieldConvert [options] "
188 "[inputfile.xml] inputfile.ext1 outputfile.ext2"
192 cout <<
"Example Usage: \n" << endl;
193 cout <<
"\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
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.) "
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.) "
210 "Must specify input(s) and/or output file.");
211 vector<string> inout = vm[
"input-file"].as<vector<string>>();
234 if (vm.count(
"nparts"))
237 MPInprocs = MPIComm->GetSpaceComm()->GetSize();
238 MPIrank = MPIComm->GetSpaceComm()->GetRank();
240 nParts = vm[
"nparts"].as<
int>();
243 "Serial", argc, argv);
252 if (vm.count(
"nparts"))
254 nParts = vm[
"nparts"].as<
int>();
264 for (
auto io = inout.end() - 2; io != inout.end(); io++)
268 boost::split(tmp, *io, boost::is_any_of(
":"));
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();
277 auto start = filename.find_last_of(
"_") + 1;
278 auto index = atoi(filename.substr(start, filename.size()).c_str());
281 if (f->m_comm->TreatAsRankZero() && !fs::is_directory(dir) &&
282 io == inout.end() - 1)
284 fs::create_directory(dir);
289 auto index_new = index + f->m_comm->GetRank() % vm[
"npt"].as<
int>();
290 fs::path path_new = dir;
292 filename.substr(0, start) + std::to_string(index_new) + ftype;
296 *io = path_new.string();
297 for (
auto i = 1; i < tmp.size(); i++)
304 vector<ModuleSharedPtr> modules;
305 vector<string> modcmds;
309 if (vm.count(
"verbose"))
314 if (vm.count(
"module"))
316 modcmds = vm[
"module"].as<vector<string>>();
320 modcmds.insert(modcmds.begin(), inout.begin(), inout.end() - 1);
321 modcmds.push_back(inout.back());
323 int nInput = inout.size() - 1;
329 if (vm.count(
"part-only") || vm.count(
"part-only-overlapping"))
331 nInput = inout.size();
337 for (
int i = 0; i < modcmds.size(); ++i)
343 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
345 if (i < nInput || i == modcmds.size() - 1)
349 if (tmp1.size() > 1 && tmp1.back() ==
"out")
362 if (tmp1.size() == 1)
370 guess = InputModule::GuessFormat(tmp1[0]);
378 cout <<
"Using input module " << guess
379 <<
" for: " << tmp1[0] << endl;
382 module.second = guess;
383 tmp1.push_back(
string(
"infile=" + tmp1[0]));
387 int dot = tmp1[0].find_last_of(
'.') + 1;
388 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
392 if (ext.back() == fs::path::preferred_separator)
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);
413 module.second = tmp1[1];
424 module.second = tmp1[0];
429 modules.push_back(mod);
433 inputModule = std::dynamic_pointer_cast<InputModule>(mod);
434 inputModule->AddFile(module.second, tmp1[0]);
438 outfilename = tmp1[0];
443 mod->RegisterConfig(
"writemultiplefiles");
448 for (
int j = offset; j < tmp1.size(); ++j)
451 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
453 if (tmp2.size() == 1)
455 mod->RegisterConfig(tmp2[0]);
457 else if (tmp2.size() == 2)
459 mod->RegisterConfig(tmp2[0], tmp2[1]);
463 cerr <<
"ERROR: Invalid module configuration: format is "
464 <<
"either :arg or :arg=val" << endl;
475 for (
int i = 0; i < modules.size(); ++i)
477 ++modulesCount[modules[i]->GetModulePriority()];
483 module.second = string(
"equispacedoutput");
485 modules.push_back(mod);
492 if (vm.count(
"range") && f->m_declareExpansionAsContField)
494 ASSERTL0(
false,
"Can't use range option with module requiring "
495 "a continuous expansion.");
498 bool verbose = (f->m_verbose && f->m_comm->TreatAsRankZero());
507 for (
int p = MPIrank;
p < nParts;
p += MPInprocs)
513 cout << endl <<
"Processing partition: " <<
p << endl;
517 partComm = std::shared_ptr<FieldConvertComm>(
530 f->m_comm = partComm;
538 for (
int i = 0; i < modules.size(); ++i)
540 if (modules[i]->GetModulePriority() == priority)
553 for (i = 0; i < modules.size(); ++i)
555 if (boost::iequals(modules[i]->GetModuleName(),
"OutputFld"))
561 if (i != modules.size())
565 MPIComm->GetSpaceComm()->Block();
571 module.second = string(
"info");
574 mod->RegisterConfig(
"nparts",
575 boost::lexical_cast<string>(nParts));
578 if (f->m_writeBndFld)
581 int dot = outfilename.find_last_of(
'.') + 1;
583 outfilename.substr(dot, outfilename.length() - dot);
584 string name = outfilename.substr(0, dot - 1);
586 for (
int b = 0; b < f->m_bndRegionsToWrite.size(); ++b)
588 string outfilenew =
name +
"_b" +
589 boost::lexical_cast<string>(
590 f->m_bndRegionsToWrite[b]) +
592 mod->RegisterConfig(
"outfile", outfilenew);
598 mod->RegisterConfig(
"outfile", outfilename);
612 ss << cpuTime <<
"s";
613 cout <<
"Total CPU Time: " << setw(8) << left << ss.str() << endl;
618 MPIComm->GetSpaceComm()->Block();
619 MPIComm->GetSpaceComm()->Finalise();
630 for (
int i = 0; i < modules.size(); ++i)
632 ++modulesCount[modules[i]->GetModulePriority()];
641 for (
int i = 0; i < modules.size(); ++i)
645 ss << modules[i]->GetModuleName() <<
" ";
648 ss <<
"require fld input.";
660 for (
int i = 0; i < modules.size(); ++i)
662 if (modules[i]->GetModulePriority() ==
eFillExp)
664 ss << modules[i]->GetModuleName() <<
" ";
667 ss <<
"require xml input without fld input.";
679 for (
int i = 0; i < modules.size(); ++i)
681 if (modules[i]->GetModulePriority() ==
eModifyExp ||
684 ss << modules[i]->GetModuleName() <<
" ";
687 ss <<
"require xml input.";
699 for (
int i = 0; i < modules.size(); ++i)
701 if (modules[i]->GetModulePriority() ==
eCreatePts)
703 ss << modules[i]->GetModuleName() <<
" ";
706 ss <<
"should not use xml or fld inputs.";
719 for (
int i = 0; i < modules.size(); ++i)
723 ss << modules[i]->GetModuleName() <<
" ";
726 ss <<
"require xml input.";
733 for (
int i = 0; i < modules.size(); ++i)
737 ss << modules[i]->GetModuleName() <<
" ";
740 ss <<
"is not compatible with module(s): ";
741 for (
int i = 0; i < modules.size(); ++i)
745 ss << modules[i]->GetModuleName() <<
" ";
758 cout <<
"Execution sequence:" << endl;
762 for (
int i = 0; i < modules.size(); ++i)
764 if (modules[i]->GetModulePriority() == priority)
768 cout <<
"\t" << modules[i]->GetModuleName();
773 cout <<
" -> " << modules[i]->GetModuleName();
789 cout << module->GetModuleName() <<
": "
790 << module->GetModuleDescription() << endl;
800 ss << cpuTime <<
"s";
801 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.