OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalSimulation.h
Go to the documentation of this file.
1 #ifndef __OPALSIMULATION_H__
2 #define __OPALSIMULATION_H__
3 
4 #include <string>
5 #include <map>
6 
7 #include "mpi.h"
8 
9 #include "Util/Types.h"
10 #include "Util/CmdArguments.h"
11 #include "Simulation/Simulation.h"
13 
14 #include "boost/smart_ptr.hpp"
15 
30 class OpalSimulation : public Simulation {
31 
32 public:
33 
46  Expressions::Named_t constraints,
47  Param_t params, std::string name, MPI_Comm comm,
48  CmdArguments_t args,
49  std::map<std::string, std::string> uvars);
50 
51  virtual ~OpalSimulation();
52 
55  void run();
56 
57  std::map<std::string, std::vector<double> > getData(const std::vector<std::string> &statVariables);
58 
60  void collectResults();
61 
64  void cleanUp();
65 
67  void cleanUp(const std::vector<std::string>& keep);
68 
71 
73  void setFilename(int id) { id_m = id; }
74 
75 private:
76 
78  std::string simulationName_;
80  std::string simulationDirName_;
82  std::string simTmpDir_;
83 
85  std::string pwd_;
86 
88  std::streambuf* strm_buffer_;
90  std::streambuf* strm_err_;
91 
93  std::map<std::string, std::string> userVariables_;
94 
97 
100  std::set<std::string> dvarNames_;
101 
102  MPI_Comm comm_;
103 
105  boost::scoped_ptr<GenerateOpalSimulation> gs_;
106 
108  int id_m;
109 
111  void invalidBunch();
112 
114  bool hasResultsAvailable();
115 
117  void createSymlink_m(const std::string& path);
118 
120  void copyH5_m();
121 
123  void setupSimulation();
124 
126  void setupFSStructure();
127 
130  const std::string& filename,
131  const Expressions::Expr_t* const expression);
132 
134  void redirectOutToFile();
136  void restoreOut();
137 };
138 
139 #endif
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:55
const std::string name
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
std::map< std::string, reqVarInfo_t > reqVarContainer_t
Definition: Types.h:79
namedVariableCollection_t Param_t
Definition: Types.h:48
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition: Expression.h:74
Concrete implementation of an Opal simulation wrapper.
std::string pwd_
holds current directory (for restoring)
void invalidBunch()
mark a solution as invalid
virtual ~OpalSimulation()
std::map< std::string, std::vector< double > > getData(const std::vector< std::string > &statVariables)
void getVariableDictionary(variableDictionary_t &dictionary, const std::string &filename, const Expressions::Expr_t *const expression)
get variables for expression evaluation from SDDS file. Can throw SDDSParserException
reqVarContainer_t requestedVars_
holds solutions returned to the optimizer
void setupSimulation()
create directories, input files, fieldmaps...
void setFilename(int id)
set job id (SAMPLE command)
void copyH5_m()
copy H5 file
void redirectOutToFile()
redirect stdout and stderr to file
Expressions::Named_t objectives_
std::streambuf * strm_err_
stream buffer to redirect stderr
std::string simulationDirName_
full path of simulation directory (where simulation will be run)
std::set< std::string > dvarNames_
Expressions::Named_t constraints_
std::map< std::string, std::string > userVariables_
variable dictionary holding requested optimizer values
boost::scoped_ptr< GenerateOpalSimulation > gs_
object to generate simulation input files
std::string simTmpDir_
temporary directory for simulation data (environment var SIMTMPDIR)
reqVarContainer_t getResults()
returns container containing all requested variables with results
std::streambuf * strm_buffer_
stream buffer to redirect output
void createSymlink_m(const std::string &path)
create symbolic links
std::string simulationName_
identification of the simulation (corresponding to output filename)
bool hasResultsAvailable()
check if we already have simulated the current set of design vars
void setupFSStructure()
create directories, input files, symlinks...
void collectResults()
Parse SDDS stat file and build up requested variable dictionary.
void restoreOut()
restore stdout and stderr to default
int id_m
job id (SAMPLE command)
OpalSimulation(Expressions::Named_t objectives, Expressions::Named_t constraints, Param_t params, std::string name, MPI_Comm comm, CmdArguments_t args, std::map< std::string, std::string > uvars)