36#include "OPALconfig.h"
39#include <AMReX_ParallelDescriptor.H>
50#include <gsl/gsl_errno.h>
52#include <boost/system/error_code.hpp>
64#ifdef DONT_DEFINE_IPPL_GMSG
75 void printStdoutHeader() {
77 std::string dateStr(simtimer.
date());
78 std::string timeStr(simtimer.
time());
79 std::string mySpace(
" ");
81 *
gmsg << mySpace <<
" ____ _____ ___ " <<
endl;
82 *
gmsg << mySpace <<
" / __ \\| __ \\ /\\ | | " <<
endl;
83 *
gmsg << mySpace <<
" | | | | |__) / \\ | |" <<
endl;
84 *
gmsg << mySpace <<
" | | | | ___/ /\\ \\ | |" <<
endl ;
85 *
gmsg << mySpace <<
" | |__| | | / ____ \\| |____" <<
endl;
86 *
gmsg << mySpace <<
" \\____/|_| /_/ \\_\\______|" <<
endl;
89 std::string copyRight =
"(c) PSI, http://amas.web.psi.ch";
91 <<
"This is OPAL (Object Oriented Parallel Accelerator Library) Version " << OPAL_PROJECT_VERSION <<
"\n"
92 << std::setw(37 + gitRevision.length() / 2) << std::right << gitRevision <<
"\n\n" <<
endl
93 << std::setw(37 + copyRight.length() / 2) << std::right << copyRight <<
"\n\n" <<
endl
94 <<
"The optimiser (former opt-Pilot) is integrated " <<
endl
97 *
gmsg <<
"Please send cookies, goodies or other motivations (wine and beer ... ) \nto the OPAL developers " << PACKAGE_BUGREPORT <<
"\n" <<
endl;
98 *
gmsg <<
"Time: " << timeStr <<
" date: " << dateStr <<
"\n" <<
endl;
102 ::printStdoutHeader();
105 INFOMSG(
"Usage: opal [<option> <option> ...]\n");
106 INFOMSG(
" The possible values for <option> are:\n");
107 INFOMSG(
" --version : Print the version of opal.\n");
108 INFOMSG(
" --version-full : Print the version of opal with additional informations.\n");
109 INFOMSG(
" --git-revision : Print the revision hash of the repository.\n");
110 INFOMSG(
" --input <fname> : Specifies the input file <fname>.\n");
111 INFOMSG(
" --restart <n> : Performes a restart from step <n>.\n");
112 INFOMSG(
" --restartfn <fname> : Uses the file <fname> to restart from.\n");
114 INFOMSG(
" --noInitAMR : Disable initialization of AMR\n");
117 INFOMSG(
" --help-command <command> : Display the help for the command <command>\n");
118 INFOMSG(
" --help : Display this command-line summary.\n");
125 std::string noamr =
"noInitAMR";
127 for (
int i = 0; i < argc; ++i) {
128 std::string sargv = std::string(argv[i]);
129 if ( sargv.find(noamr) != std::string::npos ) {
137int opalMain(
int argc,
char *argv[]);
139int main(
int argc,
char *argv[]) {
142 new Ippl(argc, argv);
150 namespace fs = std::filesystem;
160 H5SetVerbosityLevel(1);
172 std::cout.precision(16);
173 std::cout.setf(std::ios::scientific, std::ios::floatfield);
174 std::cerr.precision(16);
175 std::cerr.setf(std::ios::scientific, std::ios::floatfield);
189 std::error_code error_code;
191 std::cerr << error_code.message() <<
std::endl;
198 std::cerr <<
"unable to create directory; aborting" <<
std::endl;
209 char *startup = getenv(
"HOME");
210 std::filesystem::path p = strncat(startup,
"/init.opal", 20);
211 if (startup !=
nullptr && is_regular_file(p)) {
220 ERRORMSG(
"Could not open startup file '" << startup <<
"'\n"
221 <<
"Note: this is not mandatory for an OPAL simulation!\n");
225 *
gmsg <<
"Reading startup file '" << startup <<
"'" <<
endl;
227 *
gmsg <<
"Finished reading startup file." <<
endl;
232 <<
"Couldn't find startup file '" << startup <<
"'\n"
233 <<
"Note: this is not mandatory for an OPAL simulation!\n" <<
endl;
240 int inputFileArgument = -1;
242 std::string restartFileName;
244 for(
int ii = 1; ii < argc; ++ ii) {
245 std::string argStr = std::string(argv[ii]);
246 if (argStr == std::string(
"-h") ||
247 argStr == std::string(
"-help") ||
248 argStr == std::string(
"--help")) {
251 }
else if (argStr == std::string(
"--help-command")) {
256 ::printStdoutHeader();
261 *
gmsg <<
"\nOpalParser::printHelp(): Unknown object \""
262 << cmdName <<
"\".\n" <<
endl;
266 object->printHelp(std::cout);
268 }
else if (argStr == std::string(
"--version")) {
270 std::cout << OPAL_PROJECT_VERSION <<
std::endl;
273 }
else if (argStr == std::string(
"--version-full")) {
274 ::printStdoutHeader();
279 std::string(OPAL_COMPILE_OPTIONS) +
281 std::set<std::string> uniqOptions;
282 while (options.length() > 0) {
283 size_t n = options.find_first_of(
' ');
285 options = options.substr(
n + 1);
286 n = options.find_first_of(
' ');
289 uniqOptions.insert(options.substr(0,
n));
290 options = options.substr(
n + 1);
292 for (
auto it: uniqOptions) {
296 std::string header(
"Compile-time options: ");
297 while (options.length() > 58) {
298 std::string line = options.substr(0, 58);
299 size_t n = line.find_last_of(
' ');
300 INFOMSG(header << line.substr(0,
n) <<
"\n");
302 header = std::string(22,
' ');
303 options = options.substr(
n + 1);
307 }
else if (argStr == std::string(
"--git-revision")) {
312 }
else if (argStr == std::string(
"--input")) {
314 inputFileArgument = ii;
316 }
else if (argStr == std::string(
"-restart") ||
317 argStr == std::string(
"--restart")) {
321 }
else if (argStr == std::string(
"-restartfn") ||
322 argStr == std::string(
"--restartfn")) {
323 restartFileName = std::string(argv[++ ii]);
325 }
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
328 if (inputFileArgument == -1 &&
329 (ii == 1 || ii + 1 == argc) &&
330 argv[ii][0] !=
'-') {
331 inputFileArgument = ii;
334 INFOMSG(
"Unknown argument \"" << argStr <<
"\"" <<
endl);
341 ::printStdoutHeader();
342 if (inputFileArgument == -1) {
347 fname = std::string(argv[inputFileArgument]);
348 if (!fs::exists(fname)) {
349 INFOMSG(
"Input file '" << fname <<
"' doesn't exist!" <<
endl);
356 if (restartFileName.empty()) {
359 if (!fs::exists(restartFileName)) {
360 INFOMSG(
"Restart file '" << restartFileName <<
"' doesn't exist!" <<
endl);
372 *
gmsg <<
"Input file '" << fname <<
"' not found." <<
endl;
376 *
gmsg <<
"* Reading input stream '" << fname <<
"'" <<
endl;
378 *
gmsg <<
"* End of input stream '" << fname <<
"'" <<
endl;
382 std::ifstream errormsg(
"errormsg.txt");
383 if(errormsg.good()) {
385 std::string closure(
" *\n");
387 <<
"* **********************************************************************************\n"
388 <<
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n"
389 <<
"* **********************************************************************************"
391 errormsg.getline(buffer, 256);
392 while(errormsg.good()) {
394 if(errormsg.gcount() == 1) {
396 }
else if ((
size_t)errormsg.gcount() <= closure.size()) {
397 ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
401 errormsg.getline(buffer, 256);
404 <<
"* **********************************************************************************\n"
405 <<
"* **********************************************************************************"
415 errorMsg <<
"\n*** User error detected by function \""
416 << ex.
where() <<
"\"\n";
418 std::string what = ex.
what();
419 size_t pos = what.find_first_of(
'\n');
421 errorMsg <<
" " << what.substr(0, pos) <<
endl;
422 what = what.substr(pos + 1, std::string::npos);
423 pos = what.find_first_of(
'\n');
424 }
while (pos != std::string::npos);
425 errorMsg <<
" " << what <<
endl;
427 MPI_Abort(MPI_COMM_WORLD, -100);
430 errorMsg <<
"\n*** User error detected by function \""
431 << ex.
where() <<
"\"\n";
433 std::string what = ex.
what();
434 size_t pos = what.find_first_of(
'\n');
436 errorMsg <<
" " << what.substr(0, pos) <<
endl;
437 what = what.substr(pos + 1, std::string::npos);
438 pos = what.find_first_of(
'\n');
439 }
while (pos != std::string::npos);
440 errorMsg <<
" " << what <<
endl;
442 MPI_Abort(MPI_COMM_WORLD, -100);
446 errorMsg <<
"\n*** Error detected by function \""
447 << ex.
where() <<
"\"\n";
448 std::string what = ex.
what();
449 size_t pos = what.find_first_of(
'\n');
451 errorMsg <<
" " << what.substr(0, pos) <<
endl;
452 what = what.substr(pos + 1, std::string::npos);
453 pos = what.find_first_of(
'\n');
454 }
while (pos != std::string::npos);
455 errorMsg <<
" " << what <<
endl;
457 MPI_Abort(MPI_COMM_WORLD, -100);
461 errorMsg <<
"\n*** Error detected by function \""
462 << ex.
where() <<
"\"\n";
463 std::string what = ex.
what();
464 size_t pos = what.find_first_of(
'\n');
466 errorMsg <<
" " << what.substr(0, pos) <<
endl;
467 what = what.substr(pos + 1, std::string::npos);
468 pos = what.find_first_of(
'\n');
469 }
while (pos != std::string::npos);
470 errorMsg <<
" " << what <<
endl;
472 MPI_Abort(MPI_COMM_WORLD, -100);
473 }
catch(std::bad_alloc &ex) {
475 errorMsg <<
"\n*** Error:\n";
476 errorMsg <<
" Sorry, virtual memory exhausted.\n"
480 MPI_Abort(MPI_COMM_WORLD, -100);
483 errorMsg <<
"\n*** Runtime-error ******************\n";
484 std::string what = ex.
what();
485 size_t pos = what.find_first_of(
'\n');
487 errorMsg <<
" " << what.substr(0, pos) <<
endl;
488 what = what.substr(pos + 1, std::string::npos);
489 pos = what.find_first_of(
'\n');
490 }
while (pos != std::string::npos);
491 errorMsg <<
" " << what <<
endl;
493 errorMsg <<
"\n************************************\n" <<
endl;
494 throw std::runtime_error(
"in Parser");
495 }
catch(std::exception &ex) {
499 <<
" Internal OPAL error: \n";
500 std::string what = ex.
what();
501 size_t pos = what.find_first_of(
'\n');
503 errorMsg <<
" " << what.substr(0, pos) <<
endl;
504 what = what.substr(pos + 1, std::string::npos);
505 pos = what.find_first_of(
'\n');
506 }
while (pos != std::string::npos);
507 errorMsg <<
" " << what <<
endl;
509 MPI_Abort(MPI_COMM_WORLD, -100);
512 errorMsg <<
"\n*** Error:\n"
513 <<
" Unexpected exception caught.\n" <<
endl;
515 MPI_Abort(MPI_COMM_WORLD, -100);
533 amrex::Finalize(
true);
int opalMain(int argc, char *argv[])
int main(int argc, char *argv[])
bool checkInitAmrFlag(int argc, char *argv[])
void handleGSLErrors(const char *reason, const char *file, int, int)
Inform & endl(Inform &inf)
Inform & level5(Inform &inf)
std::string toUpper(const std::string &str)
std::string getGitRevision()
void configure()
Configure all commands.
The base class for all OPAL objects.
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
Object * find(const std::string &name)
Find entry.
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)