19 previousH5Local_m(false),
20 referenceMomentum_m(0.0),
21 referenceLocation_m(0.0),
30 std::string sourceFile,
33 previousH5Local_m(false),
34 referenceMomentum_m(0.0),
35 referenceLocation_m(0.0),
46 h5_int64_t numFileAttributes = H5GetNumFileAttribs(
file_m);
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;
54 for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
60 &numAttributeElements));
62 attributeNames.insert(attributeName);
65 if (attributeNames.find(
"dump frequency") != attributeNames.end()) {
73 h5_ssize_t firstParticle,
74 h5_ssize_t lastParticle)
76 h5_ssize_t numStepsInSource = H5GetNumSteps(
file_m);
77 h5_ssize_t
readStep = numStepsInSource - 1;
85 h5_float64_t pathLength;
101 bunch->
setT(actualT);
103 h5_int64_t SteptoLastInj;
123 h5_int64_t localDump = 0;
124 h5_int64_t rc = H5ReadStepAttribInt64(
file_m,
"LOCAL", &localDump);
125 if(rc != H5_SUCCESS) {
127 ERRORMSG(
"H5 rc= " << rc <<
" in " << __FILE__ <<
" @ line " << __LINE__ <<
endl);
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!";
134 throw OpalException(
"H5PartWrapperForPC::readStepHeader", errormsg);
143 double mass = bunch->
getM() * 1
e-6;
148 h5_ssize_t firstParticle,
149 h5_ssize_t lastParticle)
152 if (lastParticle >= numParticles || firstParticle > lastParticle) {
154 "the provided particle numbers don't match the number of particles in the file");
161 numParticles = lastParticle - firstParticle + 1;
163 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
165 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
166 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
>(buffer_ptr);
169 for(
long int n = 0;
n < numParticles; ++
n) {
170 bunch->
R[
n](0) = f64buffer[
n];
175 for(
long int n = 0;
n < numParticles; ++
n) {
176 bunch->
R[
n](yIndex) = f64buffer[
n];
180 for(
long int n = 0;
n < numParticles; ++
n) {
181 bunch->
R[
n](zIndex) = f64buffer[
n];
185 for(
long int n = 0;
n < numParticles; ++
n) {
186 bunch->
P[
n](0) = f64buffer[
n];
190 for(
long int n = 0;
n < numParticles; ++
n) {
191 bunch->
P[
n](yIndex) = f64buffer[
n];
195 for(
long int n = 0;
n < numParticles; ++
n) {
196 bunch->
P[
n](zIndex) = f64buffer[
n];
200 for(
long int n = 0;
n < numParticles; ++
n) {
201 bunch->
Q[
n] = f64buffer[
n];
205 for(
long int n = 0;
n < numParticles; ++
n) {
206 bunch->
M[
n] = f64buffer[
n];
211 for(
long int n = 0;
n < numParticles; ++
n) {
212 bunch->
Bin[
n] = i64buffer[
n];
217 for(
long int n = 0;
n < numParticles; ++
n) {
225 std::stringstream OPAL_version;
311 const std::map<std::string, double> &additionalStepAttributes)
315 open(H5_O_APPENDONLY);
324 const std::map<std::string, double> &additionalStepAttributes)
328 double t = bunch->
getT();
329 double pathLength = bunch->
get_sPos();
345 double energySpread = bunch->
getdE();
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]));
353 h5_int64_t numBunch = (h5_int64_t)bunch->
getNumBunch();
356 double mass = 1.0e-9 * bunch->
getM();
361 double sposHead = 0.0;
362 double sposRef = 0.0;
363 double sposTail = 0.0;
371 char const *OPALFlavour =
"opal-cycl";
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");
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"));
455 }
catch (std::out_of_range & m) {
459 "some additional step attribute not found");
475 for(
size_t k = 0; k < IDZero; ++ k) {
476 if (bunch->
ID[k] == 0) {
484 const size_t skipID = IDZero;
486 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
488 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
489 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
> (buffer_ptr);
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);
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);
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);
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);
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);
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);
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];
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];
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];
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];
566 for (
size_t i = 0; i < skipID; ++ i)
568 for (
size_t i = skipID; i < numLocalParticles; ++ i)
569 i64buffer[i] = bunch->
bunchNum[i + 1];
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);
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);
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);
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);
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);
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);
622 idx[0].
min(), idx[0].
max(),
623 idx[1].
min(), idx[1].
max(),
624 idx[2].
min(), idx[2].
max()));
626 std::unique_ptr<h5_float64_t[]> data(
new h5_float64_t[(idx[0].
max() + 1) * (idx[1].
max() + 1) * (idx[2].
max() + 1)]);
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);
649 (h5_float64_t)bunch->
get_hr()(0),
650 (h5_float64_t)bunch->
get_hr()(1),
651 (h5_float64_t)bunch->
get_hr()(2)));
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
#define OPAL_PROJECT_VERSION
#define OPAL_PROJECT_NAME
#define WRITESTRINGFILEATTRIB(file, name, value)
#define WRITESTEPATTRIB(type, file, name, value, length)
#define REPORTONERROR(rc)
#define READSTEPATTRIB(type, file, name, value)
#define WRITEDATA(type, file, name, value)
#define WRITEFILEATTRIB(type, file, name, value, length)
#define WRITESTRINGSTEPATTRIB(file, name, value)
#define READDATA(type, file, name, value)
#define READFILEATTRIB(type, file, name, value)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Inform & endl(Inform &inf)
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
constexpr double e
The value of.
constexpr double c
The velocity of light in m/s.
constexpr double pi
The value of.
int psDumpFreq
The frequency to dump the phase space, i.e.dump data when steppsDumpFreq==0.
DumpFrame psDumpFrame
flag to decide in which coordinate frame the phase space will be dumped for OPAL-cycl
T * c_data(std::vector< T, A > &v)
std::string getGitRevision()
ParticleAttrib< Vector_t > Ef
double get_meanKineticEnergy() const
ParticleAttrib< int > Bin
int getSteptoLastInj() const
void setNumBunch(short n)
double getQ() const
Access to reference data.
size_t getLocalNum() const
void setLocalTrackStep(long long n)
step in a TRACK command
ParticleAttrib< double > M
size_t getTotalNum() const
ParticleAttrib< Vector_t > P
Vector_t get_rrms() const
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
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
ParticleAttrib< Vector_t > Bf
long long getGlobalTrackStep() const
virtual Vector_t get_hr() const
Vector_t get_emit() const
Vector_t get_rmean() const
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
static OpalData * getInstance()
size_t getNumParticles() const
void open(h5_int32_t flags)
std::string predecessorOPALFlavour_m
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &additionalStepAttributes)
void readStepData(PartBunchBase< double, 3 > *, h5_ssize_t, h5_ssize_t)
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 > *)
Vector_t referenceLocation_m
h5_float64_t meanMomentum_m
virtual ~H5PartWrapperForPC()
virtual void readHeader()
Vector_t referenceMomentum_m
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.
NDIndex< Dim > getLocalNDIndex()