OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
MultiBunchDump.cpp
Go to the documentation of this file.
1//
2// Class MultiBunchDump
3// This class writes a SDDS file of single bunch statistics in multibunch simulations.
4//
5// Copyright (c) 2018 - 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// Implemented as part of the PhD thesis
9// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
21#include "MultiBunchDump.h"
22
23#include <sstream>
24
25#include "Utilities/Timer.h"
26#include "Utilities/Util.h"
29#include "Ippl.h"
30
31extern Inform *gmsg;
32
33MultiBunchDump::MultiBunchDump(const std::string& fname, bool restart)
34 : StatBaseWriter(fname, restart)
35{ }
36
37
39
40 if (this->hasColumns()) {
41 return;
42 }
43
44 columns_m.addColumn("t", "double", "ns", "Time");
45 columns_m.addColumn("s", "double", "m", "Path length");
46 columns_m.addColumn("azimuth", "double", "deg", "Azimuth in global coordinates");
47 columns_m.addColumn("radius", "double", "mm", "Radius in global coordinates");
48 columns_m.addColumn("numParticles", "long", "1", "Number of Macro Particles");
49 columns_m.addColumn("energy", "double", "MeV", "Mean Bunch Energy");
50 columns_m.addColumn("dE", "double", "MeV", "energy spread of the beam");
51
52 columns_m.addColumn("rms_x", "double", "m", "RMS Beamsize in x");
53 columns_m.addColumn("rms_y", "double", "m", "RMS Beamsize in y");
54 columns_m.addColumn("rms_s", "double", "m", "RMS Beamsize in s");
55
56 columns_m.addColumn("rms_px", "double", "1", "RMS Normalized Momenta in x");
57 columns_m.addColumn("rms_py", "double", "1", "RMS Normalized Momenta in y");
58 columns_m.addColumn("rms_ps", "double", "1", "RMS Normalized Momenta in s");
59
60 columns_m.addColumn("emit_x", "double", "m", "Normalized Emittance x");
61 columns_m.addColumn("emit_y", "double", "m", "Normalized Emittance y");
62 columns_m.addColumn("emit_s", "double", "m", "Normalized Emittance s");
63
64 columns_m.addColumn("mean_x", "double", "m", "Mean Beam Position in x");
65 columns_m.addColumn("mean_y", "double", "m", "Mean Beam Position in y");
66 columns_m.addColumn("mean_s", "double", "m", "Mean Beam Position in s");
67
68 columns_m.addColumn("xpx", "double", "1", "RMS Correlation xpx");
69 columns_m.addColumn("ypy", "double", "1", "RMS Correlation ypy");
70 columns_m.addColumn("zpz", "double", "1", "RMS Correlation zpz");
71
72 columns_m.addColumn("halo_x", "double", "1", "Halo in x");
73 columns_m.addColumn("halo_y", "double", "1", "Halo in y");
74 columns_m.addColumn("halo_z", "double", "1", "Halo in z");
75
76 if ( mode_m == std::ios::app )
77 return;
78
79 OPALTimer::Timer simtimer;
80 std::string dateStr(simtimer.date());
81 std::string timeStr(simtimer.time());
82
83 std::stringstream ss;
84 ss << "Multi Bunch Statistics data '"
86 << "' " << dateStr << " " << timeStr;
87
88 this->addDescription(ss.str(), "multi bunch stat parameters");
89
91
92 this->addInfo("ascii", 1);
93}
94
95
97 const beaminfo_t& binfo) {
98
99 if ( Ippl::myNode() > 0)
100 return;
101
102 fillHeader();
103
104 this->open();
105
106 this->writeHeader();
107
108 columns_m.addColumnValue("t", binfo.time);
110 columns_m.addColumnValue("azimuth", binfo.azimuth);
111 columns_m.addColumnValue("radius", binfo.radius);
112 columns_m.addColumnValue("numParticles", binfo.nParticles);
113 columns_m.addColumnValue("energy", binfo.ekin);
114 columns_m.addColumnValue("dE", binfo.dEkin);
115
116 columns_m.addColumnValue("rms_x", binfo.rrms[0]);
117 columns_m.addColumnValue("rms_y", binfo.rrms[1]);
118 columns_m.addColumnValue("rms_s", binfo.rrms[2]);
119
120 columns_m.addColumnValue("rms_px", binfo.prms[0]);
121 columns_m.addColumnValue("rms_py", binfo.prms[1]);
122 columns_m.addColumnValue("rms_ps", binfo.prms[2]);
123
124 columns_m.addColumnValue("emit_x", binfo.emit[0]);
125 columns_m.addColumnValue("emit_y", binfo.emit[1]);
126 columns_m.addColumnValue("emit_s", binfo.emit[2]);
127
128 columns_m.addColumnValue("mean_x", binfo.mean[0]);
129 columns_m.addColumnValue("mean_y", binfo.mean[1]);
130 columns_m.addColumnValue("mean_s", binfo.mean[2]);
131
132 columns_m.addColumnValue("xpx", binfo.correlation[0]);
133 columns_m.addColumnValue("ypy", binfo.correlation[1]);
134 columns_m.addColumnValue("zpz", binfo.correlation[2]);
135
136 columns_m.addColumnValue("halo_x", binfo.halo[0]);
137 columns_m.addColumnValue("halo_y", binfo.halo[1]);
138 columns_m.addColumnValue("halo_z", binfo.halo[2]);
139
140 this->writeRow();
141
142 this->close();
143}
Inform * gmsg
Definition: Main.cpp:61
std::string getInputFn()
get opals input filename
Definition: OpalData.cpp:665
static OpalData * getInstance()
Definition: OpalData.cpp:196
MultiBunchDump(const std::string &fname, bool restart)
void write(const PartBunchBase< double, 3 > *beam, const beaminfo_t &binfo)
void addColumn(const std::string &name, const std::string &type, const std::string &unit, const std::string &desc, std::ios_base::fmtflags flags=std::ios_base::scientific, unsigned short precision=15)
void addColumnValue(const std::string &name, const T &val)
Definition: SDDSColumnSet.h:63
SDDSColumnSet columns_m
Definition: SDDSWriter.h:126
bool hasColumns() const
Definition: SDDSWriter.h:207
void addDefaultParameters()
Definition: SDDSWriter.cpp:211
void addDescription(const std::string &text, const std::string &content)
Definition: SDDSWriter.h:164
void open()
Definition: SDDSWriter.cpp:134
void writeHeader()
Write SDDS header.
Definition: SDDSWriter.cpp:151
std::ios_base::openmode mode_m
First write to the statistics output file.
Definition: SDDSWriter.h:124
void close()
Definition: SDDSWriter.cpp:144
void writeRow()
Definition: SDDSWriter.h:192
void addInfo(const std::string &mode, const size_t &no_row_counts)
Definition: SDDSWriter.h:185
std::string date() const
Return date.
Definition: Timer.cpp:35
std::string time() const
Return time.
Definition: Timer.cpp:42
Definition: Inform.h:42
static int myNode()
Definition: IpplInfo.cpp:691