OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
opal.cpp
Go to the documentation of this file.
1#include "opal.h"
2
3extern Ippl *ippl;
4extern Inform *gmsg;
5
9#include "Parser/FileStream.h"
11#include "Fields/Fieldmap.h"
12#include "Track/TrackRun.h"
14#include "Utilities/Options.h"
15
16#include "OPALconfig.h"
17
18#ifdef ENABLE_AMR
19 #include <AMReX.H>
20#endif
21
22#include "Message/Communicate.h"
23
24#include "GSLErrorHandling.h"
25
26#include <gsl/gsl_errno.h>
27
28#include <fstream>
29#include <iostream>
30#include <limits>
31#include <string>
32
33int run_opal(char */*args*/[], std::string inputfile, int restartStep,
34 int infoLevel, int warnLevel, MPI_Comm comm)
35{
36 std::string::size_type startExtension = inputfile.find_last_of('.');
37 std::string outputFileName = inputfile.substr(0,startExtension) + ".out";
38 std::ofstream output(outputFileName.c_str());
39
40 MPI_Barrier(comm);
41
42 IpplInfoWrapper *newippl = new IpplInfoWrapper(inputfile, infoLevel, warnLevel, comm);
43 gmsg = new Inform("OPAL ", output);
47
48#ifdef ENABLE_AMR
49 if (Options::amr)
50 amrex::Initialize(comm);
51#endif
52
53 gsl_set_error_handler(&handleGSLErrors);
54
56
58 opal->storeInputFn(inputfile);
59
60 // FileStream is a RCObject
61 FileStream *is = 0;
62 try {
63 is = new FileStream(inputfile);
64 } catch(...) {
65 is = 0;
66 throw new OpalException("run_opal", "Could not open inputfile: " + inputfile);
67 }
68
69 // run simulation
70 OpalParser *parser = new OpalParser();
71
72 if (restartStep > std::numeric_limits<int>::min()) {
73 opal->setRestartRun();
74 opal->setRestartStep(restartStep);
75 opal->setRestartFileName(inputfile.substr(0,startExtension) + ".h5");
76 }
77
78 if(is) parser->run(is);
79
81
85
86 // cleanup
87 //OPAL->reset();
88 // Same reason as in Main.cpp. This path is used by the optimiser, which calls
89 // run_opal() once per design evaluation in the same process, so leaving the tracker
90 // alive here also keeps a second copy of every field map resident.
94 delete parser;
95 delete gmsg;
96
97#ifdef ENABLE_AMR
98 if (Options::amr)
99 amrex::Finalize(true);
100#endif
101
102 //FIXME: strange side effects
103 //ippl = 0;
104 //delete aippl;
105
106 //XXX: seems like Ippl is always returning the same instance after the
107 // initial instantiation.
108 delete newippl;
109
110 output.close();
111 return 0;
112}
int run_opal(char *[], std::string inputfile, int restartStep, int infoLevel, int warnLevel, MPI_Comm comm)
Definition opal.cpp:33
Ippl * ippl
Definition Main.cpp:69
Inform * gmsg
Definition Main.cpp:70
void handleGSLErrors(const char *reason, const char *file, int, int)
bool amr
Enable AMR if true.
Definition Options.cpp:97
void configure()
Configure all commands.
The global OPAL structure.
Definition OpalData.h:49
void storeInputFn(const std::string &fn)
store opals input filename
Definition OpalData.cpp:654
void setRestartRun(const bool &value=true)
set OPAL in restart mode
Definition OpalData.cpp:316
static void deleteInstance()
Definition OpalData.cpp:206
void setRestartFileName(std::string s)
store opals restart h5 format filename
Definition OpalData.cpp:332
static OpalData * getInstance()
Definition OpalData.cpp:196
void setRestartStep(int s)
store the location where to restart
Definition OpalData.cpp:320
static void clearDictionary()
Definition Fieldmap.cpp:274
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.
static void releaseTracker()
Definition TrackRun.cpp:63
The base class for all OPAL exceptions.
void barrier(void)
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