OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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")), h5wrapper_m(h5wrapper), H5call_m(0) {
22 if (!restart) {
23 h5wrapper->writeHeader();
24 }
25 h5wrapper->close();
26}
27
29 PartBunch_t& beam, Vector_t<double, 3> FDext[], size_t particleContainerIndex) {
30 IpplTimings::startTimer(H5PartTimer_m);
31 std::map<std::string, double> additionalAttributes = {
32 std::make_pair("B-ref_x", FDext[0](0)), std::make_pair("B-ref_z", FDext[0](1)),
33 std::make_pair("B-ref_y", FDext[0](2)), std::make_pair("E-ref_x", FDext[1](0)),
34 std::make_pair("E-ref_z", FDext[1](1)), std::make_pair("E-ref_y", FDext[1](2))};
35
36 h5wrapper_m->writeStep(&beam, additionalAttributes, particleContainerIndex);
37 IpplTimings::stopTimer(H5PartTimer_m);
38}
39
41 PartBunch_t& beam, Vector_t<double, 3> FDext[], double /*meanEnergy*/, double refPr,
42 double refPt, double refPz, double refR, double refTheta, double refZ, double azimuth,
43 double elevation, bool /*local*/, size_t particleContainerIndex) {
44 auto pc = beam.getParticleContainer(particleContainerIndex);
45 if (!pc || pc->getTotalNum() < 3) return -1; // single-particle / tune modes
46
47 IpplTimings::startTimer(H5PartTimer_m);
48 std::map<std::string, double> additionalAttributes = {
49 std::make_pair("REFPR", refPr), std::make_pair("REFPT", refPt),
50 std::make_pair("REFPZ", refPz), std::make_pair("REFR", refR),
51 std::make_pair("REFTHETA", refTheta), std::make_pair("REFZ", refZ),
52 std::make_pair("AZIMUTH", azimuth), std::make_pair("ELEVATION", elevation),
53 std::make_pair("B-head_x", FDext[0](0)), std::make_pair("B-head_z", FDext[0](1)),
54 std::make_pair("B-head_y", FDext[0](2)), std::make_pair("E-head_x", FDext[1](0)),
55 std::make_pair("E-head_z", FDext[1](1)), std::make_pair("E-head_y", FDext[1](2)),
56 std::make_pair("B-ref_x", FDext[2](0)), std::make_pair("B-ref_z", FDext[2](1)),
57 std::make_pair("B-ref_y", FDext[2](2)), std::make_pair("E-ref_x", FDext[3](0)),
58 std::make_pair("E-ref_z", FDext[3](1)), std::make_pair("E-ref_y", FDext[3](2)),
59 std::make_pair("B-tail_x", FDext[4](0)), std::make_pair("B-tail_z", FDext[4](1)),
60 std::make_pair("B-tail_y", FDext[4](2)), std::make_pair("E-tail_x", FDext[5](0)),
61 std::make_pair("E-tail_z", FDext[5](1)), std::make_pair("E-tail_y", FDext[5](2))};
62
63 h5wrapper_m->writeStep(&beam, additionalAttributes, particleContainerIndex);
64 IpplTimings::stopTimer(H5PartTimer_m);
65
66 ++H5call_m;
67 return H5call_m - 1;
68}
ippl::Vector< T, Dim > Vector_t
virtual void writeStep(PartBunch_t *, const std::map< std::string, double > &, size_t particleContainerIndex=0)=0
virtual void writeHeader()=0
void writePhaseSpace(PartBunch_t &beam, Vector_t< double, 3 > FDext[], size_t particleContainerIndex=0)
Dumps Phase Space to H5 file.
Definition H5Writer.cpp:28
IpplTimings::TimerRef H5PartTimer_m
Timer to track particle data/H5 file write time.
Definition H5Writer.h:73
H5Writer(H5PartWrapper *h5wrapper, bool restart)
Definition H5Writer.cpp:20
H5PartWrapper * h5wrapper_m
Definition H5Writer.h:75
int H5call_m
Current record, or time step, of H5 file.
Definition H5Writer.h:78