37 #include <boost/algorithm/string.hpp>
38 #include <boost/program_options.hpp>
45 int main(
int argc,
char* argv[])
50 po::options_description desc(
"Available options");
53 "Produce this help message.")
55 "Print the list of available modules.")
56 (
"output-points,n", po::value<int>(),
57 "Output at n equipspaced points along the collapsed coordinates (for .dat, .vtk).")
58 (
"output-points-hom-z", po::value<int>(),
59 "Number of planes in the z-direction for output of Homogeneous 1D expansion(for .dat, .vtk).")
61 "Write error of fields for regression checking")
63 "Force the output to be written without any checks")
64 (
"range,r", po::value<string>(),
65 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
66 "in which any vertex is contained.")
67 (
"noequispaced",
"Do not use equispaced output. Currently stops the output-points option")
68 (
"nprocs", po::value<int>(),
69 "Used to define nprocs if running serial problem to mimic "
71 (
"npz", po::value<int>(),
72 "Used to define number of partitions in z for Homogeneous1D "
73 "expansions for parallel runs.")
74 (
"onlyshape", po::value<string>(),
75 "Only use element with defined shape type i.e. -onlyshape "
77 (
"part-only", po::value<int>(),
78 "Partition into specfiied npart partitions and exit")
79 (
"part-only-overlapping", po::value<int>(),
80 "Partition into specfiied npart overlapping partitions and exit")
81 (
"procid", po::value<int>(),
82 "Process as single procid of a partition of size nproc "
83 "(-nproc must be specified).")
84 (
"modules-opt,p", po::value<string>(),
85 "Print options for a module.")
86 (
"module,m", po::value<vector<string> >(),
87 "Specify modules which are to be used.")
88 (
"shared-filesystem,s",
"Using shared filesystem.")
89 (
"useSessionVariables",
90 "Use variables defined in session for output")
92 "Enable verbose mode.");
94 po::options_description hidden(
"Hidden options");
96 (
"input-file", po::value<vector<string> >(),
"Input filename");
98 po::options_description cmdline_options;
99 cmdline_options.add(hidden).add(desc);
101 po::options_description visible(
"Allowed options");
104 po::positional_options_description p;
105 p.add(
"input-file", -1);
107 po::variables_map vm;
111 po::store(po::command_line_parser(argc, argv).
112 options(cmdline_options).positional(p).run(), vm);
115 catch (
const std::exception& e)
117 cerr << e.what() << endl;
123 if (vm.count(
"modules-list"))
129 if (vm.count(
"modules-opt"))
132 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
133 boost::is_any_of(
":"));
135 if (tmp1.size() != 2)
137 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
138 <<
"together with the filename; for example in:vtk." << endl;
142 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
144 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
154 else if (tmp1[0] ==
"out")
158 else if (tmp1[0] ==
"proc")
166 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
171 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
172 cerr <<
"Usage: FieldConvert [options] inputfile.ext1 outputfile.ext2"
176 cout <<
"Example Usage: \n" << endl;
177 cout <<
"\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
179 cout <<
"(This will add vorticity to file file.fld and put it in a "
180 "new file file_vort.fld) " << endl;
182 cout <<
"\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
183 cout <<
"(process file_vort.fld and make a tecplot output "
184 "file_vort.dat) " << endl;
190 "Must specify input(s) and/or output file.");
191 vector<string> inout = vm[
"input-file"].as<vector<string> >();
207 if(vm.count(
"procid"))
212 "Must specify --nprocs when using --procid option");
213 nprocs = vm[
"nprocs"].as<
int>();
214 rank = vm[
"procid"].as<
int>();
216 f->m_comm = boost::shared_ptr<FieldConvertComm>(
220 vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
225 "ParallelMPI", argc, argv);
231 "Serial", argc, argv);
235 vector<ModuleSharedPtr> modules;
236 vector<string> modcmds;
239 if (vm.count(
"verbose"))
244 if (vm.count(
"module"))
246 modcmds = vm[
"module"].as<vector<string> >();
250 modcmds.insert(modcmds.begin(), inout.begin(), inout.end()-1);
251 modcmds.push_back(*(inout.end()-1));
253 int nInput = inout.size()-1;
259 if(vm.count(
"part-only")||vm.count(
"part-only-overlapping"))
261 nInput = inout.size();
266 for (
int i = 0; i < modcmds.size(); ++i)
273 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
275 if (i < nInput || i == modcmds.size() - 1)
286 if (tmp1.size() == 1)
288 int dot = tmp1[0].find_last_of(
'.') + 1;
289 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
293 string tmp2 = tmp1[0].substr(0,dot-1);
294 dot = tmp2.find_last_of(
'.') + 1;
295 ext = tmp1[0].substr(dot,tmp1[0].length()-dot);
299 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
304 module.second = tmp1[1];
305 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
313 module.second = tmp1[0];
319 modules.push_back(mod);
323 inputModule = boost::dynamic_pointer_cast<
InputModule>(mod);
324 inputModule->
AddFile(module.second, tmp1[0]);
328 for (
int j = offset; j < tmp1.size(); ++j)
331 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
333 if (tmp2.size() == 1)
335 mod->RegisterConfig(tmp2[0],
"1");
337 else if (tmp2.size() == 2)
339 mod->RegisterConfig(tmp2[0], tmp2[1]);
343 cerr <<
"ERROR: Invalid module configuration: format is "
344 <<
"either :arg or :arg=val" << endl;
354 if(vm.count(
"noequispaced"))
356 for (
int i = 0; i < modules.size(); ++i)
358 modules[i]->SetRequireEquiSpaced(
false);
363 bool RequiresEquiSpaced =
false;
364 for (
int i = 0; i < modules.size(); ++i)
366 if(modules[i]->GetRequireEquiSpaced())
368 RequiresEquiSpaced =
true;
371 if (RequiresEquiSpaced)
373 for (
int i = 0; i < modules.size(); ++i)
375 modules[i]->SetRequireEquiSpaced(
true);
381 for (
int i = 0; i < modules.size(); ++i)
383 if(f->m_verbose && f->m_comm->GetRank() == 0)
387 modules[i]->Process(vm);
389 if(f->m_verbose && f->m_comm->GetRank() == 0)
395 ss << cpuTime <<
"s";
396 cout << modules[i]->GetModuleName()
397 <<
" CPU Time: " << setw(8) << left
404 if(f->m_comm->GetRank() == 0)
410 ss << cpuTime <<
"s";
411 cout <<
"Total CPU Time: " << setw(8) << left
#define ASSERTL0(condition, msg)
void PrintAvailableClasses(std::ostream &pOut=std::cout)
Prints the available classes to stdout.
pair< ModuleType, string > ModuleKey
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
CommFactory & GetCommFactory()
boost::shared_ptr< InputModule > InputModuleSharedPtr
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
boost::shared_ptr< Module > ModuleSharedPtr
boost::shared_ptr< Field > FieldSharedPtr
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
ModuleFactory & GetModuleFactory()
int main(int argc, char *argv[])