OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
H5PartWrapperForPS.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 <boost/filesystem.hpp>
15 
16 #include <sstream>
17 #include <set>
18 
19 H5PartWrapperForPS::H5PartWrapperForPS(const std::string &fileName, h5_int32_t flags):
20  H5PartWrapper(fileName, flags)
21 { }
22 
23 H5PartWrapperForPS::H5PartWrapperForPS(const std::string &fileName, int restartStep, std::string sourceFile, h5_int32_t flags):
24  H5PartWrapper(fileName, restartStep, sourceFile, flags)
25 {
26  if (restartStep == -1) {
27  restartStep = H5GetNumSteps(file_m) - 1 ;
28  OpalData::getInstance()->setRestartStep(restartStep);
29  }
30 }
31 
33 { }
34 
36  h5_int64_t numFileAttributes = H5GetNumFileAttribs(file_m);
37 
38  const h5_size_t lengthAttributeName = 256;
39  char attributeName[lengthAttributeName];
40  h5_int64_t attributeType;
41  h5_size_t numAttributeElements;
42  std::set<std::string> attributeNames;
43 
44  for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
45  REPORTONERROR(H5GetFileAttribInfo(file_m,
46  i,
47  attributeName,
48  lengthAttributeName,
49  &attributeType,
50  &numAttributeElements));
51 
52  attributeNames.insert(attributeName);
53  }
54 
55  if (attributeNames.find("dump frequency") != attributeNames.end()) {
56  h5_int64_t dumpfreq;
57  READFILEATTRIB(Int64, file_m, "dump frequency", &dumpfreq);
59  }
60 
61  if (attributeNames.find("dPhiGlobal") != attributeNames.end()) {
62  h5_float64_t dphi;
63  READFILEATTRIB(Float64, file_m, "dPhiGlobal", &dphi);
65  }
66 
67  if (attributeNames.find("nAutoPhaseCavities") != attributeNames.end()) {
68  auto opal = OpalData::getInstance();
69  h5_float64_t phase;
70  h5_int64_t numAutoPhaseCavities;
71  if (!H5HasFileAttrib(file_m, "nAutoPhaseCavities") ||
72  H5ReadFileAttribInt64(file_m, "nAutoPhaseCavities", &numAutoPhaseCavities) != H5_SUCCESS) {
73  numAutoPhaseCavities = 0;
74  } else {
75  for(long i = 0; i < numAutoPhaseCavities; ++ i) {
76  std::string elementName = "Cav-" + std::to_string(i + 1) + "-name";
77  std::string elementPhase = "Cav-" + std::to_string(i + 1) + "-value";
78 
79  char name[128];
80  READFILEATTRIB(String, file_m, elementName.c_str(), name);
81  READFILEATTRIB(Float64, file_m, elementPhase.c_str(), &phase);
82 
83  opal->setMaxPhase(name, phase);
84  }
85  }
86  }
87 }
88 
89 void H5PartWrapperForPS::readStep(PartBunchBase<double, 3>* bunch, h5_ssize_t firstParticle, h5_ssize_t lastParticle) {
90  h5_ssize_t numStepsInSource = H5GetNumSteps(file_m);
91  h5_ssize_t readStep = numStepsInSource - 1;
92  REPORTONERROR(H5SetStep(file_m, readStep));
93 
94  readStepHeader(bunch);
95  readStepData(bunch, firstParticle, lastParticle);
96 }
97 
99  double actualT;
100  READSTEPATTRIB(Float64, file_m, "TIME", &actualT);
101  bunch->setT(actualT);
102 }
103 
104 void H5PartWrapperForPS::readStepData(PartBunchBase<double, 3>* bunch, h5_ssize_t firstParticle, h5_ssize_t lastParticle) {
105  h5_ssize_t numParticles = getNumParticles();
106  if (lastParticle >= numParticles || firstParticle > lastParticle) {
107  throw OpalException("H5PartWrapperForPS::readStepData",
108  "the provided particle numbers don't match the number of particles in the file");
109  }
110 
111  EnvelopeBunch *ebunch = static_cast<EnvelopeBunch*>(bunch);
112 
113  REPORTONERROR(H5PartSetView(file_m, firstParticle, lastParticle));
114 
115  numParticles = lastParticle - firstParticle + 1;
116 
117  std::vector<char> buffer(numParticles * sizeof(h5_float64_t));
118  h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]);
119 
120  READDATA(Float64, file_m, "x", f64buffer);
121  for(long int n = 0; n < numParticles; ++ n) {
122  ebunch->setX(n, f64buffer[n]);
123  }
124 
125  READDATA(Float64, file_m, "y", f64buffer);
126  for(long int n = 0; n < numParticles; ++ n) {
127  ebunch->setY(n, f64buffer[n]);
128  }
129 
130  READDATA(Float64, file_m, "z", f64buffer);
131  for(long int n = 0; n < numParticles; ++ n) {
132  ebunch->setZ(n, f64buffer[n]);
133  }
134 
135  READDATA(Float64, file_m, "px", f64buffer);
136  for(long int n = 0; n < numParticles; ++ n) {
137  ebunch->setPx(n, f64buffer[n]);
138  }
139 
140  READDATA(Float64, file_m, "py", f64buffer);
141  for(long int n = 0; n < numParticles; ++ n) {
142  ebunch->setPy(n, f64buffer[n]);
143  }
144 
145  READDATA(Float64, file_m, "beta", f64buffer);
146  for(long int n = 0; n < numParticles; ++ n) {
147  ebunch->setBeta(n, f64buffer[n]);
148  }
149 
150  READDATA(Float64, file_m, "X0", f64buffer);
151  for(long int n = 0; n < numParticles; ++ n) {
152  ebunch->setX0(n, f64buffer[n]);
153  }
154 
155  READDATA(Float64, file_m, "Y0", f64buffer);
156  for(long int n = 0; n < numParticles; ++ n) {
157  ebunch->setY0(n, f64buffer[n]);
158  }
159 
160  READDATA(Float64, file_m, "pX0", f64buffer);
161  for(long int n = 0; n < numParticles; ++ n) {
162  ebunch->setPx0(n, f64buffer[n]);
163  }
164 
165  READDATA(Float64, file_m, "pY0", f64buffer);
166  for(long int n = 0; n < numParticles; ++ n) {
167  ebunch->setPy0(n, f64buffer[n]);
168  }
169 
170  REPORTONERROR(H5PartSetView(file_m, -1, -1));
171 }
172 
174  h5_int64_t dumpfreq = Options::psDumpFreq;
175  h5_float64_t dphi = OpalData::getInstance()->getGlobalPhaseShift();
176  std::stringstream OPAL_version;
177 
178  OPAL_version << OPAL_PROJECT_NAME << " " << OPAL_PROJECT_VERSION << " # git rev. " << Util::getGitRevision();
179  WRITESTRINGFILEATTRIB(file_m, "OPAL_version", OPAL_version.str().c_str());
180 
181  WRITESTRINGFILEATTRIB(file_m, "xUnit", "m");
182  WRITESTRINGFILEATTRIB(file_m, "yUnit", "m");
183  WRITESTRINGFILEATTRIB(file_m, "zUnit", "m");
184  WRITESTRINGFILEATTRIB(file_m, "pxUnit", "#beta#gamma");
185  WRITESTRINGFILEATTRIB(file_m, "pyUnit", "#beta#gamma");
186  WRITESTRINGFILEATTRIB(file_m, "pzUnit", "#beta#gamma");
187  WRITESTRINGFILEATTRIB(file_m, "qUnit", "Cb");
188 
189  WRITESTRINGFILEATTRIB(file_m, "idUnit", "1");
190 
191  WRITESTRINGFILEATTRIB(file_m, "SPOSUnit", "m");
192  WRITESTRINGFILEATTRIB(file_m, "TIMEUnit", "s");
193  WRITESTRINGFILEATTRIB(file_m, "ENERGYUnit", "MeV");
194  WRITESTRINGFILEATTRIB(file_m, "#varepsilonUnit", "m rad");
195  WRITESTRINGFILEATTRIB(file_m, "#varepsilon-geomUnit", "m rad");
196 
197  WRITESTRINGFILEATTRIB(file_m, "#sigmaUnit", "1");
198  WRITESTRINGFILEATTRIB(file_m, "RMSXUnit", "m");
199  WRITESTRINGFILEATTRIB(file_m, "RMSRUnit", "m");
200  WRITESTRINGFILEATTRIB(file_m, "RMSPUnit", "#beta#gamma");
201 
202  WRITESTRINGFILEATTRIB(file_m, "MASSUnit", "GeV");
203  WRITESTRINGFILEATTRIB(file_m, "CHARGEUnit", "C");
204 
205  WRITESTRINGFILEATTRIB(file_m, "spos-headUnit", "m");
206  WRITESTRINGFILEATTRIB(file_m, "E-headUnit", "MV/m");
207  WRITESTRINGFILEATTRIB(file_m, "B-headUnit", "T");
208  WRITESTRINGFILEATTRIB(file_m, "spos-refUnit", "m");
209  WRITESTRINGFILEATTRIB(file_m, "E-refUnit", "MV/m");
210  WRITESTRINGFILEATTRIB(file_m, "B-refUnit", "T");
211  WRITESTRINGFILEATTRIB(file_m, "spos-tailUnit", "m");
212  WRITESTRINGFILEATTRIB(file_m, "E-tailUnit", "MV/m");
213  WRITESTRINGFILEATTRIB(file_m, "B-tailUnit", "T");
214 
215  WRITESTRINGFILEATTRIB(file_m, "NumBunchUnit", "1");
216  WRITESTRINGFILEATTRIB(file_m, "NumPartUnit", "1");
217 
218  WRITESTRINGFILEATTRIB(file_m, "RefPartRUnit", "m");
219  WRITESTRINGFILEATTRIB(file_m, "RefPartPUnit", "#beta#gamma");
220 
222  WRITEFILEATTRIB(Int64, file_m, "dump frequency", &dumpfreq, 1);
223 
225  WRITEFILEATTRIB(Float64, file_m, "dPhiGlobal", &dphi, 1);
226 }
227 
228 void H5PartWrapperForPS::writeStep(PartBunchBase<double, 3>* bunch, const std::map<std::string, double> &additionalStepAttributes) {
229  if (static_cast<EnvelopeBunch*>(bunch)->getTotalNum() == 0) return;
230 
231  open(H5_O_APPENDONLY);
232  writeStepHeader(bunch, additionalStepAttributes);
233  writeStepData(bunch);
234  close();
235 }
236 
238  const std::map<std::string, double> &additionalStepAttributes) {
239  EnvelopeBunch *ebunch = static_cast<EnvelopeBunch*>(bunch);
240  ebunch->calcBeamParameters();
241 
242  double actPos = ebunch->get_sPos();
243  double t = ebunch->getT();
244  Vector_t rmin = ebunch->get_origin();
245  Vector_t rmax = ebunch->get_maxExtent();
246 
247  Vector_t xsigma = ebunch->get_rrms();
248  Vector_t psigma = ebunch->get_prms();
249  Vector_t vareps = ebunch->get_norm_emit();
250 
251  double meanEnergy = ebunch->get_meanKineticEnergy();
252 
253  double mass = 1.0e-9 * ebunch->getM();
254  double charge = ebunch->getCharge();
255 
256  Vector_t minP = ebunch->minP();
257  Vector_t maxP = ebunch->maxP();
258 
259  // TODO:
260  Vector_t RefPartR(0.0);
261  Vector_t RefPartP(0.0);
262  Vector_t centroid(0.0);
263  Vector_t geomvareps(0.0);
264  double I_0 = 4.0 * Physics::pi * Physics::epsilon_0 * Physics::c * ebunch->getM() / ebunch->getQ();
265  double sigma = ((xsigma[0] * xsigma[0]) + (xsigma[1] * xsigma[1])) /
266  (2.0 * ebunch->get_gamma() * I_0 * (geomvareps[0] * geomvareps[0] + geomvareps[1] * geomvareps[1]));
267 
268  /* ------------------------------------------------------------------------ */
269 
270  REPORTONERROR(H5SetStep(file_m, numSteps_m));
271 
272  char const *OPALFlavour = "opal-env";
273  WRITESTRINGSTEPATTRIB(file_m, "OPAL_flavour", OPALFlavour);
274  WRITESTEPATTRIB(Float64, file_m, "TIME", &t, 1);
275  WRITESTEPATTRIB(Float64, file_m, "SPOS", &actPos, 1);
276  WRITESTEPATTRIB(Float64, file_m, "RMSX", (h5_float64_t *)&xsigma, 3);
277  WRITESTEPATTRIB(Float64, file_m, "RMSP", (h5_float64_t *)&psigma, 3);
278  WRITESTEPATTRIB(Float64, file_m, "#varepsilon", (h5_float64_t *)&vareps, 3);
279 
280  WRITESTEPATTRIB(Float64, file_m, "ENERGY", &meanEnergy, 1);
281 
282  WRITESTEPATTRIB(Float64, file_m, "RefPartR", (h5_float64_t *)&RefPartR, 3);
283  WRITESTEPATTRIB(Float64, file_m, "RefPartP", (h5_float64_t *)&RefPartP, 3);
284  WRITESTEPATTRIB(Float64, file_m, "centroid", (h5_float64_t *)&centroid, 3);
285  WRITESTEPATTRIB(Float64, file_m, "#varepsilon-geom", (h5_float64_t *)&geomvareps, 3);
286 
287  WRITESTEPATTRIB(Float64, file_m, "minX", (h5_float64_t *)&rmin, 3);
288  WRITESTEPATTRIB(Float64, file_m, "maxX", (h5_float64_t *)&rmax, 3);
289 
290  WRITESTEPATTRIB(Float64, file_m, "minP", (h5_float64_t *)&minP, 3);
291  WRITESTEPATTRIB(Float64, file_m, "maxP", (h5_float64_t *)&maxP, 3);
292 
293  WRITESTEPATTRIB(Float64, file_m, "#sigma", &sigma, 1);
294 
296  WRITESTEPATTRIB(Float64, file_m, "MASS", &mass, 1);
297  WRITESTEPATTRIB(Float64, file_m, "CHARGE", &charge, 1);
298 
299  try {
300  double sposHead = additionalStepAttributes.at("sposHead");
301  double sposRef = additionalStepAttributes.at("sposRef");
302  double sposTail = additionalStepAttributes.at("sposTail");
303  Vector_t referenceB(additionalStepAttributes.at("B-ref_x"),
304  additionalStepAttributes.at("B-ref_z"),
305  additionalStepAttributes.at("B-ref_y"));
306  Vector_t referenceE(additionalStepAttributes.at("E-ref_x"),
307  additionalStepAttributes.at("E-ref_z"),
308  additionalStepAttributes.at("E-ref_y"));
309  Vector_t headB(additionalStepAttributes.at("B-head_x"),
310  additionalStepAttributes.at("B-head_z"),
311  additionalStepAttributes.at("B-head_y"));
312  Vector_t headE(additionalStepAttributes.at("E-head_x"),
313  additionalStepAttributes.at("E-head_z"),
314  additionalStepAttributes.at("E-head_y"));
315  Vector_t tailB(additionalStepAttributes.at("B-tail_x"),
316  additionalStepAttributes.at("B-tail_z"),
317  additionalStepAttributes.at("B-tail_y"));
318  Vector_t tailE(additionalStepAttributes.at("E-tail_x"),
319  additionalStepAttributes.at("E-tail_z"),
320  additionalStepAttributes.at("E-tail_y"));
321 
322  WRITESTEPATTRIB(Float64, file_m, "spos-head", &sposHead, 1);
323  WRITESTEPATTRIB(Float64, file_m, "spos-ref", &sposRef, 1);
324  WRITESTEPATTRIB(Float64, file_m, "spos-tail", &sposTail, 1);
325 
326  WRITESTEPATTRIB(Float64, file_m, "B-ref", (h5_float64_t *)&referenceB, 3);
327  WRITESTEPATTRIB(Float64, file_m, "E-ref", (h5_float64_t *)&referenceE, 3);
328  WRITESTEPATTRIB(Float64, file_m, "B-head", (h5_float64_t *)&headB, 3);
329  WRITESTEPATTRIB(Float64, file_m, "E-head", (h5_float64_t *)&headE, 3);
330  WRITESTEPATTRIB(Float64, file_m, "B-tail", (h5_float64_t *)&tailB, 3);
331  WRITESTEPATTRIB(Float64, file_m, "E-tail", (h5_float64_t *)&tailE, 3);
332  } catch (std::out_of_range & m) {
333  ERRORMSG(m.what() << endl);
334 
335  throw OpalException("H5PartWrapperForPC::writeStepHeader",
336  "some additional step attribute not found");
337  }
338  ++ numSteps_m;
339 }
340 
342  EnvelopeBunch *ebunch = static_cast<EnvelopeBunch*>(bunch);
343 
344  size_t numLocalParticles = ebunch->getLocalNum();
345 
346  std::vector<char> buffer(numLocalParticles * sizeof(h5_float64_t));
347  h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]);
348 
349  REPORTONERROR(H5PartSetNumParticles(file_m, numLocalParticles));
350 
351  for(size_t i = 0; i < numLocalParticles; ++ i)
352  f64buffer[i] = ebunch->getX(i);
353  WRITEDATA(Float64, file_m, "x", f64buffer);
354 
355  for(size_t i = 0; i < numLocalParticles; ++ i)
356  f64buffer[i] = ebunch->getY(i);
357  WRITEDATA(Float64, file_m, "y", f64buffer);
358 
359  for(size_t i = 0; i < numLocalParticles; ++ i)
360  f64buffer[i] = ebunch->getZ(i);
361  WRITEDATA(Float64, file_m, "z", f64buffer);
362 
363  for(size_t i = 0; i < numLocalParticles; ++ i)
364  f64buffer[i] = ebunch->getPx(i);
365  WRITEDATA(Float64, file_m, "px", f64buffer);
366 
367  for(size_t i = 0; i < numLocalParticles; ++ i)
368  f64buffer[i] = ebunch->getPy(i);
369  WRITEDATA(Float64, file_m, "py", f64buffer);
370 
371  for(size_t i = 0; i < numLocalParticles; ++ i)
372  f64buffer[i] = ebunch->getPz(i);
373  WRITEDATA(Float64, file_m, "pz", f64buffer);
374 
375  for(size_t i = 0; i < numLocalParticles; ++ i)
376  f64buffer[i] = ebunch->getBeta(i);
377  WRITEDATA(Float64, file_m, "beta", f64buffer);
378 
379  for(size_t i = 0; i < numLocalParticles; ++ i)
380  f64buffer[i] = ebunch->getX0(i);
381  WRITEDATA(Float64, file_m, "X0", f64buffer);
382 
383  for(size_t i = 0; i < numLocalParticles; ++ i)
384  f64buffer[i] = ebunch->getY0(i);
385  WRITEDATA(Float64, file_m, "Y0", f64buffer);
386 
387  for(size_t i = 0; i < numLocalParticles; ++ i)
388  f64buffer[i] = ebunch->getPx0(i);
389  WRITEDATA(Float64, file_m, "pX0", f64buffer);
390 
391  for(size_t i = 0; i < numLocalParticles; ++ i)
392  f64buffer[i] = ebunch->getPy0(i);
393  WRITEDATA(Float64, file_m, "pY0", f64buffer);
394 }
395 
397  Vector_t FDext[],
398  double sposHead,
399  double sposRef,
400  double sposTail) {
401  EnvelopeBunch *ebunch = static_cast<EnvelopeBunch*>(&bunch);
402 
405  ebunch->calcBeamParameters();
406 
407  size_t numLocalParticles = ebunch->getLocalNum();
408  //TODO:
409  stash_RefPartR.push_back(Vector_t(0.0)); //ebunch->RefPart_R;
410  stash_RefPartP.push_back(Vector_t(0.0)); //ebunch->RefPart_P;
411  stash_centroid.push_back(Vector_t(0.0));
412 
413  stash_actPos.push_back(ebunch->get_sPos());
414  stash_t.push_back(ebunch->getT());
415 
416  stash_nTot.push_back(ebunch->getTotalNum());
417  stash_nLoc.push_back(numLocalParticles);
418 
419  stash_xsigma.push_back(ebunch->sigmax());
420  stash_psigma.push_back(ebunch->sigmap());
421  stash_vareps.push_back(ebunch->get_norm_emit());
422  stash_geomvareps.push_back(ebunch->emtn());
423  stash_rmin.push_back(ebunch->minX());
424  stash_rmax.push_back(ebunch->maxX());
425  stash_maxP.push_back(ebunch->maxP());
426  stash_minP.push_back(ebunch->minP());
427 
428  //in MeV
429  stash_meanEnergy.push_back(ebunch->get_meanKineticEnergy() * 1e-6);
430 
431  stash_sposHead.push_back(sposHead);
432  stash_sposRef.push_back(sposRef);
433  stash_sposTail.push_back(sposTail);
434  stash_Bhead.push_back(FDext[0]);
435  stash_Ehead.push_back(FDext[1]);
436  stash_Bref.push_back(FDext[2]);
437  stash_Eref.push_back(FDext[3]);
438  stash_Btail.push_back(FDext[4]);
439  stash_Etail.push_back(FDext[5]);
440 
443  stash_mass.push_back(1.0e-9 * ebunch->getM());
444  stash_charge.push_back(ebunch->getChargePerParticle());
445 
447  //for (size_t i=0; i<numLocalParticles;i++)
448  //farray[i] = bunch->getX(i);
449 
450  //for (size_t i=0; i<numLocalParticles;i++)
451  //farray[i] = bunch->getY(i);
452 
453  //for (size_t i=0; i<numLocalParticles;i++)
454  //farray[i] = bunch->getZ(i);
455 
456  //for (size_t i=0; i<numLocalParticles;i++)
457  //farray[i] = bunch->getPx(i);
458 
459  //for (size_t i=0; i<numLocalParticles;i++)
460  //farray[i] = bunch->getPy(i);
461 
462  //for (size_t i=0; i<numLocalParticles;i++)
463  //farray[i] = bunch->getPz(i);
464 
465  ++ numSteps_m;
466 }
467 
469 
470  size_t numLocalParticles = stash_nLoc[0];
471  std::vector<char> buffer(numLocalParticles * sizeof(h5_float64_t));
472  h5_float64_t *f64buffer = reinterpret_cast<h5_float64_t*>(&buffer[0]);
473 
474  //FIXME: restart step
475  for(int step = 0; step < numSteps_m; ++ step) {
476  numLocalParticles = stash_nLoc[step];
477 
479  REPORTONERROR(H5SetStep(file_m, step));
480  REPORTONERROR(H5PartSetNumParticles(file_m, numLocalParticles));
481 
483  WRITESTEPATTRIB(Float64, file_m, "SPOS", &stash_actPos[step], 1);
484  WRITESTEPATTRIB(Float64, file_m, "RMSX", &stash_xsigma[step](0), 3);
485  WRITESTEPATTRIB(Float64, file_m, "RMSP", &stash_psigma[step](0), 3);
486  WRITESTEPATTRIB(Float64, file_m, "maxX", &stash_rmax[step](0), 3);
487  WRITESTEPATTRIB(Float64, file_m, "minX", &stash_rmin[step](0), 3);
488  WRITESTEPATTRIB(Float64, file_m, "maxP", &stash_maxP[step](0), 3);
489  WRITESTEPATTRIB(Float64, file_m, "minP", &stash_minP[step](0), 3);
490  WRITESTEPATTRIB(Float64, file_m, "centroid", &stash_centroid[step](0), 3);
491  WRITESTEPATTRIB(Float64, file_m, "TIME", &stash_t[step], 1);
492  WRITESTEPATTRIB(Float64, file_m, "ENERGY", &stash_meanEnergy[step], 1);
493  WRITESTEPATTRIB(Float64, file_m, "RefPartR", &stash_RefPartR[step](0), 3);
494  WRITESTEPATTRIB(Float64, file_m, "RefPartP", &stash_RefPartP[step](0), 3);
495  WRITESTEPATTRIB(Float64, file_m, "B-head", &stash_Bhead[step](0), 3);
496  WRITESTEPATTRIB(Float64, file_m, "E-head", &stash_Ehead[step](0), 3);
497  WRITESTEPATTRIB(Float64, file_m, "B-ref", &stash_Bref[step](0), 3);
498  WRITESTEPATTRIB(Float64, file_m, "E-ref", &stash_Eref[step](0), 3);
499  WRITESTEPATTRIB(Float64, file_m, "B-tail", &stash_Btail[step](0), 3);
500  WRITESTEPATTRIB(Float64, file_m, "E-tail", &stash_Etail[step](0), 3);
501  WRITESTEPATTRIB(Float64, file_m, "spos-head", &stash_sposHead[step], 1);
502  WRITESTEPATTRIB(Float64, file_m, "spos-ref", &stash_sposRef[step], 1);
503  WRITESTEPATTRIB(Float64, file_m, "spos-tail", &stash_sposTail[step], 1);
504 
507  WRITESTEPATTRIB(Float64, file_m, "MASS", &stash_mass[step], 1);
508  WRITESTEPATTRIB(Float64, file_m, "CHARGE", &stash_charge[step], 1);
510  WRITESTEPATTRIB(Float64, file_m, "#varepsilon", &stash_vareps[step](0), 3);
512  WRITESTEPATTRIB(Float64, file_m, "#varepsilon-geom", &stash_geomvareps[step](0), 3);
513 
515  for(size_t i = 0; i < numLocalParticles; i++)
516  f64buffer[i] = 0.0;
517  WRITEDATA(Float64, file_m, "x", f64buffer);
518  for(size_t i = 0; i < numLocalParticles; i++)
519  f64buffer[i] = 0.0; //bunch->getY(i);
520  WRITEDATA(Float64, file_m, "y", f64buffer);
521  for(size_t i = 0; i < numLocalParticles; i++)
522  f64buffer[i] = 0.0; //bunch->getZ(i);
523  WRITEDATA(Float64, file_m, "z", f64buffer);
524  for(size_t i = 0; i < numLocalParticles; i++)
525  f64buffer[i] = 0.0; //bunch->getPx(i);
526  WRITEDATA(Float64, file_m, "px", f64buffer);
527  for(size_t i = 0; i < numLocalParticles; i++)
528  f64buffer[i] = 0.0; //bunch->getPy(i);
529  WRITEDATA(Float64, file_m, "py", f64buffer);
530  for(size_t i = 0; i < numLocalParticles; i++)
531  f64buffer[i] = 0.0; //bunch->getPz(i);
532  WRITEDATA(Float64, file_m, "pz", f64buffer);
533  //rc = H5Fflush, file_m->file, rc = H5F_SCOPE_GLOBAL);
534  }
535 }
void setBeta(int i, double val)
void setPy(int i, double val)
void setPy0(int i, double val)
Vector_t minX()
returns vector with the min spatial extends of the bunch
double get_meanKineticEnergy()
returns the mean energy
void open(h5_int32_t flags)
Vector_t get_rrms()
returns RMS x,y,z
constexpr double e
The value of .
Definition: Physics.h:40
double getT()
returns the current time of the bunch
void readStepHeader(PartBunchBase< double, 3 > *)
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &additionalStepAttributes)
std::vector< h5_float64_t > stash_sposRef
std::vector< Vektor< h5_float64_t, 3 > > stash_Etail
core of the envelope tracker based on Rene Bakkers BET implementation
Definition: EnvelopeBunch.h:60
Vector_t maxX()
returns vector with the max spatial extends of the bunch
Vector_t get_norm_emit()
returns vector with normalized emittance
std::vector< Vektor< h5_float64_t, 3 > > stash_psigma
double getZ(int i)
returns Z coordinate of slice i
The base class for all OPAL exceptions.
Definition: OpalException.h:28
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
void setZ(int i, double coo)
set Z coordinate of slice i
double getM() const
std::vector< Vektor< h5_float64_t, 3 > > stash_Ehead
std::vector< Vektor< h5_float64_t, 3 > > stash_Btail
#define WRITEDATA(type, file, name, value)
Definition: H5PartWrapper.h:28
#define REPORTONERROR(rc)
Definition: H5PartWrapper.h:18
void setX(int i, double val)
double getX0(int i)
returns X coordinate of the centroid of slice i
#define WRITESTRINGSTEPATTRIB(file, name, value)
Definition: H5PartWrapper.h:24
h5_int64_t numSteps_m
Definition: H5PartWrapper.h:72
virtual void writeHeader()
Vector_t sigmax()
returns vector with rms position
std::vector< size_t > stash_nLoc
static OpalData * getInstance()
Definition: OpalData.cpp:209
#define OPAL_PROJECT_NAME
Definition: OPALconfig.h:2
Vector_t get_maxExtent() const
std::vector< h5_float64_t > stash_t
std::vector< Vektor< h5_float64_t, 3 > > stash_rmax
double getGlobalPhaseShift()
units: (sec)
Definition: OpalData.cpp:497
std::vector< Vektor< h5_float64_t, 3 > > stash_rmin
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
Definition: OpalData.cpp:369
constexpr double pi
The value of .
Definition: Physics.h:31
Vector_t maxP()
returns vector with the max momentum of the bunch
Vector_t emtn()
returns vector with emittance
double getPy(int i)
returns Y momenta of slice i
std::vector< h5_float64_t > stash_meanEnergy
std::vector< Vektor< h5_float64_t, 3 > > stash_RefPartP
std::vector< Vektor< h5_float64_t, 3 > > stash_RefPartR
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
double getY0(int i)
returns Y coordinate of the centroid of slice i
void writeStepHeader(PartBunchBase< double, 3 > *, const std::map< std::string, double > &)
std::vector< size_t > stash_nTot
double get_sPos()
return reference position
std::vector< Vektor< h5_float64_t, 3 > > stash_geomvareps
void writeStepData(PartBunchBase< double, 3 > *)
double getPx0(int i)
returns angular deflection centroid in x of slice i
H5PartWrapperForPS(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
#define OPAL_PROJECT_VERSION
Definition: OPALconfig.h:5
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
std::vector< Vektor< h5_float64_t, 3 > > stash_Eref
std::vector< h5_float64_t > stash_sposTail
int getLocalNum()
returns the number of local slices
Vector_t get_origin() const
#define WRITESTEPATTRIB(type, file, name, value, length)
Definition: H5PartWrapper.h:25
std::vector< h5_float64_t > stash_mass
void setX0(int i, double val)
double getPy0(int i)
returns angular deflection centroid in y of slice i
std::vector< Vektor< h5_float64_t, 3 > > stash_maxP
int psDumpFreq
The frequency to dump the phase space, i.e.dump data when steppsDumpFreq==0.
Definition: Options.cpp:48
double getCharge() const
get the total charge per simulation particle
#define READSTEPATTRIB(type, file, name, value)
Definition: H5PartWrapper.h:23
std::vector< h5_float64_t > stash_actPos
void setY(int i, double val)
double getY(int i)
returns Y coordinate of slice i
double get_gamma() const
std::vector< Vektor< h5_float64_t, 3 > > stash_Bhead
std::vector< h5_float64_t > stash_sposHead
void setGlobalPhaseShift(double shift)
units: (sec)
Definition: OpalData.cpp:492
virtual void readHeader()
void setT(double t)
double getQ() const
Access to reference data.
void setY0(int i, double val)
const std::string name
double getChargePerParticle()
returns charge per slice
std::vector< Vektor< h5_float64_t, 3 > > stash_minP
double getPz(int i)
returns Z momenta of slice i
std::string getGitRevision()
Definition: Util.cpp:15
double getBeta(int i)
returns beta of slice i
#define WRITEFILEATTRIB(type, file, name, value, length)
Definition: H5PartWrapper.h:21
void setPx0(int i, double val)
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
Definition: Physics.h:58
Vector_t sigmap()
returns vector with rms momenta
void stashPhaseSpaceEnvelope(EnvelopeBunch &bunch, Vector_t FDext[], double sposHead, double sposRef, double sposTail)
h5_file_t file_m
Definition: H5PartWrapper.h:69
double getPx(int i)
returns X momenta of slice i
#define READDATA(type, file, name, value)
Definition: H5PartWrapper.h:27
int getTotalNum()
returns the total number of slices
std::vector< Vektor< h5_float64_t, 3 > > stash_centroid
std::vector< Vektor< h5_float64_t, 3 > > stash_vareps
void readStepData(PartBunchBase< double, 3 > *, h5_ssize_t, h5_ssize_t)
size_t getNumParticles() const
void calcBeamParameters()
calculates envelope statistics
void setPx(int i, double val)
std::vector< Vektor< h5_float64_t, 3 > > stash_Bref
Vector_t minP()
returns vector with the min momentum of the bunch
#define READFILEATTRIB(type, file, name, value)
Definition: H5PartWrapper.h:19
std::vector< h5_float64_t > stash_charge
virtual void readStep(PartBunchBase< double, 3 > *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define WRITESTRINGFILEATTRIB(file, name, value)
Definition: H5PartWrapper.h:20
std::vector< Vektor< h5_float64_t, 3 > > stash_xsigma
Vector_t get_prms()
returns RMSP x,y,z
void setRestartStep(int s)
store the location where to restart
Definition: OpalData.cpp:345
double getX(int i)
returns X coordinate of slice i