OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
H5Writer.cpp
Go to the documentation of this file.
1//
2// Class H5Writer
3// Interface for H5 writers.
4//
5// Copyright (c) 2019-2020, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#include "H5Writer.h"
19
20H5Writer::H5Writer(H5PartWrapper* h5wrapper, bool restart)
21 : H5PartTimer_m(IpplTimings::getTimer("Write H5-File"))
22 , h5wrapper_m(h5wrapper)
23 , H5call_m(0)
24{
25 if ( !restart ) {
26 h5wrapper->writeHeader();
27 }
28 h5wrapper->close();
29}
30
31
34 std::map<std::string, double> additionalAttributes = {
35 std::make_pair("B-ref_x", FDext[0](0)),
36 std::make_pair("B-ref_z", FDext[0](1)),
37 std::make_pair("B-ref_y", FDext[0](2)),
38 std::make_pair("E-ref_x", FDext[1](0)),
39 std::make_pair("E-ref_z", FDext[1](1)),
40 std::make_pair("E-ref_y", FDext[1](2))};
41
42 h5wrapper_m->writeStep(beam, additionalAttributes);
44}
45
46
47int H5Writer::writePhaseSpace(PartBunchBase<double, 3> *beam, Vector_t FDext[], double /*meanEnergy*/,
48 double refPr, double refPt, double refPz,
49 double refR, double refTheta, double refZ,
50 double azimuth, double elevation, bool /*local*/) {
51
52 if (beam->getTotalNum() < 3) return -1; // in single particle mode and tune calculation (2 particles) we do not need h5 data
53
55 std::map<std::string, double> additionalAttributes = {
56 std::make_pair("REFPR", refPr),
57 std::make_pair("REFPT", refPt),
58 std::make_pair("REFPZ", refPz),
59 std::make_pair("REFR", refR),
60 std::make_pair("REFTHETA", refTheta),
61 std::make_pair("REFZ", refZ),
62 std::make_pair("AZIMUTH", azimuth),
63 std::make_pair("ELEVATION", elevation),
64 std::make_pair("B-head_x", FDext[0](0)),
65 std::make_pair("B-head_z", FDext[0](1)),
66 std::make_pair("B-head_y", FDext[0](2)),
67 std::make_pair("E-head_x", FDext[1](0)),
68 std::make_pair("E-head_z", FDext[1](1)),
69 std::make_pair("E-head_y", FDext[1](2)),
70 std::make_pair("B-ref_x", FDext[2](0)),
71 std::make_pair("B-ref_z", FDext[2](1)),
72 std::make_pair("B-ref_y", FDext[2](2)),
73 std::make_pair("E-ref_x", FDext[3](0)),
74 std::make_pair("E-ref_z", FDext[3](1)),
75 std::make_pair("E-ref_y", FDext[3](2)),
76 std::make_pair("B-tail_x", FDext[4](0)),
77 std::make_pair("B-tail_z", FDext[4](1)),
78 std::make_pair("B-tail_y", FDext[4](2)),
79 std::make_pair("E-tail_x", FDext[5](0)),
80 std::make_pair("E-tail_z", FDext[5](1)),
81 std::make_pair("E-tail_y", FDext[5](2))};
82
83 h5wrapper_m->writeStep(beam, additionalAttributes);
85
86 ++ H5call_m;
87 return H5call_m - 1;
88}
size_t getTotalNum() const
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &)=0
virtual void writeHeader()=0
IpplTimings::TimerRef H5PartTimer_m
Timer to track particle data/H5 file write time.
Definition: H5Writer.h:75
H5Writer(H5PartWrapper *h5wrapper, bool restart)
Definition: H5Writer.cpp:20
H5PartWrapper * h5wrapper_m
Definition: H5Writer.h:77
void writePhaseSpace(PartBunchBase< double, 3 > *beam, Vector_t FDext[])
Dumps Phase Space to H5 file.
Definition: H5Writer.cpp:32
int H5call_m
Current record, or time step, of H5 file.
Definition: H5Writer.h:80
static void stopTimer(TimerRef t)
Definition: IpplTimings.h:192
static void startTimer(TimerRef t)
Definition: IpplTimings.h:187