OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OpalSimulation.h
Go to the documentation of this file.
1#ifndef __OPALSIMULATION_H__
2#define __OPALSIMULATION_H__
3
4#include <map>
5#include <string>
6
7#include "mpi.h"
8
9#include "Util/Types.h"
10#include "Util/CmdArguments.h"
13
14
29class OpalSimulation : public Simulation {
30
31public:
32
45 Expressions::Named_t constraints,
46 Param_t params, std::string name, MPI_Comm comm,
47 CmdArguments_t args,
48 std::map<std::string, std::string> uvars);
49
50 virtual ~OpalSimulation();
51
54 void run();
55
56 std::map<std::string, std::vector<double> > getData(const std::vector<std::string> &statVariables);
57
59 void collectResults();
60
63 void cleanUp();
64
66 void cleanUp(const std::vector<std::string>& keep);
67
70
72 void setFilename(int id) { id_m = id; }
73
74private:
75
77 std::string simulationName_;
79 std::string simulationDirName_;
81 std::string simTmpDir_;
82
84 std::string pwd_;
85
87 std::streambuf* strm_buffer_;
89 std::streambuf* strm_err_;
90
92 std::map<std::string, std::string> userVariables_;
93
96
99 std::set<std::string> dvarNames_;
100
101 MPI_Comm comm_;
102
104 std::unique_ptr<GenerateOpalSimulation> gs_;
105
107 int id_m;
108
110 void invalidBunch();
111
113 bool hasResultsAvailable();
114
116 void createSymlink_m(const std::string& path);
117
119 void copyH5_m();
120
122 void setupSimulation();
123
125 void setupFSStructure();
126
129 const std::string& filename,
130 const Expressions::Expr_t* const expression);
131
133 void redirectOutToFile();
135 void restoreOut();
136};
137
138#endif
std::shared_ptr< CmdArguments > CmdArguments_t
std::map< std::string, reqVarInfo_t > reqVarContainer_t
Definition Types.h:78
namedVariableCollection_t Param_t
Definition Types.h:47
const std::string name
std::map< std::string, double > variableDictionary_t
Definition Expression.h:54
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition Expression.h:73
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
std::unique_ptr< GenerateOpalSimulation > gs_
object to generate simulation input files
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
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)