OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
45  Expressions::Named_t constraints,
46  Param_t params, std::string name, MPI_Comm comm,
47  CmdArguments_t args);
48 
49  virtual ~OpalSimulation();
50 
53  void run();
54 
55  std::map<std::string, std::vector<double> > getData(const std::vector<std::string> &statVariables);
56 
58  void collectResults();
59 
62  void cleanUp();
63 
65  void cleanUp(const std::vector<std::string>& keep);
66 
69 
71  void setFilename(int id) { id_m = id; }
72 
73 private:
74 
76  std::string simulationName_;
78  std::string simulationDirName_;
80  std::string simTmpDir_;
81 
83  std::string pwd_;
84 
86  std::streambuf* strm_buffer_;
88  std::streambuf* strm_err_;
89 
91  std::map<std::string, std::string> userVariables_;
92 
95 
98  std::set<std::string> dvarNames_;
99 
100  MPI_Comm comm_;
101 
103  boost::scoped_ptr<GenerateOpalSimulation> gs_;
104 
106  int id_m;
107 
109  void invalidBunch();
110 
112  bool hasResultsAvailable();
113 
115  void createSymlink_m(const std::string& path);
116 
118  void copyH5_m();
119 
121  void setupSimulation();
122 
124  void setupFSStructure();
125 
128  const std::string& filename,
129  const Expressions::Expr_t* const expression);
130 
132  void redirectOutToFile();
134  void restoreOut();
135 };
136 
137 #endif
std::map< std::string, reqVarInfo_t > reqVarContainer_t
Definition: Types.h:64
Expressions::Named_t constraints_
Concrete implementation of an Opal simulation wrapper.
void setupFSStructure()
create directories, input files, symlinks...
reqVarContainer_t requestedVars_
holds solutions returned to the optimizer
virtual ~OpalSimulation()
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:169
std::string pwd_
holds current directory (for restoring)
Expression to be evaluated in the framework.
Definition: Expression.h:75
std::string simTmpDir_
temporary directory for simulation data (environment var SIMTMPDIR)
Expressions::Named_t objectives_
std::string simulationDirName_
full path of simulation directory (where simulation will be run)
void restoreOut()
restore stdout and stderr to default
std::streambuf * strm_err_
stream buffer to redirect stderr
void copyH5_m()
copy H5 file
Abstract class every simulation has to implement to be able to work with the optimization pilot...
Definition: Simulation.h:20
namedVariableCollection_t Param_t
Definition: Types.h:33
bool hasResultsAvailable()
check if we already have simulated the current set of design vars
void invalidBunch()
mark a solution as invalid
OpalSimulation(Expressions::Named_t objectives, Expressions::Named_t constraints, Param_t params, std::string name, MPI_Comm comm, CmdArguments_t args)
reqVarContainer_t getResults()
returns container containing all requested variables with results
void setupSimulation()
create directories, input files, fieldmaps...
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition: Expression.h:45
std::map< std::string, std::vector< double > > getData(const std::vector< std::string > &statVariables)
void createSymlink_m(const std::string &path)
create symbolic links
const std::string name
std::streambuf * strm_buffer_
stream buffer to redirect output
int id_m
job id (SAMPLE command)
boost::scoped_ptr< GenerateOpalSimulation > gs_
object to generate simulation input files
std::set< std::string > dvarNames_
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 ...
void redirectOutToFile()
redirect stdout and stderr to file
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:26
std::map< std::string, std::string > userVariables_
variable dictionary holding requested optimizer values
std::string simulationName_
identification of the simulation (corresponding to output filename)
void collectResults()
Parse SDDS stat file and build up requested variable dictionary.
void setFilename(int id)
set job id (SAMPLE command)