OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
32#include "Structure/H5Writer.h"
35
36#include <iomanip>
37#include <memory>
38#include <string>
39#include <vector>
40
42class H5PartWrapper;
43
44class DataSink {
45private:
47 typedef std::unique_ptr<StatWriter> statWriter_t;
48 typedef std::unique_ptr<SDDSWriter> sddsWriter_t;
49 typedef std::unique_ptr<H5Writer> h5Writer_t;
50
51public:
57 DataSink();
58 DataSink(H5PartWrapper* h5wrapper, bool restart);
59 DataSink(H5PartWrapper* h5wrapper);
60
61 void dumpH5(PartBunch_t* beam, Vector_t<double, 3> FDext[]) const;
62
63 int dumpH5(
64 PartBunch_t* beam, Vector_t<double, 3> FDext[], double meanEnergy, double refPr,
65 double refPt, double refPz, double refR, double refTheta, double refZ, double azimuth,
66 double elevation, bool local) const;
67
68 void dumpSDDS(PartBunch_t* beam, Vector_t<double, 3> FDext[], const double& azimuth = -1) const;
69
70 void dumpSDDS(
71 PartBunch_t* beam, Vector_t<double, 3> FDext[], const losses_t& losses = losses_t(),
72 const double& azimuth = -1) const;
73
77
78 void changeH5Wrapper(H5PartWrapper* h5wrapper);
79
86 void writeGeomToVtk(BoundaryGeometry& bg, std::string fn);
87 // void writeGeoContourToVtk(BoundaryGeometry &bg, std::string fn);
88
96 const PartBunch_t* beam, long long int& step, size_t& impact, double& sey_num,
97 size_t numberOfFieldEmittedParticles, bool nEmissionMode, std::string fn);
98
99private:
100 DataSink(const DataSink& ds) = delete;
101 DataSink& operator=(const DataSink&) = delete;
102
103 void rewindLines();
104
105 void init(bool restart = false, H5PartWrapper* h5wrapper = nullptr);
106
109 std::vector<sddsWriter_t> sddsWriter_m;
110
111 static std::string convertToString(int number, int setw = 5);
112
114 unsigned int lossWrCounter_m;
115
117 IpplTimings::TimerRef StatMarkerTimer_m;
118};
119
120inline std::string DataSink::convertToString(int number, int setw) {
121 std::stringstream ss;
122 ss << std::setw(setw) << std::setfill('0') << number;
123 return ss.str();
124}
125
126#endif // DataSink_H_
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
ippl::Vector< T, Dim > Vector_t
void rewindLines()
Definition DataSink.cpp:169
std::vector< sddsWriter_t > sddsWriter_m
Definition DataSink.h:109
void init(bool restart=false, H5PartWrapper *h5wrapper=nullptr)
Definition DataSink.cpp:189
void changeH5Wrapper(H5PartWrapper *h5wrapper)
Definition DataSink.cpp:114
StatWriter::losses_t losses_t
Definition DataSink.h:46
void writeImpactStatistics(const PartBunch_t *beam, long long int &step, size_t &impact, double &sey_num, size_t numberOfFieldEmittedParticles, bool nEmissionMode, std::string fn)
Definition DataSink.cpp:127
DataSink & operator=(const DataSink &)=delete
void writeGeomToVtk(BoundaryGeometry &bg, std::string fn)
Definition DataSink.cpp:121
std::unique_ptr< SDDSWriter > sddsWriter_t
Definition DataSink.h:48
static std::string convertToString(int number, int setw=5)
Definition DataSink.h:120
void dumpH5(PartBunch_t *beam, Vector_t< double, 3 > FDext[]) const
Definition DataSink.cpp:62
void storeCavityInformation()
Write cavity information from H5 file.
Definition DataSink.cpp:107
void dumpSDDS(PartBunch_t *beam, Vector_t< double, 3 > FDext[], const double &azimuth=-1) const
Definition DataSink.cpp:81
IpplTimings::TimerRef StatMarkerTimer_m
Timer to track statistics write time.
Definition DataSink.h:117
std::unique_ptr< H5Writer > h5Writer_t
Definition DataSink.h:49
unsigned int lossWrCounter_m
needed to create index for vtk file
Definition DataSink.h:114
DataSink(const DataSink &ds)=delete
statWriter_t statWriter_m
Definition DataSink.h:108
DataSink()
Default constructor.
Definition DataSink.cpp:44
h5Writer_t h5Writer_m
Definition DataSink.h:107
std::unique_ptr< StatWriter > statWriter_t
Definition DataSink.h:47
std::vector< std::pair< std::string, unsigned int > > losses_t
Definition StatWriter.h:26