OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
opal.cpp
Go to the documentation of this file.
1 #include "opal.h"
2 
3 extern Ippl *ippl;
4 extern Inform *gmsg;
5 
9 #include "Parser/FileStream.h"
11 #include "Fields/Fieldmap.h"
13 #include "Utilities/Options.h"
14 
15 #include "OPALconfig.h"
16 
17 #ifdef ENABLE_AMR
18  #include <AMReX.H>
19 #endif
20 
21 #include "Message/Communicate.h"
22 
23 #include "GSLErrorHandling.h"
24 
25 #include <gsl/gsl_errno.h>
26 
27 #include <fstream>
28 #include <iostream>
29 #include <limits>
30 #include <string>
31 
32 int run_opal(char */*args*/[], std::string inputfile, int restartStep,
33  int infoLevel, int warnLevel, MPI_Comm comm)
34 {
35  std::string::size_type startExtension = inputfile.find_last_of('.');
36  std::string outputFileName = inputfile.substr(0,startExtension) + ".out";
37  std::ofstream output(outputFileName.c_str());
38 
39  MPI_Barrier(comm);
40 
41  IpplInfoWrapper *newippl = new IpplInfoWrapper(inputfile, infoLevel, warnLevel, comm);
42  gmsg = new Inform("OPAL ", output);
46 
47 #ifdef ENABLE_AMR
48  if (Options::amr)
49  amrex::Initialize(comm);
50 #endif
51 
52  gsl_set_error_handler(&handleGSLErrors);
53 
55 
57  opal->storeInputFn(inputfile);
58 
59  // FileStream is a RCObject
60  FileStream *is = 0;
61  try {
62  is = new FileStream(inputfile);
63  } catch(...) {
64  is = 0;
65  throw new OpalException("run_opal", "Could not open inputfile: " + inputfile);
66  }
67 
68  // run simulation
69  OpalParser *parser = new OpalParser();
70 
71  if (restartStep > std::numeric_limits<int>::min()) {
72  opal->setRestartRun();
73  opal->setRestartStep(restartStep);
74  opal->setRestartFileName(inputfile.substr(0,startExtension) + ".h5");
75  }
76 
77  if(is) parser->run(is);
78 
80 
81  IpplInfo::Info->setDestination(std::cout);
82  IpplInfo::Error->setDestination(std::cout);
83  IpplInfo::Warn->setDestination(std::cout);
84 
85  // cleanup
86  //OPAL->reset();
89  delete parser;
90  delete gmsg;
91 
92 #ifdef ENABLE_AMR
93  if (Options::amr)
94  amrex::Finalize(true);
95 #endif
96 
97  //FIXME: strange side effects
98  //ippl = 0;
99  //delete aippl;
100 
101  //XXX: seems like Ippl is always returning the same instance after the
102  // initial instantiation.
103  delete newippl;
104 
105  output.close();
106  return 0;
107 }
void handleGSLErrors(const char *reason, const char *file, int, int)
int run_opal(char *[], std::string inputfile, int restartStep, int infoLevel, int warnLevel, MPI_Comm comm)
Definition: opal.cpp:32
Ippl * ippl
Definition: Main.cpp:61
Inform * gmsg
Definition: Main.cpp:62
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
int warnLevel
Definition: Options.cpp:34
bool amr
Enable AMR if true.
Definition: Options.cpp:99
int infoLevel
Definition: Options.cpp:29
void configure()
Configure all commands.
Definition: Configure.cpp:245
The global OPAL structure.
Definition: OpalData.h:49
void storeInputFn(const std::string &fn)
store opals input filename
Definition: OpalData.cpp:638
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition: OpalData.cpp:315
static void deleteInstance()
Definition: OpalData.cpp:205
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition: OpalData.cpp:331
static OpalData * getInstance()
Definition: OpalData.cpp:195
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:319
static void clearDictionary()
Definition: Fieldmap.cpp:275
A stream of input tokens.
Definition: FileStream.h:32
The default parser for OPAL-9.
Definition: OpalParser.h:44
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:602
The base class for all OPAL exceptions.
Definition: OpalException.h:28
void barrier(void)
Definition: Inform.h:42
void setDestination(std::ostream &dest)
Definition: Inform.cpp:216
static Inform * Warn
Definition: IpplInfo.h:79
static Inform * Info
Definition: IpplInfo.h:78
static Inform * Error
Definition: IpplInfo.h:80
static Communicate * Comm
Definition: IpplInfo.h:84