DataSink.h 4.95 KB
Newer Older
gsell's avatar
gsell committed
1
//
gsell's avatar
gsell committed
2 3
//  Copyright & License: See Copyright.readme in src directory
//
gsell's avatar
gsell committed
4

gsell's avatar
gsell committed
5 6
/**
   \brief Class: DataSink
7

gsell's avatar
gsell committed
8 9 10 11
   This class acts as an observer during the calculation. It generates diagnostic
   output of the accelerated beam such as statistical beam descriptors of particle
   positions, momenta, beam phase space (emittance) etc. These are written to file
   at periodic time steps during the calculation.
12

gsell's avatar
gsell committed
13 14 15
   This class also writes the full beam phase space to an H5 file at periodic time
   steps in the calculation (this period is different from that of the statistical
   numbers).
16

gsell's avatar
gsell committed
17 18 19
   Class also writes processor load balancing data to file to track parallel
   calculation efficiency.
*/
gsell's avatar
gsell committed
20

gsell's avatar
gsell committed
21 22
#ifndef _OPAL_DATA_SINK_H
#define _OPAL_DATA_SINK_H
gsell's avatar
gsell committed
23

24
#include "Algorithms/PBunchDefs.h"
gsell's avatar
gsell committed
25

frey_m's avatar
frey_m committed
26 27
#include "StatWriter.h"
#include "H5Writer.h"
frey_m's avatar
frey_m committed
28
#include "MultiBunchDump.h"
29

30 31
template <class T, unsigned Dim>
class PartBunchBase;
32
class BoundaryGeometry;
33
class H5PartWrapper;
gsell's avatar
gsell committed
34 35 36

class DataSink {
public:
frey_m's avatar
frey_m committed
37
    typedef MultiBunchDump::beaminfo_t      beaminfo_t;
frey_m's avatar
frey_m committed
38 39 40 41 42
    typedef StatWriter::losses_t            losses_t;
    typedef std::unique_ptr<StatWriter>     statWriter_t;
    typedef std::unique_ptr<SDDSWriter>     sddsWriter_t;
    typedef std::unique_ptr<H5Writer>       h5Writer_t;
    typedef std::unique_ptr<MultiBunchDump> mbWriter_t;
frey_m's avatar
frey_m committed
43 44
    
    
gsell's avatar
gsell committed
45 46 47 48 49 50
    /** \brief Default constructor.
     *
     * The default constructor is called at the start of a new calculation (as
     * opposed to a calculation restart).
     */
    DataSink();
frey_m's avatar
frey_m committed
51 52
    DataSink(H5PartWrapper *h5wrapper, bool restart);
    DataSink(H5PartWrapper *h5wrapper);
53

frey_m's avatar
frey_m committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    void dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[]) const;
    
    int dumpH5(PartBunchBase<double, 3> *beam, Vector_t FDext[], double meanEnergy,
               double refPr, double refPt, double refPz,
               double refR, double refTheta, double refZ,
               double azimuth, double elevation, bool local) const;
    
    //FIXME https://gitlab.psi.ch/OPAL/src/issues/245
    void dumpH5(EnvelopeBunch &beam, Vector_t FDext[],
                double sposHead, double sposRef,
                double sposTail) const;
    
    
    void dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[],
                  const double& azimuth = -1) const;
    
    void dumpSDDS(PartBunchBase<double, 3> *beam, Vector_t FDext[],
                  const losses_t &losses = losses_t(), const double& azimuth = -1) const;
    
    //FIXME https://gitlab.psi.ch/OPAL/src/issues/245
    void dumpSDDS(EnvelopeBunch &beam, Vector_t FDext[],
                  double sposHead, double sposRef, double sposTail) const;
gsell's avatar
gsell committed
76 77 78 79

    /** \brief Write cavity information from  H5 file
     */
    void storeCavityInformation();
frey_m's avatar
frey_m committed
80
    
frey_m's avatar
frey_m committed
81
    void changeH5Wrapper(H5PartWrapper *h5wrapper);
frey_m's avatar
frey_m committed
82 83
    
    
gsell's avatar
gsell committed
84 85 86 87 88
    /**
     * Write particle loss data to an ASCII fille for histogram
     * @param fn specifies the name of ASCII file
     * @param beam
     */
frey_m's avatar
frey_m committed
89
    void writePartlossZASCII(PartBunchBase<double, 3> *beam, BoundaryGeometry &bg, std::string fn);
frey_m's avatar
frey_m committed
90
    
gsell's avatar
gsell committed
91 92 93 94 95 96 97 98
    /**
     * Write geometry points and surface triangles to vtk file
     *
     * @param fn specifies the name of vtk file contains the geometry
     *
     */
    void writeGeomToVtk(BoundaryGeometry &bg, std::string fn);
    //void writeGeoContourToVtk(BoundaryGeometry &bg, std::string fn);
frey_m's avatar
frey_m committed
99 100
    
    
gsell's avatar
gsell committed
101 102 103 104 105 106
    /**
     * Write impact number and outgoing secondaries in each time step
     *
     * @param fn specifies the name of vtk file contains the geometry
     *
     */
frey_m's avatar
frey_m committed
107 108 109 110 111 112 113
    void writeImpactStatistics(PartBunchBase<double, 3> *beam,
                               long long int &step,
                               size_t &impact,
                               double &sey_num,
                               size_t numberOfFieldEmittedParticles,
                               bool nEmissionMode,
                               std::string fn);
frey_m's avatar
frey_m committed
114

frey_m's avatar
frey_m committed
115 116
    /** no statWriter_m dump
     * @param beam
frey_m's avatar
frey_m committed
117
     * @param binfo is the beam info
frey_m's avatar
frey_m committed
118 119
     */
    void writeMultiBunchStatistics(PartBunchBase<double, 3> *beam,
frey_m's avatar
frey_m committed
120
                                   MultiBunchHandler* mbhandler);
121

gsell's avatar
gsell committed
122
private:
123 124
    DataSink(const DataSink &) { }
    DataSink &operator = (const DataSink &) { return *this; }
frey_m's avatar
frey_m committed
125
    
frey_m's avatar
frey_m committed
126
    void rewindLines();
frey_m's avatar
frey_m committed
127
    
128 129
    void init(bool restart = false,
              H5PartWrapper* h5wrapper = nullptr);
frey_m's avatar
frey_m committed
130
    
frey_m's avatar
frey_m committed
131 132 133 134
    
    h5Writer_t      h5Writer_m;
    statWriter_t    statWriter_m;
    std::vector<sddsWriter_t> sddsWriter_m;
frey_m's avatar
frey_m committed
135
    std::vector<mbWriter_t> mbWriter_m;
frey_m's avatar
frey_m committed
136
    
137
    static std::string convertToString(int number);
gsell's avatar
gsell committed
138 139 140

    /// needed to create index for vtk file
    unsigned int lossWrCounter_m;
141 142 143

    /// Timer to track statistics write time.
    IpplTimings::TimerRef StatMarkerTimer_m;
gsell's avatar
gsell committed
144 145
};

146 147 148 149 150 151 152

inline
std::string DataSink::convertToString(int number) {
    std::stringstream ss;
    ss << std::setw(5) << std::setfill('0') <<  number;
    return ss.str();
}
153

154

gsell's avatar
gsell committed
155 156
#endif // DataSink_H_

gsell's avatar
gsell committed
157 158 159 160 161
// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode:nil
162
// End: