OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OpalSimulation.h
Go to the documentation of this file.
1//
2// Class OpalSimulation
3// Concrete implementation of an Opal simulation wrapper.
4//
5// Copyright (c) 2017, Paul Scherrer Institute, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef __OPALSIMULATION_H__
19#define __OPALSIMULATION_H__
20
21#include <map>
22#include <string>
23
24#include "mpi.h"
25
28#include "Util/CmdArguments.h"
29#include "Util/Types.h"
30
39class OpalSimulation : public Simulation {
40
41public:
42
55 Expressions::Named_t constraints,
56 Param_t params, std::string name, MPI_Comm comm,
57 CmdArguments_t args,
58 std::map<std::string, std::string> uvars);
59
60 virtual ~OpalSimulation();
61
64 void run();
65
66 std::map<std::string, std::vector<double> > getData(const std::vector<std::string>& statVariables);
67
69 void collectResults();
70
73 void cleanUp();
74
76 void cleanUp(const std::vector<std::string>& keep);
77
80
82 void setFilename(int id) { id_m = id; }
83
84private:
85
87 std::string simulationName_;
89 std::string simulationDirName_;
91 std::string simTmpDir_;
92
94 std::string pwd_;
95
97 std::streambuf* strm_buffer_;
99 std::streambuf* strm_err_;
100
102 std::map<std::string, std::string> userVariables_;
103
106
109 std::set<std::string> dvarNames_;
110
111 MPI_Comm comm_;
112
114 std::unique_ptr<GenerateOpalSimulation> gs_;
115
117 int id_m;
118
120 void invalidBunch();
121
123 bool hasResultsAvailable();
124
126 void createSymlink_m(const std::string& path);
127
129 void copyH5_m();
130
132 void setupSimulation();
133
135 void setupFSStructure();
136
139 const std::string& filename,
140 const Expressions::Expr_t* const expression);
141
143 void redirectOutToFile();
145 void restoreOut();
146};
147
148#endif
const std::string name
std::map< std::string, double > variableDictionary_t
Definition Expression.h:50
std::map< std::string, reqVarInfo_t > reqVarContainer_t
Definition Types.h:96
namedVariableCollection_t Param_t
Definition Types.h:52
std::shared_ptr< CmdArguments > CmdArguments_t
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition Expression.h:68
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)