OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 #include "Structure/H5Writer.h"
34 #include "Structure/SDDSWriter.h"
35 #include "Structure/StatWriter.h"
36 
37 #include <iomanip>
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 template <class T, unsigned Dim>
43 class PartBunchBase;
44 class BoundaryGeometry;
45 class H5PartWrapper;
46 class MultiBunchHandler;
47 
48 class DataSink {
49 private:
51  typedef std::unique_ptr<StatWriter> statWriter_t;
52  typedef std::unique_ptr<SDDSWriter> sddsWriter_t;
53  typedef std::unique_ptr<H5Writer> h5Writer_t;
54  typedef std::unique_ptr<MultiBunchDump> mbWriter_t;
55 
56 public:
62  DataSink();
63  DataSink(H5PartWrapper *h5wrapper, bool restart, short numBunch);
64  DataSink(H5PartWrapper *h5wrapper, short numBunch);
65 
66  void dumpH5(PartBunchBase<double, 3>* beam, Vector_t FDext[]) const;
67 
68  int dumpH5(PartBunchBase<double, 3>* beam, Vector_t FDext[], double meanEnergy,
69  double refPr, double refPt, double refPz,
70  double refR, double refTheta, double refZ,
71  double azimuth, double elevation, bool local) const;
72 
73  void dumpSDDS(PartBunchBase<double, 3>* beam, Vector_t FDext[],
74  const double& azimuth = -1) const;
75 
76  void dumpSDDS(PartBunchBase<double, 3>* beam, Vector_t FDext[],
77  const losses_t& losses = losses_t(), const double& azimuth = -1) const;
78 
82 
83  void changeH5Wrapper(H5PartWrapper* h5wrapper);
84 
91  void writeGeomToVtk(BoundaryGeometry& bg, const std::string& fn);
92  //void writeGeoContourToVtk(BoundaryGeometry& bg, std::string fn);
93 
101  long long int& step,
102  size_t& impact,
103  double& sey_num,
104  size_t numberOfFieldEmittedParticles,
105  bool nEmissionMode,
106  std::string fn);
107 
113  MultiBunchHandler* mbhandler);
114 
121 
122 private:
123  DataSink(const DataSink& ds) = delete;
124  DataSink &operator = (const DataSink &) = delete;
125 
126  void rewindLines();
127 
128  void init(bool restart = false,
129  H5PartWrapper* h5wrapper = nullptr,
130  short numBunch = 1);
131 
134  std::vector<sddsWriter_t> sddsWriter_m;
135  std::vector<mbWriter_t> mbWriter_m;
136 
137  static std::string convertToString(int number, int setw = 5);
138 
140  unsigned int lossWrCounter_m;
141 
144 
145  const bool isMultiBunch_m;
146 
147  void initMultiBunchDump(short numBunch);
148 };
149 
150 
151 inline
152 std::string DataSink::convertToString(int number, int setw) {
153  std::stringstream ss;
154  ss << std::setw(setw) << std::setfill('0') << number;
155  return ss.str();
156 }
157 
158 #endif // DataSink_H_
DataSink & operator=(const DataSink &)=delete
void initMultiBunchDump(short numBunch)
Definition: DataSink.cpp:313
std::unique_ptr< SDDSWriter > sddsWriter_t
Definition: DataSink.h:52
std::vector< std::pair< std::string, unsigned int > > losses_t
Definition: StatWriter.h:27
statWriter_t statWriter_m
Definition: DataSink.h:133
void rewindLines()
Definition: DataSink.cpp:234
DataSink()
Default constructor.
Definition: DataSink.cpp:60
IpplTimings::TimerRef StatMarkerTimer_m
Timer to track statistics write time.
Definition: DataSink.h:143
void storeCavityInformation()
Write cavity information from H5 file.
Definition: DataSink.cpp:136
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176
void setMultiBunchInitialPathLengh(MultiBunchHandler *mbhandler_p)
Definition: DataSink.cpp:220
h5Writer_t h5Writer_m
Definition: DataSink.h:132
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:157
void writeMultiBunchStatistics(PartBunchBase< double, 3 > *beam, MultiBunchHandler *mbhandler)
Definition: DataSink.cpp:199
unsigned int lossWrCounter_m
needed to create index for vtk file
Definition: DataSink.h:140
std::vector< mbWriter_t > mbWriter_m
Definition: DataSink.h:135
std::vector< sddsWriter_t > sddsWriter_m
Definition: DataSink.h:134
static std::string convertToString(int number, int setw=5)
Definition: DataSink.h:152
void dumpH5(PartBunchBase< double, 3 > *beam, Vector_t FDext[]) const
Definition: DataSink.cpp:87
std::unique_ptr< H5Writer > h5Writer_t
Definition: DataSink.h:53
void writeGeomToVtk(BoundaryGeometry &bg, const std::string &fn)
Definition: DataSink.cpp:150
void init(bool restart=false, H5PartWrapper *h5wrapper=nullptr, short numBunch=1)
Definition: DataSink.cpp:271
void dumpSDDS(PartBunchBase< double, 3 > *beam, Vector_t FDext[], const double &azimuth=-1) const
Definition: DataSink.cpp:106
std::unique_ptr< MultiBunchDump > mbWriter_t
Definition: DataSink.h:54
void changeH5Wrapper(H5PartWrapper *h5wrapper)
Definition: DataSink.cpp:143
StatWriter::losses_t losses_t
Definition: DataSink.h:50
const bool isMultiBunch_m
Definition: DataSink.h:145
std::unique_ptr< StatWriter > statWriter_t
Definition: DataSink.h:51