OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
H5PartWrapperForPC.cpp
Go to the documentation of this file.
1 //
2 // Copyright & License: See Copyright.readme in src directory
3 //
4 
6 
7 #include "OPALconfig.h"
10 #include "Utilities/Options.h"
11 #include "Utilities/Util.h"
12 #include "Physics/Physics.h"
13 
14 #include <sstream>
15 #include <set>
16 
17 H5PartWrapperForPC::H5PartWrapperForPC(const std::string &fileName, h5_int32_t flags):
18  H5PartWrapper(fileName, flags),
19  previousH5Local_m(false),
20  referenceMomentum_m(0.0),
21  referenceLocation_m(0.0),
22  meanE_m(0.0),
23  meanMomentum_m(0.0),
24  azimuth_m(0.0),
25  elevation_m(0.0)
26 { }
27 
28 H5PartWrapperForPC::H5PartWrapperForPC(const std::string &fileName,
29  int restartStep,
30  std::string sourceFile,
31  h5_int32_t flags):
32  H5PartWrapper(fileName, restartStep, sourceFile, flags),
33  previousH5Local_m(false),
34  referenceMomentum_m(0.0),
35  referenceLocation_m(0.0),
36  meanE_m(0.0),
37  meanMomentum_m(0.0),
38  azimuth_m(0.0),
39  elevation_m(0.0)
40 { }
41 
43 { }
44 
46  h5_int64_t numFileAttributes = H5GetNumFileAttribs(file_m);
47 
48  const h5_size_t lengthAttributeName = 256;
49  char attributeName[lengthAttributeName];
50  h5_int64_t attributeType;
51  h5_size_t numAttributeElements;
52  std::set<std::string> attributeNames;
53 
54  for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
55  REPORTONERROR(H5GetFileAttribInfo(file_m,
56  i,
57  attributeName,
58  lengthAttributeName,
59  &attributeType,
60  &numAttributeElements));
61 
62  attributeNames.insert(attributeName);
63  }
64 
65  if (attributeNames.find("dump frequency") != attributeNames.end()) {
66  h5_int64_t dumpfreq;
67  READFILEATTRIB(Int64, file_m, "dump frequency", &dumpfreq);
69  }
70 }
71 
73  h5_ssize_t firstParticle,
74  h5_ssize_t lastParticle)
75 {
76  h5_ssize_t numStepsInSource = H5GetNumSteps(file_m);
77  h5_ssize_t readStep = numStepsInSource - 1;
78  REPORTONERROR(H5SetStep(file_m, readStep));
79 
80  readStepHeader(bunch);
81  readStepData(bunch, firstParticle, lastParticle);
82 }
83 
85  h5_float64_t pathLength;
86  READSTEPATTRIB(Float64, file_m, "SPOS", &pathLength);
87  bunch->set_sPos(pathLength);
88 
89  h5_int64_t ltstep;
90  READSTEPATTRIB(Int64, file_m, "LocalTrackStep", &ltstep);
91  bunch->setLocalTrackStep((long long)ltstep);
92 
93  h5_int64_t gtstep;
94  READSTEPATTRIB(Int64, file_m, "GlobalTrackStep", &gtstep);
95  bunch->setGlobalTrackStep((long long)gtstep);
96 
97  READSTEPATTRIB(Float64, file_m, "ENERGY", &meanE_m);
98 
99  double actualT;
100  READSTEPATTRIB(Float64, file_m, "TIME", &actualT);
101  bunch->setT(actualT);
102 
103  h5_int64_t SteptoLastInj;
104  READSTEPATTRIB(Int64, file_m, "SteptoLastInj", &SteptoLastInj);
105  bunch->setSteptoLastInj((int)SteptoLastInj);
106 
107  h5_int64_t numBunch;
108  READSTEPATTRIB(Int64, file_m, "NumBunch", &numBunch);
109  bunch->setNumBunch((short)numBunch);
110 
111  if (predecessorOPALFlavour_m == "opal-cycl") {
112  READSTEPATTRIB(Float64, file_m, "REFPR", (h5_float64_t*) &referenceMomentum_m[0]);
113  READSTEPATTRIB(Float64, file_m, "REFPT", (h5_float64_t*) &referenceMomentum_m[1]);
114  READSTEPATTRIB(Float64, file_m, "REFPZ", (h5_float64_t*) &referenceMomentum_m[2]);
115 
116  READSTEPATTRIB(Float64, file_m, "REFR", (h5_float64_t*) &referenceLocation_m[0]);
117  READSTEPATTRIB(Float64, file_m, "REFTHETA", (h5_float64_t*) &referenceLocation_m[1]);
118  READSTEPATTRIB(Float64, file_m, "REFZ", (h5_float64_t*) &referenceLocation_m[2]);
119 
120  READSTEPATTRIB(Float64, file_m, "AZIMUTH", &azimuth_m);
121  READSTEPATTRIB(Float64, file_m, "ELEVATION", &elevation_m);
122 
123  h5_int64_t localDump = 0;
124  h5_int64_t rc = H5ReadStepAttribInt64(file_m, "LOCAL", &localDump);
125  if(rc != H5_SUCCESS) {
126 
127  ERRORMSG("H5 rc= " << rc << " in " << __FILE__ << " @ line " << __LINE__ << endl);
128 
129  std::string errormsg =
130  "You are trying to restart from a legacy file that doesn't contain"
131  "information on local/global frame. We are working on legacy support,"
132  "but for now you have to use OPAL 1.3.0!";
133 
134  throw OpalException("H5PartWrapperForPC::readStepHeader", errormsg);
135  } else {
136  if (localDump == 1) previousH5Local_m = true;
137  }
138  } else {
139  bunch->setT(0.0);
140  bunch->setLocalTrackStep((long long) 0 );
141  }
142 
143  double mass = bunch->getM() * 1e-6;
144  meanMomentum_m = sqrt(std::pow(meanE_m,2.0) + 2 * meanE_m * mass) / mass;
145 }
146 
148  h5_ssize_t firstParticle,
149  h5_ssize_t lastParticle)
150 {
151  h5_ssize_t numParticles = getNumParticles();
152  if (lastParticle >= numParticles || firstParticle > lastParticle) {
153  throw OpalException("H5PartWrapperForPC::readStepData",
154  "the provided particle numbers don't match the number of particles in the file");
155  }
156  const unsigned int yIndex = (predecessorOPALFlavour_m == "opal-t"? 2: 1);
157  const unsigned int zIndex = (predecessorOPALFlavour_m == "opal-t"? 1: 2);
158 
159  REPORTONERROR(H5PartSetView(file_m, firstParticle, lastParticle));
160 
161  numParticles = lastParticle - firstParticle + 1;
162 
163  std::vector<char> buffer(numParticles * sizeof(h5_float64_t));
164  char* buffer_ptr = Util::c_data(buffer);
165  h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr);
166  h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*>(buffer_ptr);
167 
168  READDATA(Float64, file_m, "x", f64buffer);
169  for(long int n = 0; n < numParticles; ++ n) {
170  bunch->R[n](0) = f64buffer[n];
171  bunch->Bin[n] = 0;
172  }
173 
174  READDATA(Float64, file_m, "y", f64buffer);
175  for(long int n = 0; n < numParticles; ++ n) {
176  bunch->R[n](yIndex) = f64buffer[n];
177  }
178 
179  READDATA(Float64, file_m, "z", f64buffer);
180  for(long int n = 0; n < numParticles; ++ n) {
181  bunch->R[n](zIndex) = f64buffer[n];
182  }
183 
184  READDATA(Float64, file_m, "px", f64buffer);
185  for(long int n = 0; n < numParticles; ++ n) {
186  bunch->P[n](0) = f64buffer[n];
187  }
188 
189  READDATA(Float64, file_m, "py", f64buffer);
190  for(long int n = 0; n < numParticles; ++ n) {
191  bunch->P[n](yIndex) = f64buffer[n];
192  }
193 
194  READDATA(Float64, file_m, "pz", f64buffer);
195  for(long int n = 0; n < numParticles; ++ n) {
196  bunch->P[n](zIndex) = f64buffer[n];
197  }
198 
199  READDATA(Float64, file_m, "q", f64buffer);
200  for(long int n = 0; n < numParticles; ++ n) {
201  bunch->Q[n] = f64buffer[n];
202  }
203 
204  READDATA(Float64, file_m, "mass", f64buffer);
205  for(long int n = 0; n < numParticles; ++ n) {
206  bunch->M[n] = f64buffer[n];
207  }
208 
209  if ( bunch->getNumBunch() > 1 ) {
210  READDATA(Int64, file_m, "bin", i64buffer);
211  for(long int n = 0; n < numParticles; ++ n) {
212  bunch->Bin[n] = i64buffer[n];
213  }
214  }
215 
216  READDATA(Int64, file_m, "bunchNumber", i64buffer);
217  for(long int n = 0; n < numParticles; ++ n) {
218  bunch->bunchNum[n] = i64buffer[n];
219  }
220 
221  REPORTONERROR(H5PartSetView(file_m, -1, -1));
222 }
223 
225  std::stringstream OPAL_version;
226  OPAL_version << OPAL_PROJECT_NAME << " " << OPAL_PROJECT_VERSION << " # git rev. " << Util::getGitRevision();
227  WRITESTRINGFILEATTRIB(file_m, "OPAL_version", OPAL_version.str().c_str());
228 
229  // Units for the step data
230  WRITESTRINGFILEATTRIB(file_m, "xUnit", "m");
231  WRITESTRINGFILEATTRIB(file_m, "yUnit", "m");
232  WRITESTRINGFILEATTRIB(file_m, "zUnit", "m");
233  WRITESTRINGFILEATTRIB(file_m, "pxUnit", "#beta#gamma");
234  WRITESTRINGFILEATTRIB(file_m, "pyUnit", "#beta#gamma");
235  WRITESTRINGFILEATTRIB(file_m, "pzUnit", "#beta#gamma");
236  WRITESTRINGFILEATTRIB(file_m, "qUnit", "C");
237  WRITESTRINGFILEATTRIB(file_m, "massUnit", "GeV");
238  WRITESTRINGFILEATTRIB(file_m, "idUnit", "1");
239  WRITESTRINGFILEATTRIB(file_m, "binUnit", "1");
240  WRITESTRINGFILEATTRIB(file_m, "bunchNumberUnit", "1");
241  if (Options::ebDump) {
242  WRITESTRINGFILEATTRIB(file_m, "Ex", "MV/m");
243  WRITESTRINGFILEATTRIB(file_m, "Ey", "MV/m");
244  WRITESTRINGFILEATTRIB(file_m, "Ez", "MV/m");
245  WRITESTRINGFILEATTRIB(file_m, "Bx", "T");
246  WRITESTRINGFILEATTRIB(file_m, "By", "T");
247  WRITESTRINGFILEATTRIB(file_m, "Bz", "T");
248  }
249 
250  // Units for the step attributes
251  WRITESTRINGFILEATTRIB(file_m, "TIMEUnit", "s");
252  WRITESTRINGFILEATTRIB(file_m, "SPOSUnit", "m");
253 
254  WRITESTRINGFILEATTRIB(file_m, "RefPartRUnit", "m");
255  WRITESTRINGFILEATTRIB(file_m, "centroidUnit", "m");
256  WRITESTRINGFILEATTRIB(file_m, "RMSXUnit", "m");
257  WRITESTRINGFILEATTRIB(file_m, "minXUnit", "m");
258  WRITESTRINGFILEATTRIB(file_m, "maxXUnit", "m");
259 
260  WRITESTRINGFILEATTRIB(file_m, "RefPartPUnit", "#beta#gamma");
261  WRITESTRINGFILEATTRIB(file_m, "RMSPUnit", "#beta#gamma");
262  WRITESTRINGFILEATTRIB(file_m, "minPUnit", "#beta#gamma");
263  WRITESTRINGFILEATTRIB(file_m, "maxPUnit", "#beta#gamma");
264 
265  WRITESTRINGFILEATTRIB(file_m, "#varepsilonUnit", "m rad");
266  WRITESTRINGFILEATTRIB(file_m, "#varepsilon-geomUnit", "m rad");
267 
268  WRITESTRINGFILEATTRIB(file_m, "StepUnit", "1");
269  WRITESTRINGFILEATTRIB(file_m, "LocalTrackStepUnit", "1");
270  WRITESTRINGFILEATTRIB(file_m, "GlobalTrackStepUnit", "1");
271 
272  WRITESTRINGFILEATTRIB(file_m, "#sigmaUnit", "1");
273 
274  WRITESTRINGFILEATTRIB(file_m, "ENERGYUnit", "MeV");
275  WRITESTRINGFILEATTRIB(file_m, "dEUnit", "MeV");
276 
277  WRITESTRINGFILEATTRIB(file_m, "MASSUnit", "GeV");
278  WRITESTRINGFILEATTRIB(file_m, "CHARGEUnit", "C");
279 
280  WRITESTRINGFILEATTRIB(file_m, "NumBunchUnit", "1");
281  WRITESTRINGFILEATTRIB(file_m, "SteptoLastInjUnit", "1");
282  WRITESTRINGFILEATTRIB(file_m, "LOCALUnit", "1");
283 
284  // additional step attributes
285  WRITESTRINGFILEATTRIB(file_m, "REFPRUnit", "#beta#gamma");
286  WRITESTRINGFILEATTRIB(file_m, "REFPTUnit", "#beta#gamma");
287  WRITESTRINGFILEATTRIB(file_m, "REFPZUnit", "#beta#gamma");
288  WRITESTRINGFILEATTRIB(file_m, "REFRUnit", "mm");
289  WRITESTRINGFILEATTRIB(file_m, "REFTHETAUnit", "deg");
290  WRITESTRINGFILEATTRIB(file_m, "REFZUnit", "mm");
291  WRITESTRINGFILEATTRIB(file_m, "REFAZIMUTHUnit", "deg");
292  WRITESTRINGFILEATTRIB(file_m, "REFELEVATIONUnit", "deg");
293 
294  WRITESTRINGFILEATTRIB(file_m, "spos-headUnit", "m");
295  WRITESTRINGFILEATTRIB(file_m, "spos-refUnit", "m");
296  WRITESTRINGFILEATTRIB(file_m, "spos-tailUnit", "m");
297 
298  WRITESTRINGFILEATTRIB(file_m, "B-refUnit", "T");
299  WRITESTRINGFILEATTRIB(file_m, "E-refUnit", "MV/m");
300  WRITESTRINGFILEATTRIB(file_m, "B-headUnit", "T");
301  WRITESTRINGFILEATTRIB(file_m, "E-headUnit", "MV/m");
302  WRITESTRINGFILEATTRIB(file_m, "B-tailUnit", "T");
303  WRITESTRINGFILEATTRIB(file_m, "E-tailUnit", "MV/m");
304 
306  h5_int64_t dumpfreq = Options::psDumpFreq;
307  WRITEFILEATTRIB(Int64, file_m, "dump frequency", &dumpfreq, 1);
308 }
309 
311  const std::map<std::string, double> &additionalStepAttributes)
312 {
313  if (bunch->getTotalNum() == 0) return;
314 
315  open(H5_O_APPENDONLY);
316  writeStepHeader(bunch, additionalStepAttributes);
317  writeStepData(bunch);
318  close();
319 
320  ++ numSteps_m;
321 }
322 
324  const std::map<std::string, double> &additionalStepAttributes)
325 {
326  bunch->calcBeamParameters();
327 
328  double t = bunch->getT();
329  double pathLength = bunch->get_sPos();
330  Vector_t rmin = bunch->get_origin();
331  Vector_t rmax = bunch->get_maxExtent();
332  Vector_t centroid = bunch->get_centroid();
333 
334  Vector_t meanR = bunch->get_rmean();
335  Vector_t meanP = bunch->get_pmean();
336  Vector_t xsigma = bunch->get_rrms();
337  Vector_t psigma = bunch->get_prms();
338  Vector_t vareps = bunch->get_norm_emit();
339  Vector_t geomvareps = bunch->get_emit();
340 
341  Vector_t RefPartR = bunch->RefPartR_m;
342  Vector_t RefPartP = bunch->RefPartP_m;
343 
344  double meanEnergy = bunch->get_meanKineticEnergy();
345  double energySpread = bunch->getdE();
346  double I_0 = 4.0 * Physics::pi * Physics::epsilon_0 * Physics::c * bunch->getM() / bunch->getQ();
347  double sigma = ((xsigma[0] * xsigma[0]) + (xsigma[1] * xsigma[1])) /
348  (2.0 * bunch->get_gamma() * I_0 * (geomvareps[0] * geomvareps[0] + geomvareps[1] * geomvareps[1]));
349 
350  h5_int64_t localTrackStep = (h5_int64_t)bunch->getLocalTrackStep();
351  h5_int64_t globalTrackStep = (h5_int64_t)bunch->getGlobalTrackStep();
352 
353  h5_int64_t numBunch = (h5_int64_t)bunch->getNumBunch();
354  h5_int64_t SteptoLastInj = (h5_int64_t)bunch->getSteptoLastInj();
355 
356  double mass = 1.0e-9 * bunch->getM();
357  double charge = bunch->getCharge();
358 
359  h5_int64_t localFrame = ( Options::psDumpFrame != Options::GLOBAL );
360 
361  double sposHead = 0.0;
362  double sposRef = 0.0;
363  double sposTail = 0.0;
364 
365  Vector_t maxP(0.0);
366  Vector_t minP(0.0);
367  bunch->get_PBounds(minP, maxP);
368 
369  REPORTONERROR(H5SetStep(file_m, numSteps_m));
370 
371  char const *OPALFlavour = "opal-cycl";
372  WRITESTRINGSTEPATTRIB(file_m, "OPAL_flavour", OPALFlavour);
373  WRITESTEPATTRIB(Float64, file_m, "TIME", &t, 1);
374  WRITESTEPATTRIB(Float64, file_m, "SPOS", &pathLength, 1);
375 
376  WRITESTEPATTRIB(Float64, file_m, "RefPartR", (h5_float64_t *)&RefPartR, 3);
377  WRITESTEPATTRIB(Float64, file_m, "centroid", (h5_float64_t *)&centroid, 3);
378  WRITESTEPATTRIB(Float64, file_m, "RMSX", (h5_float64_t *)&xsigma, 3);
379  WRITESTEPATTRIB(Float64, file_m, "minX", (h5_float64_t *)&rmin, 3);
380  WRITESTEPATTRIB(Float64, file_m, "maxX", (h5_float64_t *)&rmax, 3);
381 
382  WRITESTEPATTRIB(Float64, file_m, "RefPartP", (h5_float64_t *)&RefPartP, 3);
383  WRITESTEPATTRIB(Float64, file_m, "RMSP", (h5_float64_t *)&psigma, 3);
384  WRITESTEPATTRIB(Float64, file_m, "minP", (h5_float64_t *)&minP, 3);
385  WRITESTEPATTRIB(Float64, file_m, "maxP", (h5_float64_t *)&maxP, 3);
386 
387  WRITESTEPATTRIB(Float64, file_m, "#varepsilon", (h5_float64_t *)&vareps, 3);
388  WRITESTEPATTRIB(Float64, file_m, "#varepsilon-geom", (h5_float64_t *)&geomvareps, 3);
389 
390  WRITESTEPATTRIB(Int64, file_m, "Step", &numSteps_m, 1);
391  WRITESTEPATTRIB(Int64, file_m, "LocalTrackStep", &localTrackStep, 1);
392  WRITESTEPATTRIB(Int64, file_m, "GlobalTrackStep", &globalTrackStep, 1);
393 
394  WRITESTEPATTRIB(Float64, file_m, "#sigma", &sigma, 1);
395 
396  WRITESTEPATTRIB(Float64, file_m, "ENERGY", &meanEnergy, 1);
397  WRITESTEPATTRIB(Float64, file_m, "dE", &energySpread, 1);
398 
400  WRITESTEPATTRIB(Float64, file_m, "MASS", &mass, 1);
401  WRITESTEPATTRIB(Float64, file_m, "CHARGE", &charge, 1);
402 
403  WRITESTEPATTRIB(Int64, file_m, "NumBunch", &numBunch, 1);
404  WRITESTEPATTRIB(Int64, file_m, "SteptoLastInj", &SteptoLastInj, 1);
405  WRITESTEPATTRIB(Int64, file_m, "LOCAL", &localFrame, 1);
406 
407  try {
408  h5_float64_t refpr = additionalStepAttributes.at("REFPR");
409  h5_float64_t refpt = additionalStepAttributes.at("REFPT");
410  h5_float64_t refpz = additionalStepAttributes.at("REFPZ");
411  h5_float64_t refr = additionalStepAttributes.at("REFR");
412  h5_float64_t reft = additionalStepAttributes.at("REFTHETA");
413  h5_float64_t refz = additionalStepAttributes.at("REFZ");
414  h5_float64_t azimuth = additionalStepAttributes.at("AZIMUTH");
415  h5_float64_t elevation = additionalStepAttributes.at("ELEVATION");
416 
417  Vector_t referenceB(additionalStepAttributes.at("B-ref_x"),
418  additionalStepAttributes.at("B-ref_z"),
419  additionalStepAttributes.at("B-ref_y"));
420  Vector_t referenceE(additionalStepAttributes.at("E-ref_x"),
421  additionalStepAttributes.at("E-ref_z"),
422  additionalStepAttributes.at("E-ref_y"));
423  Vector_t headB(additionalStepAttributes.at("B-head_x"),
424  additionalStepAttributes.at("B-head_z"),
425  additionalStepAttributes.at("B-head_y"));
426  Vector_t headE(additionalStepAttributes.at("E-head_x"),
427  additionalStepAttributes.at("E-head_z"),
428  additionalStepAttributes.at("E-head_y"));
429  Vector_t tailB(additionalStepAttributes.at("B-tail_x"),
430  additionalStepAttributes.at("B-tail_z"),
431  additionalStepAttributes.at("B-tail_y"));
432  Vector_t tailE(additionalStepAttributes.at("E-tail_x"),
433  additionalStepAttributes.at("E-tail_z"),
434  additionalStepAttributes.at("E-tail_y"));
435 
436  WRITESTEPATTRIB(Float64, file_m, "REFPR", &refpr, 1);
437  WRITESTEPATTRIB(Float64, file_m, "REFPT", &refpt, 1);
438  WRITESTEPATTRIB(Float64, file_m, "REFPZ", &refpz, 1);
439  WRITESTEPATTRIB(Float64, file_m, "REFR", &refr, 1);
440  WRITESTEPATTRIB(Float64, file_m, "REFTHETA", &reft, 1);
441  WRITESTEPATTRIB(Float64, file_m, "REFZ", &refz, 1);
442  WRITESTEPATTRIB(Float64, file_m, "AZIMUTH", &azimuth, 1);
443  WRITESTEPATTRIB(Float64, file_m, "ELEVATION", &elevation, 1);
444 
445  WRITESTEPATTRIB(Float64, file_m, "spos-head", &sposHead, 1);
446  WRITESTEPATTRIB(Float64, file_m, "spos-ref", &sposRef, 1);
447  WRITESTEPATTRIB(Float64, file_m, "spos-tail", &sposTail, 1);
448 
449  WRITESTEPATTRIB(Float64, file_m, "B-ref", (h5_float64_t *)&referenceB, 3);
450  WRITESTEPATTRIB(Float64, file_m, "E-ref", (h5_float64_t *)&referenceE, 3);
451  WRITESTEPATTRIB(Float64, file_m, "B-head", (h5_float64_t *)&headB, 3);
452  WRITESTEPATTRIB(Float64, file_m, "E-head", (h5_float64_t *)&headE, 3);
453  WRITESTEPATTRIB(Float64, file_m, "B-tail", (h5_float64_t *)&tailB, 3);
454  WRITESTEPATTRIB(Float64, file_m, "E-tail", (h5_float64_t *)&tailE, 3);
455  } catch (std::out_of_range & m) {
456  ERRORMSG(m.what() << endl);
457 
458  throw OpalException("H5PartWrapperForPC::writeStepHeader",
459  "some additional step attribute not found");
460  }
461 }
462 
464  /*
465  find particle with ID==0
466  and save index in zID
467 
468  FIXME After issue 287 is resolved this shouldn't be
469  necessary anymore!
470  */
471 
472  size_t IDZero = bunch->getLocalNum();
473  bool found = false;
474 #ifndef ENABLE_AMR
475  for(size_t k = 0; k < IDZero; ++ k) {
476  if (bunch->ID[k] == 0) {
477  found = true;
478  IDZero = k;
479  }
480  }
481 #endif
482 
483  const size_t numLocalParticles = (found? bunch->getLocalNum() - 1: bunch->getLocalNum());
484  const size_t skipID = IDZero;
485 
486  std::vector<char> buffer(numLocalParticles * sizeof(h5_float64_t));
487  char* buffer_ptr = Util::c_data(buffer);
488  h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(buffer_ptr);
489  h5_int64_t *i64buffer = reinterpret_cast<h5_int64_t*> (buffer_ptr);
490 
491 
492  REPORTONERROR(H5PartSetNumParticles(file_m, numLocalParticles));
493 
494  for(size_t i = 0; i < skipID; ++ i)
495  f64buffer[i] = bunch->R[i](0);
496  for (size_t i = skipID; i < numLocalParticles; ++ i)
497  f64buffer[i] = bunch->R[i + 1](0);
498 
499  WRITEDATA(Float64, file_m, "x", f64buffer);
500 
501  for(size_t i = 0; i < skipID; ++ i)
502  f64buffer[i] = bunch->R[i](1);
503  for (size_t i = skipID; i < numLocalParticles; ++ i)
504  f64buffer[i] = bunch->R[i + 1](1);
505 
506  WRITEDATA(Float64, file_m, "y", f64buffer);
507 
508  for(size_t i = 0; i < skipID; ++ i)
509  f64buffer[i] = bunch->R[i](2);
510  for (size_t i = skipID; i < numLocalParticles; ++ i)
511  f64buffer[i] = bunch->R[i + 1](2);
512 
513  WRITEDATA(Float64, file_m, "z", f64buffer);
514 
515  for(size_t i = 0; i < skipID; ++ i)
516  f64buffer[i] = bunch->P[i](0);
517  for (size_t i = skipID; i < numLocalParticles; ++ i)
518  f64buffer[i] = bunch->P[i + 1](0);
519 
520  WRITEDATA(Float64, file_m, "px", f64buffer);
521 
522  for(size_t i = 0; i < skipID; ++ i)
523  f64buffer[i] = bunch->P[i](1);
524  for (size_t i = skipID; i < numLocalParticles; ++ i)
525  f64buffer[i] = bunch->P[i + 1](1);
526 
527  WRITEDATA(Float64, file_m, "py", f64buffer);
528 
529  for(size_t i = 0; i < skipID; ++ i)
530  f64buffer[i] = bunch->P[i](2);
531  for (size_t i = skipID; i < numLocalParticles; ++ i)
532  f64buffer[i] = bunch->P[i + 1](2);
533 
534  WRITEDATA(Float64, file_m, "pz", f64buffer);
535 
536  for(size_t i = 0; i < skipID; ++ i)
537  f64buffer[i] = bunch->Q[i];
538  for (size_t i = skipID; i < numLocalParticles; ++ i)
539  f64buffer[i] = bunch->Q[i + 1];
540 
541  WRITEDATA(Float64, file_m, "q", f64buffer);
542 
543  for(size_t i = 0; i < skipID; ++ i)
544  f64buffer[i] = bunch->M[i];
545  for (size_t i = skipID; i < numLocalParticles; ++ i)
546  f64buffer[i] = bunch->M[i + 1];
547 
548  WRITEDATA(Float64, file_m, "mass", f64buffer);
549 
550  for(size_t i = 0; i < skipID; ++ i)
551  i64buffer[i] = bunch->ID[i];
552  for (size_t i = skipID; i < numLocalParticles; ++ i)
553  i64buffer[i] = bunch->ID[i + 1];
554 
555  WRITEDATA(Int64, file_m, "id", i64buffer);
556 
557  if ( bunch->hasBinning() ) {
558  for(size_t i = 0; i < skipID; ++ i)
559  i64buffer[i] = bunch->Bin[i];
560  for (size_t i = skipID; i < numLocalParticles; ++ i)
561  i64buffer[i] = bunch->Bin[i + 1];
562 
563  WRITEDATA(Int64, file_m, "bin", i64buffer);
564  }
565 
566  for (size_t i = 0; i < skipID; ++ i)
567  i64buffer[i] = bunch->bunchNum[i];
568  for (size_t i = skipID; i < numLocalParticles; ++ i)
569  i64buffer[i] = bunch->bunchNum[i + 1];
570  WRITEDATA(Int64, file_m, "bunchNumber", i64buffer);
571 
572  if (Options::ebDump) {
573  for(size_t i = 0; i < skipID; ++ i)
574  f64buffer[i] = bunch->Ef[i](0);
575  for (size_t i = skipID; i < numLocalParticles; ++ i)
576  f64buffer[i] = bunch->Ef[i + 1](0);
577 
578  WRITEDATA(Float64, file_m, "Ex", f64buffer);
579 
580  for(size_t i = 0; i < skipID; ++ i)
581  f64buffer[i] = bunch->Ef[i](1);
582  for (size_t i = skipID; i < numLocalParticles; ++ i)
583  f64buffer[i] = bunch->Ef[i + 1](1);
584 
585  WRITEDATA(Float64, file_m, "Ey", f64buffer);
586 
587  for(size_t i = 0; i < skipID; ++ i)
588  f64buffer[i] = bunch->Ef[i](2);
589  for (size_t i = skipID; i < numLocalParticles; ++ i)
590  f64buffer[i] = bunch->Ef[i + 1](2);
591 
592  WRITEDATA(Float64, file_m, "Ez", f64buffer);
593 
594  for(size_t i = 0; i < skipID; ++ i)
595  f64buffer[i] = bunch->Bf[i](0);
596  for (size_t i = skipID; i < numLocalParticles; ++ i)
597  f64buffer[i] = bunch->Bf[i + 1](0);
598 
599  WRITEDATA(Float64, file_m, "Bx", f64buffer);
600 
601  for(size_t i = 0; i < skipID; ++ i)
602  f64buffer[i] = bunch->Bf[i](1);
603  for (size_t i = skipID; i < numLocalParticles; ++ i)
604  f64buffer[i] = bunch->Bf[i + 1](1);
605 
606  WRITEDATA(Float64, file_m, "By", f64buffer);
607 
608  for(size_t i = 0; i < skipID; ++ i)
609  f64buffer[i] = bunch->Bf[i](2);
610  for (size_t i = skipID; i < numLocalParticles; ++ i)
611  f64buffer[i] = bunch->Bf[i + 1](2);
612 
613  WRITEDATA(Float64, file_m, "Bz", f64buffer);
614 
615  }
616 
618  if(Options::rhoDump) {
619  NDIndex<3> idx = bunch->getFieldLayout().getLocalNDIndex();
620  NDIndex<3> elem;
621  REPORTONERROR(H5Block3dSetView(file_m,
622  idx[0].min(), idx[0].max(),
623  idx[1].min(), idx[1].max(),
624  idx[2].min(), idx[2].max()));
625 
626  std::unique_ptr<h5_float64_t[]> data(new h5_float64_t[(idx[0].max() + 1) * (idx[1].max() + 1) * (idx[2].max() + 1)]);
627 
628  int ii = 0;
629  // h5block uses the fortran convention of storing data:
630  // INTEGER, DIMENSION(2,3) :: a
631  // => {a(1,1), a(2,1), a(1,2), a(2,2), a(1,3), a(2,3)}
632  for(int i = idx[2].min(); i <= idx[2].max(); ++ i) {
633  for(int j = idx[1].min(); j <= idx[1].max(); ++ j) {
634  for(int k = idx[0].min(); k <= idx[0].max(); ++ k) {
635  data[ii] = bunch->getRho(k, j, i);
636  ++ ii;
637  }
638  }
639  }
640  REPORTONERROR(H5Block3dWriteScalarFieldFloat64(file_m, "rho", data.get()));
641 
643  REPORTONERROR(H5Block3dSetFieldOrigin(file_m, "rho",
644  (h5_float64_t)bunch->get_origin()(0),
645  (h5_float64_t)bunch->get_origin()(1),
646  (h5_float64_t)bunch->get_origin()(2)));
647 
648  REPORTONERROR(H5Block3dSetFieldSpacing(file_m, "rho",
649  (h5_float64_t)bunch->get_hr()(0),
650  (h5_float64_t)bunch->get_hr()(1),
651  (h5_float64_t)bunch->get_hr()(2)));
652  }
653 }
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
#define OPAL_PROJECT_VERSION
Definition: OPALconfig.h:5
#define OPAL_PROJECT_NAME
Definition: OPALconfig.h:2
#define WRITESTRINGFILEATTRIB(file, name, value)
Definition: H5PartWrapper.h:24
#define WRITESTEPATTRIB(type, file, name, value, length)
Definition: H5PartWrapper.h:29
#define REPORTONERROR(rc)
Definition: H5PartWrapper.h:22
#define READSTEPATTRIB(type, file, name, value)
Definition: H5PartWrapper.h:27
#define WRITEDATA(type, file, name, value)
Definition: H5PartWrapper.h:32
#define WRITEFILEATTRIB(type, file, name, value, length)
Definition: H5PartWrapper.h:25
#define WRITESTRINGSTEPATTRIB(file, name, value)
Definition: H5PartWrapper.h:28
#define READDATA(type, file, name, value)
Definition: H5PartWrapper.h:31
#define READFILEATTRIB(type, file, name, value)
Definition: H5PartWrapper.h:23
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
Definition: Physics.h:57
constexpr double e
The value of.
Definition: Physics.h:39
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
constexpr double pi
The value of.
Definition: Physics.h:30
@ GLOBAL
Definition: OptionTypes.h:6
int psDumpFreq
The frequency to dump the phase space, i.e.dump data when steppsDumpFreq==0.
Definition: Options.cpp:39
bool rhoDump
Definition: Options.cpp:63
bool ebDump
Definition: Options.cpp:65
DumpFrame psDumpFrame
flag to decide in which coordinate frame the phase space will be dumped for OPAL-cycl
Definition: Options.cpp:45
T * c_data(std::vector< T, A > &v)
Definition: Util.h:201
std::string getGitRevision()
Definition: Util.cpp:18
ParticleAttrib< Vector_t > Ef
double get_meanKineticEnergy() const
ParticlePos_t & R
ParticleAttrib< int > Bin
Vector_t RefPartP_m
int getSteptoLastInj() const
void setNumBunch(short n)
double getQ() const
Access to reference data.
size_t getLocalNum() const
void set_sPos(double s)
void setLocalTrackStep(long long n)
step in a TRACK command
ParticleAttrib< double > M
size_t getTotalNum() const
double get_gamma() const
ParticleAttrib< Vector_t > P
Vector_t get_rrms() const
Vector_t RefPartR_m
ParticleAttrib< double > Q
void calcBeamParameters()
void setSteptoLastInj(int n)
virtual double getRho(int x, int y, int z)=0
Vector_t get_origin() const
Vector_t get_prms() const
double getdE() const
virtual FieldLayout_t & getFieldLayout()=0
double getCharge() const
get the total charge per simulation particle
long long getLocalTrackStep() const
short getNumBunch() const
Vector_t get_norm_emit() const
Vector_t get_maxExtent() const
void get_PBounds(Vector_t &min, Vector_t &max) const
void setGlobalTrackStep(long long n)
step in multiple TRACK commands
Vector_t get_centroid() const
ParticleAttrib< short > bunchNum
Vector_t get_pmean() const
bool hasBinning() const
ParticleAttrib< Vector_t > Bf
long long getGlobalTrackStep() const
void setT(double t)
virtual Vector_t get_hr() const
ParticleIndex_t & ID
Vector_t get_emit() const
double get_sPos() const
double getM() const
double getT() const
Vector_t get_rmean() const
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
Definition: OpalData.cpp:340
static OpalData * getInstance()
Definition: OpalData.cpp:195
size_t getNumParticles() const
void open(h5_int32_t flags)
h5_int64_t numSteps_m
Definition: H5PartWrapper.h:76
std::string predecessorOPALFlavour_m
Definition: H5PartWrapper.h:75
h5_file_t file_m
Definition: H5PartWrapper.h:73
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &additionalStepAttributes)
void readStepData(PartBunchBase< double, 3 > *, h5_ssize_t, h5_ssize_t)
h5_float64_t elevation_m
void readStepHeader(PartBunchBase< double, 3 > *)
virtual void writeHeader()
H5PartWrapperForPC(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
void writeStepData(PartBunchBase< double, 3 > *)
h5_float64_t meanMomentum_m
virtual void readHeader()
void writeStepHeader(PartBunchBase< double, 3 > *, const std::map< std::string, double > &)
virtual void readStep(PartBunchBase< double, 3 > *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
NDIndex< Dim > getLocalNDIndex()