OPAL (Object Oriented Parallel Accelerator Library) 2022.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"
36
37#include <iomanip>
38#include <memory>
39#include <string>
40#include <vector>
41
42template <class T, unsigned Dim>
43class PartBunchBase;
45class H5PartWrapper;
47
48class DataSink {
49private:
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
56public:
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, std::string fn);
92 //void writeGeoContourToVtk(BoundaryGeometry &bg, std::string fn);
93
94
102 long long int &step,
103 size_t &impact,
104 double &sey_num,
105 size_t numberOfFieldEmittedParticles,
106 bool nEmissionMode,
107 std::string fn);
108
114 MultiBunchHandler* mbhandler);
115
122
123private:
124 DataSink(const DataSink& ds) = delete;
125 DataSink &operator = (const DataSink &) = delete;
126
127 void rewindLines();
128
129 void init(bool restart = false,
130 H5PartWrapper* h5wrapper = nullptr,
131 short numBunch = 1);
132
133
136 std::vector<sddsWriter_t> sddsWriter_m;
137 std::vector<mbWriter_t> mbWriter_m;
138
139 static std::string convertToString(int number, int setw = 5);
140
142 unsigned int lossWrCounter_m;
143
146
147 const bool isMultiBunch_m;
148
149 void initMultiBunchDump(short numBunch);
150};
151
152
153inline
154std::string DataSink::convertToString(int number, int setw) {
155 std::stringstream ss;
156 ss << std::setw(setw) << std::setfill('0') << number;
157 return ss.str();
158}
159
160
161#endif // DataSink_H_
void setMultiBunchInitialPathLengh(MultiBunchHandler *mbhandler_p)
Definition: DataSink.cpp:218
std::unique_ptr< MultiBunchDump > mbWriter_t
Definition: DataSink.h:54
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:155
void rewindLines()
Definition: DataSink.cpp:232
std::vector< sddsWriter_t > sddsWriter_m
Definition: DataSink.h:136
void changeH5Wrapper(H5PartWrapper *h5wrapper)
Definition: DataSink.cpp:141
const bool isMultiBunch_m
Definition: DataSink.h:147
StatWriter::losses_t losses_t
Definition: DataSink.h:50
void initMultiBunchDump(short numBunch)
Definition: DataSink.cpp:311
DataSink & operator=(const DataSink &)=delete
void dumpSDDS(PartBunchBase< double, 3 > *beam, Vector_t FDext[], const double &azimuth=-1) const
Definition: DataSink.cpp:105
void init(bool restart=false, H5PartWrapper *h5wrapper=nullptr, short numBunch=1)
Definition: DataSink.cpp:269
void writeGeomToVtk(BoundaryGeometry &bg, std::string fn)
Definition: DataSink.cpp:148
std::unique_ptr< SDDSWriter > sddsWriter_t
Definition: DataSink.h:52
static std::string convertToString(int number, int setw=5)
Definition: DataSink.h:154
std::vector< mbWriter_t > mbWriter_m
Definition: DataSink.h:137
void storeCavityInformation()
Write cavity information from H5 file.
Definition: DataSink.cpp:134
void dumpH5(PartBunchBase< double, 3 > *beam, Vector_t FDext[]) const
Definition: DataSink.cpp:86
IpplTimings::TimerRef StatMarkerTimer_m
Timer to track statistics write time.
Definition: DataSink.h:145
std::unique_ptr< H5Writer > h5Writer_t
Definition: DataSink.h:53
unsigned int lossWrCounter_m
needed to create index for vtk file
Definition: DataSink.h:142
DataSink(const DataSink &ds)=delete
statWriter_t statWriter_m
Definition: DataSink.h:135
void writeMultiBunchStatistics(PartBunchBase< double, 3 > *beam, MultiBunchHandler *mbhandler)
Definition: DataSink.cpp:197
DataSink()
Default constructor.
Definition: DataSink.cpp:59
h5Writer_t h5Writer_m
Definition: DataSink.h:134
std::unique_ptr< StatWriter > statWriter_t
Definition: DataSink.h:51
std::vector< std::pair< std::string, unsigned int > > losses_t
Definition: StatWriter.h:27
Timing::TimerRef TimerRef
Definition: IpplTimings.h:176