37 #include <boost/algorithm/string.hpp>
38 #include <boost/program_options.hpp>
45 int main(
int argc,
char* argv[])
49 po::options_description desc(
"Available options");
52 "Produce this help message.")
54 "Print the list of available modules.")
55 (
"output-points,n", po::value<int>(),
56 "Output at n equipspaced points along the collapsed coordinates (for .dat, .vtk).")
57 (
"output-points-hom-z", po::value<int>(),
58 "Number of planes in the z-direction for output of Homogeneous 1D expansion(for .dat, .vtk).")
60 "Write error of fields for regression checking")
62 "Force the output to be written without any checks")
63 (
"range,r", po::value<string>(),
64 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
65 "in which any vertex is contained.")
66 (
"noequispaced",
"Do not use equispaced output. Currently stops the output-points option")
67 (
"nprocs", po::value<int>(),
68 "Used to define nprocs if running serial problem to mimic "
70 (
"onlyshape", po::value<string>(),
71 "Only use element with defined shape type i.e. -onlyshape "
73 (
"part-only", po::value<int>(),
74 "Partition into specfiied npart partitions and exit")
75 (
"part-only-overlapping", po::value<int>(),
76 "Partition into specfiied npart overlapping partitions and exit")
77 (
"procid", po::value<int>(),
78 "Process as single procid of a partition of size nproc "
79 "(-nproc must be specified).")
80 (
"modules-opt,p", po::value<string>(),
81 "Print options for a module.")
82 (
"module,m", po::value<vector<string> >(),
83 "Specify modules which are to be used.")
84 (
"shared-filesystem,s",
"Using shared filesystem.")
85 (
"useSessionVariables",
86 "Use variables defined in session for output")
88 "Enable verbose mode.");
90 po::options_description hidden(
"Hidden options");
92 (
"input-file", po::value<vector<string> >(),
"Input filename");
94 po::options_description cmdline_options;
95 cmdline_options.add(hidden).add(desc);
97 po::options_description visible(
"Allowed options");
100 po::positional_options_description p;
101 p.add(
"input-file", -1);
103 po::variables_map vm;
107 po::store(po::command_line_parser(argc, argv).
108 options(cmdline_options).positional(p).run(), vm);
111 catch (
const std::exception& e)
113 cerr << e.what() << endl;
119 if (vm.count(
"modules-list"))
125 if (vm.count(
"modules-opt"))
128 boost::split(tmp1, vm[
"modules-opt"].as<string>(),
129 boost::is_any_of(
":"));
131 if (tmp1.size() != 2)
133 cerr <<
"ERROR: To specify a module, use one of in, out or proc "
134 <<
"together with the filename; for example in:vtk." << endl;
138 if (tmp1[0] !=
"in" && tmp1[0] !=
"out" && tmp1[0] !=
"proc")
140 cerr <<
"ERROR: Invalid module type " << tmp1[0] << endl;
150 else if (tmp1[0] ==
"out")
154 else if (tmp1[0] ==
"proc")
162 cerr <<
"Options for module " << tmp1[1] <<
":" << endl;
167 if (vm.count(
"help") || vm.count(
"input-file") != 1) {
168 cerr <<
"Usage: FieldConvert [options] inputfile.ext1 outputfile.ext2"
172 cout <<
"Example Usage: \n" << endl;
173 cout <<
"\t FieldConvert -m vorticity file.xml file.fld file_vort.fld "
175 cout <<
"(This will add vorticity to file file.fld and put it in a "
176 "new file file_vort.fld) " << endl;
178 cout <<
"\t FieldConvert file.xml file_vort.fld file_vort.dat " << endl;
179 cout <<
"(process file_vort.fld and make a tecplot output "
180 "file_vort.dat) " << endl;
186 "Must specify input(s) and/or output file.");
187 vector<string> inout = vm[
"input-file"].as<vector<string> >();
203 if(vm.count(
"procid"))
208 "Must specify --nprocs when using --procid option");
209 nprocs = vm[
"nprocs"].as<
int>();
210 rank = vm[
"procid"].as<
int>();
212 f->m_comm = boost::shared_ptr<FieldConvertComm>(
216 vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
221 "ParallelMPI", argc, argv);
227 "Serial", argc, argv);
231 vector<ModuleSharedPtr> modules;
232 vector<string> modcmds;
235 if (vm.count(
"verbose"))
240 if (vm.count(
"module"))
242 modcmds = vm[
"module"].as<vector<string> >();
246 modcmds.insert(modcmds.begin(), inout.begin(), inout.end()-1);
247 modcmds.push_back(*(inout.end()-1));
249 int nInput = inout.size()-1;
255 if(vm.count(
"part-only")||vm.count(
"part-only-overlapping"))
257 nInput = inout.size();
262 for (
int i = 0; i < modcmds.size(); ++i)
269 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
271 if (i < nInput || i == modcmds.size() - 1)
282 if (tmp1.size() == 1)
284 int dot = tmp1[0].find_last_of(
'.') + 1;
285 string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
289 string tmp2 = tmp1[0].substr(0,dot-1);
290 dot = tmp2.find_last_of(
'.') + 1;
291 ext = tmp1[0].substr(dot,tmp1[0].length()-dot);
295 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
300 module.second = tmp1[1];
301 tmp1.push_back(
string(i < nInput ?
"infile=" :
"outfile=")
309 module.second = tmp1[0];
315 modules.push_back(mod);
319 inputModule = boost::dynamic_pointer_cast<
InputModule>(mod);
320 inputModule->
AddFile(module.second, tmp1[0]);
324 for (
int j = offset; j < tmp1.size(); ++j)
327 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
329 if (tmp2.size() == 1)
331 mod->RegisterConfig(tmp2[0],
"1");
333 else if (tmp2.size() == 2)
335 mod->RegisterConfig(tmp2[0], tmp2[1]);
339 cerr <<
"ERROR: Invalid module configuration: format is "
340 <<
"either :arg or :arg=val" << endl;
350 if(vm.count(
"noequispaced"))
352 for (
int i = 0; i < modules.size(); ++i)
354 modules[i]->SetRequireEquiSpaced(
false);
359 bool RequiresEquiSpaced =
false;
360 for (
int i = 0; i < modules.size(); ++i)
362 if(modules[i]->GetRequireEquiSpaced())
364 RequiresEquiSpaced =
true;
367 if (RequiresEquiSpaced)
369 for (
int i = 0; i < modules.size(); ++i)
371 modules[i]->SetRequireEquiSpaced(
true);
377 for (
int i = 0; i < modules.size(); ++i)
379 modules[i]->Process(vm);
385 if(f->m_comm->GetRank() == 0)
391 ss << cpuTime <<
"s";
392 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[])