OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
StatWriter.cpp
Go to the documentation of this file.
1//
2// Class StatWriter
3// This class writes bunch statistics (*.stat).
4//
5// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6// Christof Metzger-Kraus, Open Sourcerer
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
19#include "StatWriter.h"
20
23#include "Utilities/Timer.h"
24#include "Physics/Units.h"
25
26#include <sstream>
27
28StatWriter::StatWriter(const std::string& fname, bool restart)
29 : StatBaseWriter(fname, restart)
30{ }
31
32
34
35 if (this->hasColumns()) {
36 return;
37 }
38
39 columns_m.addColumn("t", "double", "ns", "Time");
40 columns_m.addColumn("s", "double", "m", "Path length");
41 // in OPAL-cycl the particle with ID 0 is tracked and counted but left out of
42 // the moments (DistributionMoments::isParticleExcluded)
43 if (OpalData::getInstance()->isInOPALCyclMode() && !Options::amr) {
44 columns_m.addColumn("numParticles", "long", "1",
45 "Number of Macro Particles including the one with ID 0 that the moments exclude");
46 } else {
47 columns_m.addColumn("numParticles", "long", "1", "Number of Macro Particles");
48 }
49 columns_m.addColumn("charge", "double", "C", "Bunch Charge");
50 columns_m.addColumn("energy", "double", "MeV", "Mean Bunch Energy");
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("ref_x", "double", "m", "x coordinate of reference particle in lab cs");
69 columns_m.addColumn("ref_y", "double", "m", "y coordinate of reference particle in lab cs");
70 columns_m.addColumn("ref_z", "double", "m", "z coordinate of reference particle in lab cs");
71
72 columns_m.addColumn("ref_px", "double", "1", "x momentum of reference particle in lab cs");
73 columns_m.addColumn("ref_py", "double", "1", "y momentum of reference particle in lab cs");
74 columns_m.addColumn("ref_pz", "double", "1", "z momentum of reference particle in lab cs");
75
76 columns_m.addColumn("max_x", "double", "m", "Maximum x coordinate of the particles");
77 columns_m.addColumn("max_y", "double", "m", "Maximum y coordinate of the particles");
78 columns_m.addColumn("max_s", "double", "m", "Maximum s coordinate of the particles");
79
80 columns_m.addColumn("xpx", "double", "1", "Correlation xpx");
81 columns_m.addColumn("ypy", "double", "1", "Correlation ypy");
82 columns_m.addColumn("zpz", "double", "1", "Correlation zpz");
83
84 // not the dispersion: non-central second moments with pz, see DistributionMoments::getDx()
85 columns_m.addColumn("Dx", "double", "m", "Raw moment mean(x*pz) (not the dispersion)");
86 columns_m.addColumn("DDx", "double", "1", "Raw moment mean(px*pz) (not the dispersion derivative)");
87 columns_m.addColumn("Dy", "double", "m", "Raw moment mean(y*pz) (not the dispersion)");
88 columns_m.addColumn("DDy", "double", "1", "Raw moment mean(py*pz) (not the dispersion derivative)");
89
90 columns_m.addColumn("Bx_ref", "double", "T", "Bx-Field component of ref particle");
91 columns_m.addColumn("By_ref", "double", "T", "By-Field component of ref particle");
92 columns_m.addColumn("Bz_ref", "double", "T", "Bz-Field component of ref particle");
93
94 columns_m.addColumn("Ex_ref", "double", "MV/m", "Ex-Field component of ref particle");
95 columns_m.addColumn("Ey_ref", "double", "MV/m", "Ey-Field component of ref particle");
96 columns_m.addColumn("Ez_ref", "double", "MV/m", "Ez-Field component of ref particle");
97
98 columns_m.addColumn("dE", "double", "MeV", "energy spread of the beam");
99 columns_m.addColumn("dt", "double", "ns", "time step size");
100 columns_m.addColumn("partsOutside", "double", "1", "outside n*sigma of the beam");
101 columns_m.addColumn("DebyeLength", "double", "m", "Debye length in the boosted frame");
102 columns_m.addColumn("plasmaParameter", "double", "1", "Plasma parameter that gives no. of particles in a Debye sphere");
103 columns_m.addColumn("temperature", "double", "K", "Temperature of the beam");
104 columns_m.addColumn("rmsDensity", "double", "1", "RMS number density of the beam");
105
107 columns_m.addColumn("68_Percentile_x", "double", "m",
108 "68.27 percentile (1 sigma of normal distribution) of x-component of position");
109 columns_m.addColumn("68_Percentile_y", "double", "m",
110 "68.27 percentile (1 sigma of normal distribution) of y-component of position");
111 columns_m.addColumn("68_Percentile_z", "double", "m",
112 "68.27 percentile (1 sigma of normal distribution) of z-component of position");
113
114 columns_m.addColumn("95_Percentile_x", "double", "m",
115 "95.45 percentile (2 sigma of normal distribution) of x-component of position");
116 columns_m.addColumn("95_Percentile_y", "double", "m",
117 "95.45 percentile (2 sigma of normal distribution) of y-component of position");
118 columns_m.addColumn("95_Percentile_z", "double", "m",
119 "95.45 percentile (2 sigma of normal distribution) of z-component of position");
120
121 columns_m.addColumn("99_Percentile_x", "double", "m",
122 "99.73 percentile (3 sigma of normal distribution) of x-component of position");
123 columns_m.addColumn("99_Percentile_y", "double", "m",
124 "99.73 percentile (3 sigma of normal distribution) of y-component of position");
125 columns_m.addColumn("99_Percentile_z", "double", "m",
126 "99.73 percentile (3 sigma of normal distribution) of z-component of position");
127
128 columns_m.addColumn("99_99_Percentile_x", "double", "m",
129 "99.994 percentile (4 sigma of normal distribution) of x-component of position");
130 columns_m.addColumn("99_99_Percentile_y", "double", "m",
131 "99.994 percentile (4 sigma of normal distribution) of y-component of position");
132 columns_m.addColumn("99_99_Percentile_z", "double", "m",
133 "99.994 percentile (4 sigma of normal distribution) of z-component of position");
134
135 columns_m.addColumn("normalizedEps68Percentile_x", "double", "m",
136 "x-component of normalized emittance at 68 percentile (1 sigma of normal distribution)");
137 columns_m.addColumn("normalizedEps68Percentile_y", "double", "m",
138 "y-component of normalized emittance at 68 percentile (1 sigma of normal distribution)");
139 columns_m.addColumn("normalizedEps68Percentile_z", "double", "m",
140 "z-component of normalized emittance at 68 percentile (1 sigma of normal distribution)");
141
142 columns_m.addColumn("normalizedEps95Percentile_x", "double", "m",
143 "x-component of normalized emittance at 95 percentile (2 sigma of normal distribution)");
144 columns_m.addColumn("normalizedEps95Percentile_y", "double", "m",
145 "y-component of normalized emittance at 95 percentile (2 sigma of normal distribution)");
146 columns_m.addColumn("normalizedEps95Percentile_z", "double", "m",
147 "z-component of normalized emittance at 95 percentile (2 sigma of normal distribution)");
148
149 columns_m.addColumn("normalizedEps99Percentile_x", "double", "m",
150 "x-component of normalized emittance at 99 percentile (3 sigma of normal distribution)");
151 columns_m.addColumn("normalizedEps99Percentile_y", "double", "m",
152 "y-component of normalized emittance at 99 percentile (3 sigma of normal distribution)");
153 columns_m.addColumn("normalizedEps99Percentile_z", "double", "m",
154 "z-component of normalized emittance at 99 percentile (3 sigma of normal distribution)");
155
156 columns_m.addColumn("normalizedEps99_99Percentile_x", "double", "m",
157 "x-component of normalized emittance at 99.99 percentile (4 sigma of normal distribution)");
158 columns_m.addColumn("normalizedEps99_99Percentile_y", "double", "m",
159 "y-component of normalized emittance at 99.99 percentile (4 sigma of normal distribution)");
160 columns_m.addColumn("normalizedEps99_99Percentile_z", "double", "m",
161 "z-component of normalized emittance at 99.99 percentile (4 sigma of normal distribution)");
162 }
164 columns_m.addColumn("S11","double","m**2","element 1,1 of 6D beam matrix");
165 columns_m.addColumn("S12","double","m","element 1,2 of 6D beam matrix");
166 columns_m.addColumn("S13","double","m**2","element 1,3 of 6D beam matrix");
167 columns_m.addColumn("S14","double","m","element 1,4 of 6D beam matrix");
168 columns_m.addColumn("S15","double","m**2","element 1,5 of 6D beam matrix");
169 columns_m.addColumn("S16","double","m","element 1,6 of 6D beam matrix");
170 columns_m.addColumn("S22","double","1","element 2,2 of 6D beam matrix");
171 columns_m.addColumn("S23","double","m","element 2,3 of 6D beam matrix");
172 columns_m.addColumn("S24","double","1","element 2,4 of 6D beam matrix");
173 columns_m.addColumn("S25","double","m","element 2,5 of 6D beam matrix");
174 columns_m.addColumn("S26","double","1","element 2,6 of 6D beam matrix");
175 columns_m.addColumn("S33","double","m**2","element 3,3 of 6D beam matrix");
176 columns_m.addColumn("S34","double","m","element 3,4 of 6D beam matrix");
177 columns_m.addColumn("S35","double","m**2","element 3,5 of 6D beam matrix");
178 columns_m.addColumn("S36","double","m","element 3,6 of 6D beam matrix");
179 columns_m.addColumn("S44","double","1","element 4,4 of 6D beam matrix");
180 columns_m.addColumn("S45","double","m","element 4,5 of 6D beam matrix");
181 columns_m.addColumn("S46","double","1","element 4,6 of 6D beam matrix");
182 columns_m.addColumn("S55","double","m**2","element 5,5 of 6D beam matrix");
183 columns_m.addColumn("S56","double","m","element 5,6 of 6D beam matrix");
184 columns_m.addColumn("S66","double","1","element 6,6 of 6D beam matrix");
185 }
186 if (OpalData::getInstance()->isInOPALCyclMode() &&
187 Ippl::getNodes() == 1) {
188 columns_m.addColumn("R0_x", "double", "m", "R0 Particle position in x");
189 columns_m.addColumn("R0_y", "double", "m", "R0 Particle position in y");
190 columns_m.addColumn("R0_s", "double", "m", "R0 Particle position in z");
191
192 columns_m.addColumn("P0_x", "double", "1", "R0 Particle momentum in x");
193 columns_m.addColumn("P0_y", "double", "1", "R0 Particle momentum in y");
194 columns_m.addColumn("P0_s", "double", "1", "R0 Particle momentum in z");
195 }
196
197 if (OpalData::getInstance()->isInOPALCyclMode()) {
198 columns_m.addColumn("halo_x", "double", "1", "Halo in x (kurtosis of x minus HALOSHIFT)");
199 columns_m.addColumn("halo_y", "double", "1", "Halo in y (kurtosis of y minus HALOSHIFT)");
200 columns_m.addColumn("halo_z", "double", "1", "Halo in z (kurtosis of z minus HALOSHIFT)");
201
202 columns_m.addColumn("azimuth", "double", "deg",
203 "Azimuth in global coordinates");
204 }
205
206 // FIELDSOLVER, MESHFIT=CORE: the core selection of the last space-charge solve, in its
207 // local frame (x radial, y along the mean momentum, s = z vertical)
210 columns_m.addColumn("scMode", "long", "1",
211 "Mesh fitted to the core (1) or to all particles (0)");
212 columns_m.addColumn("scNumFar", "long", "1",
213 "Live particles outside the core of the space-charge mesh fit");
214 columns_m.addColumn("scNumHalo", "long", "1",
215 "Live particles beyond 10 clipped rms widths in any axis");
216 columns_m.addColumn("scFarCharge", "double", "1",
217 "Charge of the far particles over the live charge");
218 columns_m.addColumn("scClipPasses", "long", "1",
219 "Clipped passes of the core selection");
220 columns_m.addColumn("scNumFlagged", "long", "1",
221 "Far particles outside the mesh where the multipole expansion "
222 "is not valid");
223 columns_m.addColumn("scNumOutside", "long", "1",
224 "Particles outside the space-charge mesh at the last update");
225
226 columns_m.addColumn("scBox_x", "double", "m", "Extent of the core in x");
227 columns_m.addColumn("scBox_y", "double", "m", "Extent of the core in y");
228 columns_m.addColumn("scBox_s", "double", "m", "Extent of the core in z");
229
230 columns_m.addColumn("scHr_x", "double", "m", "Mesh spacing in x of the space-charge solve");
231 columns_m.addColumn("scHr_y", "double", "m", "Mesh spacing in y of the space-charge solve");
232 columns_m.addColumn("scHr_s", "double", "m", "Mesh spacing in z of the space-charge solve");
233
234 columns_m.addColumn("scCoreRms_x", "double", "m", "Clipped rms of the core in x");
235 columns_m.addColumn("scCoreRms_y", "double", "m", "Clipped rms of the core in y");
236 columns_m.addColumn("scCoreRms_s", "double", "m", "Clipped rms of the core in z");
237
238 columns_m.addColumn("scFarMaxDist", "double", "1",
239 "Largest distance of a far particle in clipped rms widths");
240
241 columns_m.addColumn("scFullSteps", "long", "1",
242 "Solves with the mesh fitted to all particles");
243 columns_m.addColumn("scModeSwitches", "long", "1",
244 "Switches between the core and all particles");
245 columns_m.addColumn("scFarFarSampled", "long", "1",
246 "Solves with the far-far field summed over a subsample "
247 "of the far particles");
248 columns_m.addColumn("scNearSampled", "long", "1",
249 "Solves with the exact core field summed over a "
250 "subsample of the core particles");
251 }
252
253 for (size_t i = 0; i < losses.size(); ++ i) {
254 columns_m.addColumn(losses[i].first, "long", "1",
255 "Number of lost particles in element");
256 }
257
258 if ( mode_m == std::ios::app )
259 return;
260
261 OPALTimer::Timer simtimer;
262 std::string dateStr(simtimer.date());
263 std::string timeStr(simtimer.time());
264
265 std::stringstream ss;
266 ss << "Statistics data '"
268 << "' " << dateStr << " " << timeStr;
269
270 this->addDescription(ss.str(), "stat parameters");
271
272 this->addDefaultParameters();
273
274
275 this->addInfo("ascii", 1);
276}
277
278
280 const double& timeStep,
281 const losses_t &losses, const double& azimuth,
282 const size_t npOutside)
283{
284 double Ekin = beam->get_meanKineticEnergy();
285
286 double pathLength = beam->get_sPos();
287
290
291 double Q = beam->getCharge();
292
293 if (Ippl::myNode() != 0) {
294 return;
295 }
296
297 fillHeader(beam, losses);
298
299 this->open();
300
301 this->writeHeader();
302
303 columns_m.addColumnValue("t", beam->getT() * Units::s2ns); // 1
304 columns_m.addColumnValue("s", pathLength); // 2
305 columns_m.addColumnValue("numParticles", beam->getTotalNum()); // 3
306 columns_m.addColumnValue("charge", Q); // 4
307 columns_m.addColumnValue("energy", Ekin); // 5
308
309 columns_m.addColumnValue("rms_x", beam->get_rrms()(0)); // 6
310 columns_m.addColumnValue("rms_y", beam->get_rrms()(1)); // 7
311 columns_m.addColumnValue("rms_s", beam->get_rrms()(2)); // 8
312
313 columns_m.addColumnValue("rms_px", beam->get_prms()(0)); // 9
314 columns_m.addColumnValue("rms_py", beam->get_prms()(1)); // 10
315 columns_m.addColumnValue("rms_ps", beam->get_prms()(2)); // 11
316
317 columns_m.addColumnValue("emit_x", beam->get_norm_emit()(0)); // 12
318 columns_m.addColumnValue("emit_y", beam->get_norm_emit()(1)); // 13
319 columns_m.addColumnValue("emit_s", beam->get_norm_emit()(2)); // 14
320
321 columns_m.addColumnValue("mean_x", beam->get_rmean()(0) ); // 15
322 columns_m.addColumnValue("mean_y", beam->get_rmean()(1) ); // 16
323 columns_m.addColumnValue("mean_s", beam->get_rmean()(2) ); // 17
324
325 columns_m.addColumnValue("ref_x", beam->RefPartR_m(0)); // 18
326 columns_m.addColumnValue("ref_y", beam->RefPartR_m(1)); // 19
327 columns_m.addColumnValue("ref_z", beam->RefPartR_m(2)); // 20
328
329 columns_m.addColumnValue("ref_px", beam->RefPartP_m(0)); // 21
330 columns_m.addColumnValue("ref_py", beam->RefPartP_m(1)); // 22
331 columns_m.addColumnValue("ref_pz", beam->RefPartP_m(2)); // 23
332
333 columns_m.addColumnValue("max_x", beam->get_maxExtent()(0)); // 24
334 columns_m.addColumnValue("max_y", beam->get_maxExtent()(1)); // 25
335 columns_m.addColumnValue("max_s", beam->get_maxExtent()(2)); // 26
336
337 // Write out Courant Snyder parameters.
338 columns_m.addColumnValue("xpx", beam->get_rprms()(0)); // 27
339 columns_m.addColumnValue("ypy", beam->get_rprms()(1)); // 28
340 columns_m.addColumnValue("zpz", beam->get_rprms()(2)); // 29
341
342 // Write out the raw moments <x*pz>, <px*pz>, <y*pz> and <py*pz> (named after the dispersion).
343 columns_m.addColumnValue("Dx", beam->get_Dx()); // 30
344 columns_m.addColumnValue("DDx", beam->get_DDx()); // 31
345 columns_m.addColumnValue("Dy", beam->get_Dy()); // 32
346 columns_m.addColumnValue("DDy", beam->get_DDy()); // 33
347
348 // Write head/reference particle/tail field information.
349 columns_m.addColumnValue("Bx_ref", FDext[0](0)); // 34 B-ref x
350 columns_m.addColumnValue("By_ref", FDext[0](1)); // 35 B-ref y
351 columns_m.addColumnValue("Bz_ref", FDext[0](2)); // 36 B-ref z
352
353 columns_m.addColumnValue("Ex_ref", FDext[1](0)); // 37 E-ref x
354 columns_m.addColumnValue("Ey_ref", FDext[1](1)); // 38 E-ref y
355 columns_m.addColumnValue("Ez_ref", FDext[1](2)); // 39 E-ref z
356
357 columns_m.addColumnValue("dE", beam->getdE()); // 40 dE energy spread
358 columns_m.addColumnValue("dt", timeStep * Units::s2ns); // 41 dt time step size
359 columns_m.addColumnValue("partsOutside", npOutside); // 42 number of particles outside n*sigma
360
361 columns_m.addColumnValue("DebyeLength", beam->get_debyeLength()); // 43 Debye length in the boosted frame
362 columns_m.addColumnValue("plasmaParameter", beam->get_plasmaParameter()); // 43 plasma parameter
363 columns_m.addColumnValue("temperature", beam->get_temperature()); // 44 Temperature
364 columns_m.addColumnValue("rmsDensity", beam->get_rmsDensity()); // 45 RMS number density
365
367 columns_m.addColumnValue("68_Percentile_x", beam->get_68Percentile()[0]);
368 columns_m.addColumnValue("68_Percentile_y", beam->get_68Percentile()[1]);
369 columns_m.addColumnValue("68_Percentile_z", beam->get_68Percentile()[2]);
370
371 columns_m.addColumnValue("95_Percentile_x", beam->get_95Percentile()[0]);
372 columns_m.addColumnValue("95_Percentile_y", beam->get_95Percentile()[1]);
373 columns_m.addColumnValue("95_Percentile_z", beam->get_95Percentile()[2]);
374
375 columns_m.addColumnValue("99_Percentile_x", beam->get_99Percentile()[0]);
376 columns_m.addColumnValue("99_Percentile_y", beam->get_99Percentile()[1]);
377 columns_m.addColumnValue("99_Percentile_z", beam->get_99Percentile()[2]);
378
379 columns_m.addColumnValue("99_99_Percentile_x", beam->get_99_99Percentile()[0]);
380 columns_m.addColumnValue("99_99_Percentile_y", beam->get_99_99Percentile()[1]);
381 columns_m.addColumnValue("99_99_Percentile_z", beam->get_99_99Percentile()[2]);
382
383 columns_m.addColumnValue("normalizedEps68Percentile_x", beam->get_normalizedEps_68Percentile()[0]);
384 columns_m.addColumnValue("normalizedEps68Percentile_y", beam->get_normalizedEps_68Percentile()[1]);
385 columns_m.addColumnValue("normalizedEps68Percentile_z", beam->get_normalizedEps_68Percentile()[2]);
386
387 columns_m.addColumnValue("normalizedEps95Percentile_x", beam->get_normalizedEps_95Percentile()[0]);
388 columns_m.addColumnValue("normalizedEps95Percentile_y", beam->get_normalizedEps_95Percentile()[1]);
389 columns_m.addColumnValue("normalizedEps95Percentile_z", beam->get_normalizedEps_95Percentile()[2]);
390
391 columns_m.addColumnValue("normalizedEps99Percentile_x", beam->get_normalizedEps_99Percentile()[0]);
392 columns_m.addColumnValue("normalizedEps99Percentile_y", beam->get_normalizedEps_99Percentile()[1]);
393 columns_m.addColumnValue("normalizedEps99Percentile_z", beam->get_normalizedEps_99Percentile()[2]);
394
395 columns_m.addColumnValue("normalizedEps99_99Percentile_x", beam->get_normalizedEps_99_99Percentile()[0]);
396 columns_m.addColumnValue("normalizedEps99_99Percentile_y", beam->get_normalizedEps_99_99Percentile()[1]);
397 columns_m.addColumnValue("normalizedEps99_99Percentile_z", beam->get_normalizedEps_99_99Percentile()[2]);
398 }
400 columns_m.addColumnValue("S11", beam->getSigmaMatrix()[0][0]);
401 columns_m.addColumnValue("S12", beam->getSigmaMatrix()[0][1]);
402 columns_m.addColumnValue("S13", beam->getSigmaMatrix()[0][2]);
403 columns_m.addColumnValue("S14", beam->getSigmaMatrix()[0][3]);
404 columns_m.addColumnValue("S15", beam->getSigmaMatrix()[0][4]);
405 columns_m.addColumnValue("S16", beam->getSigmaMatrix()[0][5]);
406 columns_m.addColumnValue("S22", beam->getSigmaMatrix()[1][1]);
407 columns_m.addColumnValue("S23", beam->getSigmaMatrix()[1][2]);
408 columns_m.addColumnValue("S24", beam->getSigmaMatrix()[1][3]);
409 columns_m.addColumnValue("S25", beam->getSigmaMatrix()[1][4]);
410 columns_m.addColumnValue("S26", beam->getSigmaMatrix()[1][5]);
411 columns_m.addColumnValue("S33", beam->getSigmaMatrix()[2][2]);
412 columns_m.addColumnValue("S34", beam->getSigmaMatrix()[2][3]);
413 columns_m.addColumnValue("S35", beam->getSigmaMatrix()[2][4]);
414 columns_m.addColumnValue("S36", beam->getSigmaMatrix()[2][5]);
415 columns_m.addColumnValue("S44", beam->getSigmaMatrix()[3][3]);
416 columns_m.addColumnValue("S45", beam->getSigmaMatrix()[3][4]);
417 columns_m.addColumnValue("S46", beam->getSigmaMatrix()[3][5]);
418 columns_m.addColumnValue("S55", beam->getSigmaMatrix()[4][4]);
419 columns_m.addColumnValue("S56", beam->getSigmaMatrix()[4][5]);
420 columns_m.addColumnValue("S66", beam->getSigmaMatrix()[5][5]);
421 }
422 if (OpalData::getInstance()->isInOPALCyclMode()) {
423 if (Ippl::getNodes() == 1) {
424 if (beam->getLocalNum() > 0) {
425 columns_m.addColumnValue("R0_x", beam->R[0](0));
426 columns_m.addColumnValue("R0_y", beam->R[0](1));
427 columns_m.addColumnValue("R0_s", beam->R[0](2));
428 columns_m.addColumnValue("P0_x", beam->P[0](0));
429 columns_m.addColumnValue("P0_y", beam->P[0](1));
430 columns_m.addColumnValue("P0_s", beam->P[0](2));
431 } else {
432 columns_m.addColumnValue("R0_x", 0.0);
433 columns_m.addColumnValue("R0_y", 0.0);
434 columns_m.addColumnValue("R0_s", 0.0);
435 columns_m.addColumnValue("P0_x", 0.0);
436 columns_m.addColumnValue("P0_y", 0.0);
437 columns_m.addColumnValue("P0_s", 0.0);
438 }
439 }
440 Vector_t halo = beam->get_halo();
441 columns_m.addColumnValue("halo_x", halo(0));
442 columns_m.addColumnValue("halo_y", halo(1));
443 columns_m.addColumnValue("halo_z", halo(2));
444
445 columns_m.addColumnValue("azimuth", azimuth);
446 }
447
449 // zero before the first solve of a TRACK/RUN and with MESHFIT=ALL (in a later one),
450 // those of the core also without a core particle
451 const CoreFitSC::CoreSelection& core = beam->getMeshFitCore();
453 beam->getMeshFitStatistics();
454 const bool coreMode = (beam->getMeshFitMode().mode == CoreFitSC::Mode::CORE &&
456 Vector_t box(0.0);
457 if (core.numCore > 0) {
458 box = core.boundsMax - core.boundsMin;
459 }
460 columns_m.addColumnValue("scMode", static_cast<long unsigned int>(coreMode));
461 columns_m.addColumnValue("scNumFar", core.numFar);
462 columns_m.addColumnValue("scNumHalo", core.numHalo);
463 columns_m.addColumnValue("scFarCharge", core.getFarChargeFraction());
464 columns_m.addColumnValue("scClipPasses", static_cast<long unsigned int>(core.passes));
465 columns_m.addColumnValue("scNumFlagged", statistics.numFlagged);
466 columns_m.addColumnValue("scNumOutside", statistics.numOutside);
467
468 columns_m.addColumnValue("scBox_x", box(0));
469 columns_m.addColumnValue("scBox_y", box(1));
470 columns_m.addColumnValue("scBox_s", box(2));
471
472 columns_m.addColumnValue("scHr_x", statistics.meshSpacing(0));
473 columns_m.addColumnValue("scHr_y", statistics.meshSpacing(1));
474 columns_m.addColumnValue("scHr_s", statistics.meshSpacing(2));
475
476 columns_m.addColumnValue("scCoreRms_x", core.sigma(0));
477 columns_m.addColumnValue("scCoreRms_y", core.sigma(1));
478 columns_m.addColumnValue("scCoreRms_s", core.sigma(2));
479
480 columns_m.addColumnValue("scFarMaxDist", core.farMaxDistance);
481
482 columns_m.addColumnValue("scFullSteps", statistics.fullSolves);
483 columns_m.addColumnValue("scModeSwitches", statistics.modeSwitches);
484 columns_m.addColumnValue("scFarFarSampled", statistics.farFarSampled);
485 columns_m.addColumnValue("scNearSampled", statistics.nearSampled);
486 } else if (beam->getMeshFit().type == MeshFitType::CORE && !warnedMeshFitColumns_m) {
487 WARNMSG("The stat file has no columns for FIELDSOLVER, MESHFIT=\"CORE\": its columns "
488 "are those of the first TRACK/RUN, which had MESHFIT=\"ALL\"." << endl);
490 }
491
492 for(size_t i = 0; i < losses.size(); ++ i) {
493 long unsigned int loss = losses[i].second;
494 columns_m.addColumnValue(losses[i].first, loss);
495 }
496
497 this->writeRow();
498
499 this->close();
500}
#define WARNMSG(msg)
Definition IpplInfo.h:349
Inform & endl(Inform &inf)
Definition Inform.cpp:42
constexpr double s2ns
Definition Units.h:44
bool computePercentiles
Definition Options.cpp:109
bool dumpBeamMatrix
Definition Options.cpp:111
bool amr
Enable AMR if true.
Definition Options.cpp:97
double get_Dx() const
double get_meanKineticEnergy() const
ParticlePos_t & R
Vector_t RefPartP_m
Vector_t get_99Percentile() const
const MeshFitParameters & getMeshFit() const
Vector_t get_normalizedEps_99Percentile() const
size_t getLocalNum() const
FMatrix< double, 2 *Dim, 2 *Dim > getSigmaMatrix() const
double get_debyeLength() const
double get_plasmaParameter() const
size_t getTotalNum() const
double get_DDy() const
Vector_t get_95Percentile() const
Vector_t get_normalizedEps_68Percentile() const
ParticleAttrib< Vector_t > P
Vector_t get_rrms() const
Vector_t RefPartR_m
double get_rmsDensity() const
Vector_t get_prms() const
double getdE() const
const CoreFitSC::CoreSelection & getMeshFitCore() const
double getCharge() const
get the total charge per simulation particle
double get_temperature() const
Vector_t get_68Percentile() const
double get_DDx() const
Vector_t get_norm_emit() const
double get_Dy() const
Vector_t get_rprms() const
Vector_t get_maxExtent() const
Vector_t get_normalizedEps_95Percentile() const
Vector_t get_halo() const
Vector_t get_99_99Percentile() const
Vector_t get_normalizedEps_99_99Percentile() const
const CoreFitSC::ModeState & getMeshFitMode() const
double get_sPos() const
double getT() const
const MeshFitStatistics & getMeshFitStatistics() const
Vector_t get_rmean() const
std::string getInputFn()
get opals input filename
Definition OpalData.cpp:670
static OpalData * getInstance()
Definition OpalData.cpp:196
Result of selectCore(), the same on every rank.
Definition CoreFitSC.h:117
unsigned int passes
clipped passes done, 0 to maxClipPasses
Definition CoreFitSC.h:131
double getFarChargeFraction() const
Far charge over live charge, 0 without live charge.
Definition CoreFitSC.cpp:84
Vector_t boundsMin
minimum over the core particles [m]
Definition CoreFitSC.h:120
std::size_t numFar
the other live particles
Definition CoreFitSC.h:125
Vector_t sigma
clipped rms [m]
Definition CoreFitSC.h:119
std::size_t numHalo
live particles beyond haloSigma * sigma in any axis
Definition CoreFitSC.h:126
std::size_t numCore
live particles within nSigma * sigma in every axis
Definition CoreFitSC.h:124
MESHFIT=CORE: statistics of the solves of this TRACK/RUN, for the stat file and the log.
size_t numOutside
particles outside the mesh domain at the last update()
size_t fullSolves
solves in FULL mode
size_t modeSwitches
switches between CORE and FULL
MeshFitType type
Definition FieldSolver.h:67
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)
SDDSColumnSet columns_m
Definition SDDSWriter.h:122
bool hasColumns() const
Definition SDDSWriter.h:200
void addDefaultParameters()
void addDescription(const std::string &text, const std::string &content)
Definition SDDSWriter.h:159
void writeHeader()
Write SDDS header.
std::ios_base::openmode mode_m
First write to the statistics output file.
Definition SDDSWriter.h:120
void writeRow()
Definition SDDSWriter.h:185
void addInfo(const std::string &mode, const size_t &no_row_counts)
Definition SDDSWriter.h:178
bool warnedMeshFitColumns_m
The warning that the core selection is not written has been given.
Definition StatWriter.h:63
void fillHeader(const PartBunchBase< double, 3 > *beam, const losses_t &losses=losses_t())
bool hasMeshFitColumns_m
Definition StatWriter.h:61
std::vector< std::pair< std::string, unsigned int > > losses_t
Definition StatWriter.h:27
void write(const PartBunchBase< double, 3 > *beam, Vector_t FDext[], const double &timeStep, const losses_t &losses=losses_t(), const double &azimuth=-1, const size_t npOutside=0)
Write statistical data.
StatWriter(const std::string &fname, bool restart)
std::string date() const
Return date.
Definition Timer.cpp:35
std::string time() const
Return time.
Definition Timer.cpp:42
static int getNodes()
Definition IpplInfo.cpp:689
static int myNode()
Definition IpplInfo.cpp:710