OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
DataSink.h
Go to the documentation of this file.
1 //
2 // Class DataSink
3 // This class acts as an observer during the calculation. It generates diagnostic
4 // output of the accelerated beam such as statistical beam descriptors of particle
5 // positions, momenta, beam phase space (emittance) etc. These are written to file
6 // at periodic time steps during the calculation.
7 //
8 // This class also writes the full beam phase space to an H5 file at periodic time
9 // steps in the calculation (this period is different from that of the statistical
10 // numbers).
11 
12 // Class also writes processor load balancing data to file to track parallel
13 // calculation efficiency.
14 //
15 // Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
16 // All rights reserved
17 //
18 // This file is part of OPAL.
19 //
20 // OPAL is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
27 //
28 #ifndef _OPAL_DATA_SINK_H
29 #define _OPAL_DATA_SINK_H
30 
31 #include "Algorithms/Vektor.h"
32 
33 #include "SDDSWriter.h"
34 #include "StatWriter.h"
35 #include "H5Writer.h"
36 #include "MultiBunchDump.h"
37 
38 #include <iomanip>
39 #include <memory>
40 #include <string>
41 #include <vector>
42 
43 template <class T, unsigned Dim>
44 class PartBunchBase;
45 class BoundaryGeometry;
46 class H5PartWrapper;
47 class MultiBunchHandler;
48 
49 class DataSink {
50 private:
52  typedef std::unique_ptr<StatWriter> statWriter_t;
53  typedef std::unique_ptr<SDDSWriter> sddsWriter_t;
54  typedef std::unique_ptr<H5Writer> h5Writer_t;
55  typedef std::unique_ptr<MultiBunchDump> mbWriter_t;
56 
57 public:
63  DataSink();
64  DataSink(H5PartWrapper *h5wrapper, bool restart, short numBunch);
65  DataSink(H5PartWrapper *h5wrapper, short numBunch);
66 
67  void dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[]) const;
68 
69  int dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[], double meanEnergy,
70  double refPr, double refPt, double refPz,
71  double refR, double refTheta, double refZ,
72  double azimuth, double elevation, bool local) const;
73 
74  void dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[],
75  const double& azimuth = -1) const;
76 
77  void dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[],
78  const losses_t &losses = losses_t(), const double& azimuth = -1) const;
79 
83 
84  void changeH5Wrapper(H5PartWrapper *h5wrapper);
85 
92  void writeGeomToVtk(BoundaryGeometry &bg, std::string fn);
93  //void writeGeoContourToVtk(BoundaryGeometry &bg, std::string fn);
94 
95 
103  long long int &step,
104  size_t &impact,
105  double &sey_num,
106  size_t numberOfFieldEmittedParticles,
107  bool nEmissionMode,
108  std::string fn);
109 
115  MultiBunchHandler* mbhandler);
116 
123 
124 private:
125  DataSink(const DataSink& ds) = delete;
126  DataSink &operator = (const DataSink &) = delete;
127 
128  void rewindLines();
129 
130  void init(bool restart = false,
131  H5PartWrapper* h5wrapper = nullptr,
132  short numBunch = 1);
133 
134 
137  std::vector<sddsWriter_t> sddsWriter_m;
138  std::vector<mbWriter_t> mbWriter_m;
139 
140  static std::string convertToString(int number, int setw = 5);
141 
143  unsigned int lossWrCounter_m;
144 
147 
148  const bool isMultiBunch_m;
149 
150  void initMultiBunchDump(short numBunch);
151 };
152 
153 
154 inline
155 std::string DataSink::convertToString(int number, int setw) {
156  std::stringstream ss;
157  ss << std::setw(setw) << std::setfill('0') << number;
158  return ss.str();
159 }
160 
161 
162 #endif // DataSink_H_
void setMultiBunchInitialPathLengh(MultiBunchHandler *mbhandler_p)
Definition: DataSink.cpp:222
std::unique_ptr< MultiBunchDump > mbWriter_t
Definition: DataSink.h:55
void writeImpactStatistics(const PartBunchBase< double, 3 > *beam, long long int &step, size_t &impact, double &sey_num, size_t numberOfFieldEmittedParticles, bool nEmissionMode, std::string fn)
Definition: DataSink.cpp:159
void rewindLines()
Definition: DataSink.cpp:236
std::vector< sddsWriter_t > sddsWriter_m
Definition: DataSink.h:137
void changeH5Wrapper(H5PartWrapper *h5wrapper)
Definition: DataSink.cpp:145
const bool isMultiBunch_m
Definition: DataSink.h:148
StatWriter::losses_t losses_t
Definition: DataSink.h:51
void initMultiBunchDump(short numBunch)
Definition: DataSink.cpp:315
DataSink & operator=(const DataSink &)=delete
void dumpSDDS(PartBunchBase< double, 3 > *beam, Vector_t FDext[], const double &azimuth=-1) const
Definition: DataSink.cpp:109
void init(bool restart=false, H5PartWrapper *h5wrapper=nullptr, short numBunch=1)
Definition: DataSink.cpp:273
void writeGeomToVtk(BoundaryGeometry &bg, std::string fn)
Definition: DataSink.cpp:152
std::unique_ptr< SDDSWriter > sddsWriter_t
Definition: DataSink.h:53
static std::string convertToString(int number, int setw=5)
Definition: DataSink.h:155
std::vector< mbWriter_t > mbWriter_m
Definition: DataSink.h:138
void storeCavityInformation()
Write cavity information from H5 file.
Definition: DataSink.cpp:138
void dumpH5(PartBunchBase< double, 3 > *beam, Vector_t FDext[]) const
Definition: DataSink.cpp:90
IpplTimings::TimerRef StatMarkerTimer_m
Timer to track statistics write time.
Definition: DataSink.h:146
std::unique_ptr< H5Writer > h5Writer_t
Definition: DataSink.h:54
unsigned int lossWrCounter_m
needed to create index for vtk file
Definition: DataSink.h:143
DataSink(const DataSink &ds)=delete
statWriter_t statWriter_m
Definition: DataSink.h:136
void writeMultiBunchStatistics(PartBunchBase< double, 3 > *beam, MultiBunchHandler *mbhandler)
Definition: DataSink.cpp:201
DataSink()
Default constructor.
Definition: DataSink.cpp:63
h5Writer_t h5Writer_m
Definition: DataSink.h:135
std::unique_ptr< StatWriter > statWriter_t
Definition: DataSink.h:52
std::vector< std::pair< std::string, unsigned int > > losses_t
Definition: StatWriter.h:27
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176