39#include <AMReX_ParallelDescriptor.H> 
   50#include <gsl/gsl_errno.h> 
   52#include <boost/filesystem.hpp> 
   53#include <boost/system/error_code.hpp> 
   64    void printStdoutHeader() {
 
   66        std::string dateStr(simtimer.
date());
 
   67        std::string timeStr(simtimer.
time());
 
   68        std::string mySpace(
"            ");
 
   70        *
gmsg << mySpace <<  
"   ____  _____       ___ " << 
endl;
 
   71        *
gmsg << mySpace <<  
"  / __ \\|  __ \\ /\\   | | " << 
endl;
 
   72        *
gmsg << mySpace <<  
" | |  | | |__) /  \\  | |" << 
endl;
 
   73        *
gmsg << mySpace <<  
" | |  | |  ___/ /\\ \\ | |" << 
endl ;
 
   74        *
gmsg << mySpace <<  
" | |__| | |  / ____ \\| |____" << 
endl;
 
   75        *
gmsg << mySpace <<  
"  \\____/|_| /_/    \\_\\______|" << 
endl;
 
   78        std::string copyRight = 
"(c) PSI, http://amas.web.psi.ch";
 
   80              << 
"This is OPAL (Object Oriented Parallel Accelerator Library) Version " << 
OPAL_PROJECT_VERSION << 
"\n" 
   81              << std::setw(37 + gitRevision.length() / 2) << std::right << gitRevision << 
"\n\n" << 
endl 
   82              << std::setw(37 + copyRight.length() / 2) << std::right << copyRight << 
"\n\n" << 
endl 
   83              << 
"The optimiser (former opt-Pilot) is integrated " << 
endl 
   86        *
gmsg << 
"Please send cookies, goodies or other motivations (wine and beer ... ) \nto the OPAL developers " << 
PACKAGE_BUGREPORT << 
"\n" << 
endl;
 
   87        *
gmsg << 
"Time: " << timeStr << 
" date: " << dateStr << 
"\n" << 
endl;
 
   91        ::printStdoutHeader();
 
   94        INFOMSG(
"Usage: opal [<option> <option> ...]\n");
 
   95        INFOMSG(
"   The possible values for <option> are:\n");
 
   96        INFOMSG(
"   --version                : Print the version of opal.\n");
 
   97        INFOMSG(
"   --version-full           : Print the version of opal with additional informations.\n");
 
   98        INFOMSG(
"   --git-revision           : Print the revision hash of the repository.\n");
 
   99        INFOMSG(
"   --input <fname>          : Specifies the input file <fname>.\n");
 
  100        INFOMSG(
"   --restart <n>            : Performes a restart from step <n>.\n");
 
  101        INFOMSG(
"   --restartfn <fname>      : Uses the file <fname> to restart from.\n");
 
  103        INFOMSG(
"   --noInitAMR              : Disable initialization of AMR\n");
 
  106        INFOMSG(
"   --help-command <command> : Display the help for the command <command>\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 ) {
 
  126int opalMain(
int argc, 
char *argv[]);
 
  128int main(
int argc, 
char *argv[]) {
 
  137    namespace fs = boost::filesystem;
 
  147    H5SetVerbosityLevel(1); 
 
  159    std::cout.precision(16);
 
  160    std::cout.setf(std::ios::scientific, std::ios::floatfield);
 
  161    std::cerr.precision(16);
 
  162    std::cerr.setf(std::ios::scientific, std::ios::floatfield);
 
  176            boost::system::error_code error_code;
 
  178                std::cerr << error_code.message() << 
std::endl;
 
  185        std::cerr << 
"unable to create directory; aborting" << 
std::endl;
 
  196        char *startup = getenv(
"HOME");
 
  197        boost::filesystem::path p = strncat(startup, 
"/init.opal", 20);
 
  198        if (startup != 
nullptr && is_regular_file(p)) {
 
  207                ERRORMSG(
"Could not open startup file '" << startup << 
"'\n" 
  208                         << 
"Note: this is not mandatory for an OPAL simulation!\n");
 
  212                *
gmsg << 
"Reading startup file '" << startup << 
"'" << 
endl;
 
  214                *
gmsg << 
"Finished reading startup file." << 
endl;
 
  219                  << 
"Couldn't find startup file '" << startup << 
"'\n" 
  220                  << 
"Note: this is not mandatory for an OPAL simulation!\n" << 
endl;
 
  227        int inputFileArgument = -1;
 
  229        std::string restartFileName;
 
  231        for(
int ii = 1; ii < argc; ++ ii) {
 
  232            std::string argStr = std::string(argv[ii]);
 
  233            if (argStr == std::string(
"-h") ||
 
  234                argStr == std::string(
"-help") ||
 
  235                argStr == std::string(
"--help")) {
 
  238            } 
else if (argStr == std::string(
"--help-command")) {
 
  243                ::printStdoutHeader();
 
  248                    *
gmsg << 
"\nOpalParser::printHelp(): Unknown object \"" 
  249                            << cmdName << 
"\".\n" << 
endl;
 
  253                object->printHelp(std::cout);
 
  255            } 
else if (argStr == std::string(
"--version")) {
 
  260            } 
else if (argStr == std::string(
"--version-full")) {
 
  261                ::printStdoutHeader();
 
  268                std::set<std::string> uniqOptions;
 
  269                while (options.length() > 0) {
 
  270                    size_t n = options.find_first_of(
' ');
 
  272                        options = options.substr(
n + 1);
 
  273                        n = options.find_first_of(
' ');
 
  276                    uniqOptions.insert(options.substr(0, 
n));
 
  277                    options = options.substr(
n + 1);
 
  279                for (
auto it: uniqOptions) {
 
  283                std::string header(
"Compile-time options: ");
 
  284                while (options.length() > 58) {
 
  285                    std::string line = options.substr(0, 58);
 
  286                    size_t n = line.find_last_of(
' ');
 
  287                    INFOMSG(header << line.substr(0, 
n) << 
"\n");
 
  289                    header = std::string(22, 
' ');
 
  290                    options = options.substr(
n + 1);
 
  294            } 
else if (argStr == std::string(
"--git-revision")) {
 
  299            } 
else if (argStr == std::string(
"--input")) {
 
  301                inputFileArgument = ii;
 
  303            } 
else if (argStr == std::string(
"-restart") ||
 
  304                        argStr == std::string(
"--restart")) {
 
  308            } 
else if (argStr == std::string(
"-restartfn") ||
 
  309                        argStr == std::string(
"--restartfn")) {
 
  310                restartFileName = std::string(argv[++ ii]);
 
  312            } 
else if ( argStr.find(
"noInitAMR") != std::string::npos) {
 
  315                if (inputFileArgument == -1 &&
 
  316                    (ii == 1 || ii + 1 == argc) &&
 
  317                    argv[ii][0] != 
'-') {
 
  318                    inputFileArgument = ii;
 
  321                    INFOMSG(
"Unknown argument \"" << argStr << 
"\"" << 
endl);
 
  328        ::printStdoutHeader();
 
  329        if (inputFileArgument == -1) {
 
  334        fname = std::string(argv[inputFileArgument]);
 
  335        if (!fs::exists(fname)) {
 
  336            INFOMSG(
"Input file '" << fname << 
"' doesn't exist!" << 
endl);
 
  343            if (restartFileName.empty()) {
 
  346            if (!fs::exists(restartFileName)) {
 
  347                INFOMSG(
"Restart file '" << restartFileName << 
"' doesn't exist!" << 
endl);
 
  359            *
gmsg << 
"Input file '" << fname << 
"' not found." << 
endl;
 
  363            *
gmsg << 
"* Reading input stream '" << fname << 
"'" << 
endl;
 
  365            *
gmsg << 
"* End of input stream '" << fname << 
"'" << 
endl;
 
  369            std::ifstream errormsg(
"errormsg.txt");
 
  370            if(errormsg.good()) {
 
  372                std::string closure(
"                                                                                 *\n");
 
  374                         << 
"* **********************************************************************************\n" 
  375                         << 
"* ************** W A R N I N G / E R R O R * * M E S S A G E S *********************\n" 
  376                         << 
"* **********************************************************************************" 
  378                errormsg.getline(buffer, 256);
 
  379                while(errormsg.good()) {
 
  381                    if(errormsg.gcount() == 1) {
 
  383                    } 
else if ((
size_t)errormsg.gcount() <= closure.size()) {
 
  384                        ERRORMSG(buffer << closure.substr(errormsg.gcount() - 1));
 
  388                    errormsg.getline(buffer, 256);
 
  391                         << 
"* **********************************************************************************\n" 
  392                         << 
"* **********************************************************************************" 
  402        errorMsg << 
"\n*** User error detected by function \"" 
  403                 << ex.
where() << 
"\"\n";
 
  405        std::string what = ex.
what();
 
  406        size_t pos = what.find_first_of(
'\n');
 
  408            errorMsg << 
"    " << what.substr(0, pos) << 
endl;
 
  409            what = what.substr(pos + 1, std::string::npos);
 
  410            pos = what.find_first_of(
'\n');
 
  411        } 
while (pos != std::string::npos);
 
  412        errorMsg << 
"    " << what << 
endl;
 
  414        MPI_Abort(MPI_COMM_WORLD, -100);
 
  417        errorMsg << 
"\n*** User error detected by function \"" 
  418                 << ex.
where() << 
"\"\n";
 
  420        std::string what = ex.
what();
 
  421        size_t pos = what.find_first_of(
'\n');
 
  423            errorMsg << 
"    " << what.substr(0, pos) << 
endl;
 
  424            what = what.substr(pos + 1, std::string::npos);
 
  425            pos = what.find_first_of(
'\n');
 
  426        } 
while (pos != std::string::npos);
 
  427        errorMsg << 
"    " << what << 
endl;
 
  429        MPI_Abort(MPI_COMM_WORLD, -100);
 
  433        errorMsg << 
"\n*** Error detected by function \"" 
  434                 << ex.
where() << 
"\"\n";
 
  435        std::string what = ex.
what();
 
  436        size_t pos = what.find_first_of(
'\n');
 
  438            errorMsg << 
"    " << what.substr(0, pos) << 
endl;
 
  439            what = what.substr(pos + 1, std::string::npos);
 
  440            pos = what.find_first_of(
'\n');
 
  441        } 
while (pos != std::string::npos);
 
  442        errorMsg << 
"    " << what << 
endl;
 
  444        MPI_Abort(MPI_COMM_WORLD, -100);
 
  448        errorMsg << 
"\n*** Error detected by function \"" 
  449                 << ex.
where() << 
"\"\n";
 
  450        std::string what = ex.
what();
 
  451        size_t pos = what.find_first_of(
'\n');
 
  453            errorMsg << 
"    " << what.substr(0, pos) << 
endl;
 
  454            what = what.substr(pos + 1, std::string::npos);
 
  455            pos = what.find_first_of(
'\n');
 
  456        } 
while (pos != std::string::npos);
 
  457        errorMsg << 
"    " << what << 
endl;
 
  459        MPI_Abort(MPI_COMM_WORLD, -100);
 
  460    } 
catch(std::bad_alloc &ex) {
 
  462        errorMsg << 
"\n*** Error:\n";
 
  463        errorMsg << 
"    Sorry, virtual memory exhausted.\n" 
  467        MPI_Abort(MPI_COMM_WORLD, -100);
 
  470        errorMsg << 
"\n*** Runtime-error ******************\n";
 
  471        std::string what = ex.
what();
 
  472        size_t pos = what.find_first_of(
'\n');
 
  474            errorMsg << 
"    " << what.substr(0, pos) << 
endl;
 
  475            what = what.substr(pos + 1, std::string::npos);
 
  476            pos = what.find_first_of(
'\n');
 
  477        } 
while (pos != std::string::npos);
 
  478        errorMsg << 
"    " << what << 
endl;
 
  480        errorMsg << 
"\n************************************\n" << 
endl;
 
  481        throw std::runtime_error(
"in Parser");
 
  482    } 
catch(std::exception &ex) {
 
  486                 << 
"    Internal OPAL error: \n";
 
  487        std::string what = ex.
what();
 
  488        size_t pos = what.find_first_of(
'\n');
 
  490            errorMsg << 
"    " << what.substr(0, pos) << 
endl;
 
  491            what = what.substr(pos + 1, std::string::npos);
 
  492            pos = what.find_first_of(
'\n');
 
  493        } 
while (pos != std::string::npos);
 
  494        errorMsg << 
"    " << what << 
endl;
 
  496        MPI_Abort(MPI_COMM_WORLD, -100);
 
  499        errorMsg << 
"\n*** Error:\n" 
  500                 << 
"    Unexpected exception caught.\n" << 
endl;
 
  502        MPI_Abort(MPI_COMM_WORLD, -100);
 
  520        amrex::Finalize(
true);
 
#define OPAL_COMPILE_OPTIONS
 
#define PACKAGE_BUGREPORT
 
#define OPAL_PROJECT_VERSION
 
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)