H5Writer.cpp 5.9 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//
// Class H5Writer
//   Interface for H5 writers.
//
// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
frey_m's avatar
frey_m committed
18 19
#include "H5Writer.h"

20
H5Writer::H5Writer(H5PartWrapper* h5wrapper, bool restart)
frey_m's avatar
frey_m committed
21
    : H5PartTimer_m(IpplTimings::getTimer("Write H5-File"))
frey_m's avatar
frey_m committed
22
    , h5wrapper_m(h5wrapper)
frey_m's avatar
frey_m committed
23
    , H5call_m(0)
24 25 26 27 28 29
{
    if ( !restart ) {
        h5wrapper->writeHeader();
    }
    h5wrapper->close();
}
frey_m's avatar
frey_m committed
30 31


frey_m's avatar
frey_m committed
32
void H5Writer::writePhaseSpace(PartBunchBase<double, 3> *beam, Vector_t FDext[]) {
frey_m's avatar
frey_m committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
    IpplTimings::startTimer(H5PartTimer_m);
    std::map<std::string, double> additionalAttributes = {
        std::make_pair("B-ref_x", FDext[0](0)),
        std::make_pair("B-ref_z", FDext[0](1)),
        std::make_pair("B-ref_y", FDext[0](2)),
        std::make_pair("E-ref_x", FDext[1](0)),
        std::make_pair("E-ref_z", FDext[1](1)),
        std::make_pair("E-ref_y", FDext[1](2))};

    h5wrapper_m->writeStep(beam, additionalAttributes);
    IpplTimings::stopTimer(H5PartTimer_m);
}


47
int H5Writer::writePhaseSpace(PartBunchBase<double, 3> *beam, Vector_t FDext[], double /*meanEnergy*/,
frey_m's avatar
frey_m committed
48 49
                              double refPr, double refPt, double refPz,
                              double refR, double refTheta, double refZ,
50
                              double azimuth, double elevation, bool /*local*/) {
frey_m's avatar
frey_m committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

    if (beam->getTotalNum() < 3) return -1; // in single particle mode and tune calculation (2 particles) we do not need h5 data

    IpplTimings::startTimer(H5PartTimer_m);
    std::map<std::string, double> additionalAttributes = {
        std::make_pair("REFPR", refPr),
        std::make_pair("REFPT", refPt),
        std::make_pair("REFPZ", refPz),
        std::make_pair("REFR", refR),
        std::make_pair("REFTHETA", refTheta),
        std::make_pair("REFZ", refZ),
        std::make_pair("AZIMUTH", azimuth),
        std::make_pair("ELEVATION", elevation),
        std::make_pair("B-head_x", FDext[0](0)),
        std::make_pair("B-head_z", FDext[0](1)),
        std::make_pair("B-head_y", FDext[0](2)),
        std::make_pair("E-head_x", FDext[1](0)),
        std::make_pair("E-head_z", FDext[1](1)),
        std::make_pair("E-head_y", FDext[1](2)),
        std::make_pair("B-ref_x",  FDext[2](0)),
        std::make_pair("B-ref_z",  FDext[2](1)),
        std::make_pair("B-ref_y",  FDext[2](2)),
        std::make_pair("E-ref_x",  FDext[3](0)),
        std::make_pair("E-ref_z",  FDext[3](1)),
        std::make_pair("E-ref_y",  FDext[3](2)),
        std::make_pair("B-tail_x", FDext[4](0)),
        std::make_pair("B-tail_z", FDext[4](1)),
        std::make_pair("B-tail_y", FDext[4](2)),
        std::make_pair("E-tail_x", FDext[5](0)),
        std::make_pair("E-tail_z", FDext[5](1)),
        std::make_pair("E-tail_y", FDext[5](2))};

    h5wrapper_m->writeStep(beam, additionalAttributes);
    IpplTimings::stopTimer(H5PartTimer_m);

    ++ H5call_m;
    return H5call_m - 1;
}


91
void H5Writer::writePhaseSpace(EnvelopeBunch &/*beam*/, Vector_t FDext[],
frey_m's avatar
frey_m committed
92 93 94
                               double sposHead, double sposRef,
                               double sposTail)
{
frey_m's avatar
frey_m committed
95 96
    // FIXME https://gitlab.psi.ch/OPAL/src/issues/245

frey_m's avatar
frey_m committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    IpplTimings::startTimer(H5PartTimer_m);
    std::map<std::string, double> additionalAttributes = {
        std::make_pair("sposHead", sposHead),
        std::make_pair("sposRef",  sposRef),
        std::make_pair("sposTail", sposTail),
        std::make_pair("B-head_x", FDext[0](0)),
        std::make_pair("B-head_z", FDext[0](1)),
        std::make_pair("B-head_y", FDext[0](2)),
        std::make_pair("E-head_x", FDext[1](0)),
        std::make_pair("E-head_z", FDext[1](1)),
        std::make_pair("E-head_y", FDext[1](2)),
        std::make_pair("B-ref_x",  FDext[2](0)),
        std::make_pair("B-ref_z",  FDext[2](1)),
        std::make_pair("B-ref_y",  FDext[2](2)),
        std::make_pair("E-ref_x",  FDext[3](0)),
        std::make_pair("E-ref_z",  FDext[3](1)),
        std::make_pair("E-ref_y",  FDext[3](2)),
        std::make_pair("B-tail_x", FDext[4](0)),
        std::make_pair("B-tail_z", FDext[4](1)),
        std::make_pair("B-tail_y", FDext[4](2)),
        std::make_pair("E-tail_x", FDext[5](0)),
        std::make_pair("E-tail_z", FDext[5](1)),
        std::make_pair("E-tail_y", FDext[5](2))};

frey_m's avatar
frey_m committed
121
    // does not compile with that line --> should be fixed with https://gitlab.psi.ch/OPAL/src/issues/245
frey_m's avatar
frey_m committed
122
//     h5wrapper_m->writeStep(&beam, additionalAttributes);
frey_m's avatar
frey_m committed
123
    IpplTimings::stopTimer(H5PartTimer_m);
frey_m's avatar
frey_m committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
}


//FIXME https://gitlab.psi.ch/OPAL/src/issues/245
// void H5Writer::stashPhaseSpaceEnvelope(EnvelopeBunch &beam, Vector_t FDext[], double sposHead, double sposRef, double sposTail) {
// 
//     if (!doHDF5_m) return;
// 
//     /// Start timer.
//     IpplTimings::startTimer(H5PartTimer_m);
// 
//     static_cast<H5PartWrapperForPS*>(h5wrapper_m)->stashPhaseSpaceEnvelope(beam,
//                                                                            FDext,
//                                                                            sposHead,
//                                                                            sposRef,
//                                                                            sposTail);
//     H5call_m++;
// 
//     /// %Stop timer.
//     IpplTimings::stopTimer(H5PartTimer_m);
// }
// 
// void H5Writer::dumpStashedPhaseSpaceEnvelope() {
// 
//     if (!doHDF5_m) return;
// 
//     static_cast<H5PartWrapperForPS*>(h5wrapper_m)->dumpStashedPhaseSpaceEnvelope();
// 
//     /// %Stop timer.
//     IpplTimings::stopTimer(H5PartTimer_m);
// }