40 #include <AMReX_ParallelDescriptor.H>
51 #include <gsl/gsl_errno.h>
53 #include <boost/filesystem.hpp>
54 #include <boost/system/error_code.hpp>
65 void printStdoutHeader() {
67 std::string dateStr(simtimer.
date());
68 std::string timeStr(simtimer.
time());
69 std::string mySpace(
" ");
71 *
gmsg << mySpace <<
" ____ _____ ___ " <<
endl;
72 *
gmsg << mySpace <<
" / __ \\| __ \\ /\\ | | " <<
endl;
73 *
gmsg << mySpace <<
" | | | | |__) / \\ | |" <<
endl;
74 *
gmsg << mySpace <<
" | | | | ___/ /\\ \\ | |" <<
endl ;
75 *
gmsg << mySpace <<
" | |__| | | / ____ \\| |____" <<
endl;
76 *
gmsg << mySpace <<
" \\____/|_| /_/ \\_\\______|" <<
endl;
79 std::string copyRight =
"(c) PSI, http://amas.web.psi.ch";
81 <<
"This is OPAL (Object Oriented Parallel Accelerator Library) Version " <<
OPAL_PROJECT_VERSION <<
"\n"
82 << std::setw(37 + gitRevision.length() / 2) << std::right << gitRevision <<
"\n\n" <<
endl
83 << std::setw(37 + copyRight.length() / 2) << std::right << copyRight <<
"\n\n" <<
endl
84 <<
"The optimiser (former opt-Pilot) is integrated " <<
endl
87 *
gmsg <<
"Please send cookies, goodies or other motivations (wine and beer ... ) \nto the OPAL developers " <<
PACKAGE_BUGREPORT <<
"\n" <<
endl;
88 *
gmsg <<
"Time: " << timeStr <<
" date: " << dateStr <<
"\n" <<
endl;
95 INFOMSG(
"Usage: opal [<option> <option> ...]\n");
96 INFOMSG(
" The possible values for <option> are:\n");
97 INFOMSG(
" --version : Print the version of opal.\n");
98 INFOMSG(
" --version-full : Print the version of opal with additional informations.\n");
99 INFOMSG(
" --git-revision : Print the revision hash of the repository.\n");
100 INFOMSG(
" --input <fname> : Specifies the input file <fname>.\n");
101 INFOMSG(
" --restart <n> : Performes a restart from step <n>.\n");
102 INFOMSG(
" --restartfn <fname> : Uses the file <fname> to restart from.\n");
104 INFOMSG(
" --noInitAMR : Disable initialization of AMR\n");
107 INFOMSG(
" --help : Display this command-line summary.\n");
114 std::string noamr =
"noInitAMR";
116 for (
int i = 0; i < argc; ++i) {
117 std::string sargv = std::string(argv[i]);
118 if ( sargv.find(noamr) != std::string::npos ) {
127 int main(
int argc,
char *argv[]) {
131 namespace fs = boost::filesystem;
141 H5SetVerbosityLevel(1);
153 std::cout.precision(16);
154 std::cout.setf(std::ios::scientific, std::ios::floatfield);
155 std::cerr.precision(16);
156 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
170 boost::system::error_code error_code;
172 std::cerr << error_code.message() <<
std::endl;
179 std::cerr <<
"unable to create directory; aborting" <<
std::endl;
190 char *startup = getenv(
"HOME");
191 boost::filesystem::path p = strncat(startup,
"/init.opal", 20);
192 if (startup != NULL && is_regular_file(p)) {
201 ERRORMSG(
"Could not open startup file \"" << startup <<
"\".\n"
202 <<
"Note: this is not mandatory for an OPAL simulation!\n");
206 *
gmsg <<
"Reading startup file \"" << startup <<
"\"." <<
endl;
208 *
gmsg <<
"Finished reading startup file." <<
endl;
213 <<
"Couldn't find startup file \"" << startup <<
"\".\n"
214 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
221 int inputFileArgument = -1;
223 std::string restartFileName;
225 for(
int ii = 1; ii < argc; ++ ii) {
226 std::string argStr = std::string(argv[ii]);
228 if (argStr == std::string(
"-h") ||
229 argStr == std::string(
"-help") ||
230 argStr == std::string(
"--help")) {
233 }
else if (argStr == std::string(
"--version")) {
238 }
else if (argStr == std::string(
"--version-full")) {
239 ::printStdoutHeader();
246 std::set<std::string> uniqOptions;
247 while (options.length() > 0) {
248 size_t n = options.find_first_of(
' ');
250 options = options.substr(
n + 1);
251 n = options.find_first_of(
' ');
254 uniqOptions.insert(options.substr(0,
n));
255 options = options.substr(
n + 1);
257 for (
auto it: uniqOptions) {
261 std::string header(
"Compile-time options: ");
262 while (options.length() > 58) {
263 std::string line = options.substr(0, 58);
264 size_t n = line.find_last_of(
' ');
265 INFOMSG(header << line.substr(0,
n) <<
"\n");
267 header = std::string(22,
' ');
268 options = options.substr(
n + 1);
272 }
else if (argStr == std::string(
"--git-revision")) {
277 }
else if (argStr == std::string(
"--input")) {
279 inputFileArgument = ii;
281 }
else if (argStr == std::string(
"-restart") ||
282 argStr == std::string(
"--restart")) {
286 }
else if (argStr == std::string(
"-restartfn") ||
287 argStr == std::string(
"--restartfn")) {
288 restartFileName = std::string(argv[++ ii]);
290 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
293 if (inputFileArgument == -1 &&
294 (ii == 1 || ii + 1 == argc) &&
295 argv[ii][0] !=
'-') {
296 inputFileArgument = ii;
299 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" <<
endl);
306 ::printStdoutHeader();
307 if (inputFileArgument == -1) {
312 fname = std::string(argv[inputFileArgument]);
313 if (!fs::exists(fname)) {
314 INFOMSG(
"Input file \"" << fname <<
"\" doesn't exist!" <<
endl);
321 if (restartFileName ==
"")
323 if (!fs::exists(restartFileName)) {
324 INFOMSG(
"Restart file \"" << restartFileName <<
"\" doesn't exist!" <<
endl);
336 *
gmsg <<
"Input file \"" << fname <<
"\" not found." <<
endl;
340 *
gmsg <<
"* Reading input stream \"" << fname <<
"\"." <<
endl;
342 *
gmsg <<
"* End of input stream \"" << fname <<
"\"." <<
endl;
347 std::ifstream errormsg(
"errormsg.txt");
348 if(errormsg.good()) {
350 std::string closure(
" *\n");
352 <<
"* **********************************************************************************\n"
353 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
354 <<
"* **********************************************************************************"
356 errormsg.getline(buffer, 256);
357 while(errormsg.good()) {
359 if(errormsg.gcount() == 1) {
361 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
362 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
366 errormsg.getline(buffer, 256);
369 <<
"* **********************************************************************************\n"
370 <<
"* **********************************************************************************"
380 errorMsg <<
"\n*** User error detected by function \""
381 << ex.
where() <<
"\"\n";
383 std::string what = ex.
what();
384 size_t pos = what.find_first_of(
'\n');
386 errorMsg <<
" " << what.substr(0, pos) <<
endl;
387 what = what.substr(pos + 1, std::string::npos);
388 pos = what.find_first_of(
'\n');
389 }
while (pos != std::string::npos);
390 errorMsg <<
" " << what <<
endl;
392 MPI_Abort(MPI_COMM_WORLD, -100);
395 errorMsg <<
"\n*** User error detected by function \""
396 << ex.
where() <<
"\"\n";
398 std::string what = ex.
what();
399 size_t pos = what.find_first_of(
'\n');
401 errorMsg <<
" " << what.substr(0, pos) <<
endl;
402 what = what.substr(pos + 1, std::string::npos);
403 pos = what.find_first_of(
'\n');
404 }
while (pos != std::string::npos);
405 errorMsg <<
" " << what <<
endl;
407 MPI_Abort(MPI_COMM_WORLD, -100);
411 errorMsg <<
"\n*** Error detected by function \""
412 << ex.
where() <<
"\"\n";
413 std::string what = ex.
what();
414 size_t pos = what.find_first_of(
'\n');
416 errorMsg <<
" " << what.substr(0, pos) <<
endl;
417 what = what.substr(pos + 1, std::string::npos);
418 pos = what.find_first_of(
'\n');
419 }
while (pos != std::string::npos);
420 errorMsg <<
" " << what <<
endl;
422 MPI_Abort(MPI_COMM_WORLD, -100);
426 errorMsg <<
"\n*** Error detected by function \""
427 << ex.
where() <<
"\"\n";
428 std::string what = ex.
what();
429 size_t pos = what.find_first_of(
'\n');
431 errorMsg <<
" " << what.substr(0, pos) <<
endl;
432 what = what.substr(pos + 1, std::string::npos);
433 pos = what.find_first_of(
'\n');
434 }
while (pos != std::string::npos);
435 errorMsg <<
" " << what <<
endl;
437 MPI_Abort(MPI_COMM_WORLD, -100);
438 }
catch(std::bad_alloc &ex) {
440 errorMsg <<
"\n*** Error:\n";
441 errorMsg <<
" Sorry, virtual memory exhausted.\n"
445 MPI_Abort(MPI_COMM_WORLD, -100);
448 errorMsg <<
"\n*** Runtime-error ******************\n";
449 std::string what = ex.
what();
450 size_t pos = what.find_first_of(
'\n');
452 errorMsg <<
" " << what.substr(0, pos) <<
endl;
453 what = what.substr(pos + 1, std::string::npos);
454 pos = what.find_first_of(
'\n');
455 }
while (pos != std::string::npos);
456 errorMsg <<
" " << what <<
endl;
458 errorMsg <<
"\n************************************\n" <<
endl;
459 throw std::runtime_error(
"in Parser");
460 }
catch(std::exception &ex) {
464 <<
" Internal OPAL error: \n";
465 std::string what = ex.
what();
466 size_t pos = what.find_first_of(
'\n');
468 errorMsg <<
" " << what.substr(0, pos) <<
endl;
469 what = what.substr(pos + 1, std::string::npos);
470 pos = what.find_first_of(
'\n');
471 }
while (pos != std::string::npos);
472 errorMsg <<
" " << what <<
endl;
474 MPI_Abort(MPI_COMM_WORLD, -100);
477 errorMsg <<
"\n*** Error:\n"
478 <<
" Unexpected exception caught.\n" <<
endl;
480 MPI_Abort(MPI_COMM_WORLD, -100);
498 amrex::Finalize(
true);
void handleGSLErrors(const char *reason, const char *file, int, int)
int main(int argc, char *argv[])
bool checkInitAmrFlag(int argc, char *argv[])
#define OPAL_COMPILE_OPTIONS
#define PACKAGE_BUGREPORT
#define OPAL_PROJECT_VERSION
Inform & endl(Inform &inf)
Inform & level5(Inform &inf)
std::string getGitRevision()
void configure()
Configure all commands.
The global OPAL structure.
void storeInputFn(const std::string &fn)
store opals input filename
std::string getInputBasename()
get input file name without extension
void setRestartRun(const bool &value=true)
set OPAL in restart mode
static void deleteInstance()
void setRestartFileName(std::string s)
store opals restart h5 format filename
static OpalData * getInstance()
void storeArguments(int argc, char *argv[])
void setRestartStep(int s)
store the location where to restart
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
bool inRestartRun()
true if we do a restart run
static void clearDictionary()
static void setGlobalTruncOrder(int order)
Set the global truncation order.
A stream of input tokens.
static void setEcho(bool flag)
Set echo flag.
The abstract base class for all exceptions in CLASSIC.
The default parser for OPAL-9.
virtual void run() const
Read current stream.
virtual const std::string & what() const
Return the message string for the exception.
virtual const std::string & where() const
Return the name of the method or function which detected the exception.
The base class for all OPAL exceptions.
std::string date() const
Return date.
std::string time() const
Return time.
static void printVersion(void)
static MPI_Comm getComm()
static Communicate * Comm
static const char * compileOptions()
Timing::TimerRef TimerRef
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)