OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
opal.cpp
Go to the documentation of this file.
1 #include "opal.h"
2 
3 extern Ippl *ippl;
4 extern Inform *gmsg;
5 
6 
10 #include "Parser/FileStream.h"
12 #include "Fields/Fieldmap.h"
14 
15 #include "OPALconfig.h"
16 
17 #ifdef ENABLE_AMR
18  #include <AMReX.H>
19 #endif
20 
21 
22 int run_opal(char *arg[], std::string inputfile, int restartStep,
23  int infoLevel, int warnLevel, MPI_Comm comm)
24 {
25  std::string::size_type startExtension = inputfile.find_last_of('.');
26  // std::string::size_type startRelativePath = inputfile.find_last_of('/');
27  // std::string relativePath("");
28  // if (startRelativePath != std::string::npos) {
29  // relativePath = inputfile.substr(0, startRelativePath + 1);
30  // }
31  std::string outputFileName = inputfile.substr(0,startExtension) + ".out";
32  std::ofstream output(outputFileName.c_str());
33 
34  MPI_Barrier(comm);
35 
36  IpplInfoWrapper *newippl = new IpplInfoWrapper(inputfile, infoLevel, warnLevel, comm);
37  gmsg = new Inform("OPAL ", output);
41 
42 #ifdef ENABLE_AMR
43  amrex::Initialize(comm);
44 #endif
45 
47 
49  opal->storeInputFn(inputfile);
50 
51  // FileStream is a RCObject
52  FileStream *is = 0;
53  try {
54  is = new FileStream(inputfile);
55  } catch(...) {
56  is = 0;
57  throw new OpalException("run_opal", "Could not open inputfile: " + inputfile);
58  }
59 
60  // run simulation
61  OpalParser *parser = new OpalParser();
62 
63  if (restartStep > std::numeric_limits<int>::min()) {
64  opal->setRestartRun();
65  opal->setRestartStep(restartStep);
66  opal->setRestartFileName(inputfile.substr(0,startExtension) + ".h5");
67  }
68 
69  if(is) parser->run(is);
70 
72 
73  IpplInfo::Info->setDestination(std::cout);
74  IpplInfo::Error->setDestination(std::cout);
75  IpplInfo::Warn->setDestination(std::cout);
76 
77  // cleanup
78  //OPAL->reset();
81  delete parser;
82  delete gmsg;
83 
84 #ifdef ENABLE_AMR
85  amrex::Finalize(true);
86 #endif
87 
88  //FIXME: strange side effects
89  //ippl = 0;
90  //delete aippl;
91 
92  //XXX: seems like Ippl is always returning the same instance after the
93  // initial instantiation.
94  delete newippl;
95 
96  output.close();
97  return 0;
98 }
static void deleteInstance()
Definition: OpalData.cpp:219
The global OPAL structure.
Definition: OpalData.h:54
int infoLevel
Definition: Options.cpp:9
Ippl * ippl
Definition: Main.cpp:20
int run_opal(char *arg[], std::string inputfile, int restartStep, int infoLevel, int warnLevel, MPI_Comm comm)
Definition: opal.cpp:22
static void clearDictionary()
Definition: Fieldmap.cpp:271
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition: OpalData.cpp:340
int warnLevel
Definition: Options.cpp:11
The base class for all OPAL exceptions.
Definition: OpalException.h:28
void storeInputFn(const std::string &fn)
store opals input filename
Definition: OpalData.cpp:700
Inform * gmsg
Definition: Main.cpp:21
static Inform * Warn
Definition: IpplInfo.h:88
void barrier(void)
The default parser for OPAL-9.
Definition: OpalParser.h:44
void setDestination(std::ostream &dest)
Definition: Inform.cpp:216
static OpalData * getInstance()
Definition: OpalData.cpp:209
arg(a))
void configure()
Configure all commands.
Definition: Configure.cpp:303
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:601
A stream of input tokens.
Definition: FileStream.h:32
static Inform * Error
Definition: IpplInfo.h:89
static Inform * Info
Definition: IpplInfo.h:87
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition: OpalData.cpp:359
Definition: Inform.h:41
static Communicate * Comm
Definition: IpplInfo.h:93
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:345