OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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  std::unique_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
void invalidBunch()
mark a solution as invalid
namedVariableCollection_t Param_t
Definition: Types.h:48
void setupSimulation()
create directories, input files, fieldmaps...
bool hasResultsAvailable()
check if we already have simulated the current set of design vars
void setupFSStructure()
create directories, input files, symlinks...
std::map< std::string, std::vector< double > > getData(const std::vector< std::string > &statVariables)
void createSymlink_m(const std::string &path)
create symbolic links
std::string simTmpDir_
temporary directory for simulation data (environment var SIMTMPDIR)
std::string pwd_
holds current directory (for restoring)
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)
void redirectOutToFile()
redirect stdout and stderr to file
std::streambuf * strm_err_
stream buffer to redirect stderr
void restoreOut()
restore stdout and stderr to default
void collectResults()
Parse SDDS stat file and build up requested variable dictionary.
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:55
void copyH5_m()
copy H5 file
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition: Expression.h:74
int id_m
job id (SAMPLE command)
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 ...
std::map< std::string, std::string > userVariables_
variable dictionary holding requested optimizer values
Expressions::Named_t constraints_
std::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
virtual ~OpalSimulation()
std::unique_ptr< GenerateOpalSimulation > gs_
object to generate simulation input files
reqVarContainer_t getResults()
returns container containing all requested variables with results
Expressions::Named_t objectives_
const std::string name
reqVarContainer_t requestedVars_
holds solutions returned to the optimizer
std::streambuf * strm_buffer_
stream buffer to redirect output
std::set< std::string > dvarNames_
std::map< std::string, reqVarInfo_t > reqVarContainer_t
Definition: Types.h:79
std::string simulationDirName_
full path of simulation directory (where simulation will be run)
std::string simulationName_
identification of the simulation (corresponding to output filename)
void setFilename(int id)
set job id (SAMPLE command)
Concrete implementation of an Opal simulation wrapper.