20 previousH5Local_m(false),
21 referenceMomentum_m(0.0),
22 referenceLocation_m(0.0),
31 std::string sourceFile,
34 previousH5Local_m(false),
35 referenceMomentum_m(0.0),
36 referenceLocation_m(0.0),
47 h5_int64_t numFileAttributes = H5GetNumFileAttribs(
file_m);
49 const h5_size_t lengthAttributeName = 256;
51 h5_int64_t attributeType;
52 h5_size_t numAttributeElements;
53 std::set<std::string> attributeNames;
55 for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
61 &numAttributeElements));
66 if (attributeNames.find(
"dump frequency") != attributeNames.end()) {
74 h5_ssize_t firstParticle,
75 h5_ssize_t lastParticle)
77 h5_ssize_t numStepsInSource = H5GetNumSteps(
file_m);
78 h5_ssize_t
readStep = numStepsInSource - 1;
86 h5_float64_t pathLength;
102 bunch->
setT(actualT);
104 h5_int64_t SteptoLastInj;
124 h5_int64_t localDump = 0;
125 h5_int64_t rc = H5ReadStepAttribInt64(
file_m,
"LOCAL", &localDump);
126 if(rc != H5_SUCCESS) {
128 ERRORMSG(
"H5 rc= " << rc <<
" in " << __FILE__ <<
" @ line " << __LINE__ <<
endl);
130 std::string errormsg =
131 "You are trying to restart from a legacy file that doesn't contain"
132 "information on local/global frame. We are working on legacy support,"
133 "but for now you have to use OPAL 1.3.0!";
135 throw OpalException(
"H5PartWrapperForPC::readStepHeader", errormsg);
149 h5_ssize_t firstParticle,
150 h5_ssize_t lastParticle)
153 if (lastParticle >= numParticles || firstParticle > lastParticle) {
155 "the provided particle numbers don't match the number of particles in the file");
162 numParticles = lastParticle - firstParticle + 1;
164 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
166 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
167 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
>(buffer_ptr);
170 for(
long int n = 0;
n < numParticles; ++
n) {
171 bunch->
R[
n](0) = f64buffer[
n];
176 for(
long int n = 0;
n < numParticles; ++
n) {
177 bunch->
R[
n](yIndex) = f64buffer[
n];
181 for(
long int n = 0;
n < numParticles; ++
n) {
182 bunch->
R[
n](zIndex) = f64buffer[
n];
186 for(
long int n = 0;
n < numParticles; ++
n) {
187 bunch->
P[
n](0) = f64buffer[
n];
191 for(
long int n = 0;
n < numParticles; ++
n) {
192 bunch->
P[
n](yIndex) = f64buffer[
n];
196 for(
long int n = 0;
n < numParticles; ++
n) {
197 bunch->
P[
n](zIndex) = f64buffer[
n];
201 for(
long int n = 0;
n < numParticles; ++
n) {
202 bunch->
Q[
n] = f64buffer[
n];
206 for(
long int n = 0;
n < numParticles; ++
n) {
207 bunch->
M[
n] = f64buffer[
n];
212 for(
long int n = 0;
n < numParticles; ++
n) {
213 bunch->
Bin[
n] = i64buffer[
n];
218 for(
long int n = 0;
n < numParticles; ++
n) {
226 std::stringstream OPAL_version;
312 const std::map<std::string, double> &additionalStepAttributes)
316 open(H5_O_APPENDONLY);
325 const std::map<std::string, double> &additionalStepAttributes)
329 double t = bunch->
getT();
330 double pathLength = bunch->
get_sPos();
346 double energySpread = bunch->
getdE();
348 double sigma = ((xsigma[0] * xsigma[0]) + (xsigma[1] * xsigma[1])) /
349 (2.0 * bunch->
get_gamma() * I_0 * (geomvareps[0] * geomvareps[0] + geomvareps[1] * geomvareps[1]));
354 h5_int64_t numBunch = (h5_int64_t)bunch->
getNumBunch();
362 double sposHead = 0.0;
363 double sposRef = 0.0;
364 double sposTail = 0.0;
372 char const *OPALFlavour =
"opal-cycl";
409 h5_float64_t refpr = additionalStepAttributes.at(
"REFPR");
410 h5_float64_t refpt = additionalStepAttributes.at(
"REFPT");
411 h5_float64_t refpz = additionalStepAttributes.at(
"REFPZ");
412 h5_float64_t refr = additionalStepAttributes.at(
"REFR");
413 h5_float64_t reft = additionalStepAttributes.at(
"REFTHETA");
414 h5_float64_t refz = additionalStepAttributes.at(
"REFZ");
415 h5_float64_t azimuth = additionalStepAttributes.at(
"AZIMUTH");
416 h5_float64_t elevation = additionalStepAttributes.at(
"ELEVATION");
418 Vector_t referenceB(additionalStepAttributes.at(
"B-ref_x"),
419 additionalStepAttributes.at(
"B-ref_z"),
420 additionalStepAttributes.at(
"B-ref_y"));
421 Vector_t referenceE(additionalStepAttributes.at(
"E-ref_x"),
422 additionalStepAttributes.at(
"E-ref_z"),
423 additionalStepAttributes.at(
"E-ref_y"));
424 Vector_t headB(additionalStepAttributes.at(
"B-head_x"),
425 additionalStepAttributes.at(
"B-head_z"),
426 additionalStepAttributes.at(
"B-head_y"));
427 Vector_t headE(additionalStepAttributes.at(
"E-head_x"),
428 additionalStepAttributes.at(
"E-head_z"),
429 additionalStepAttributes.at(
"E-head_y"));
430 Vector_t tailB(additionalStepAttributes.at(
"B-tail_x"),
431 additionalStepAttributes.at(
"B-tail_z"),
432 additionalStepAttributes.at(
"B-tail_y"));
433 Vector_t tailE(additionalStepAttributes.at(
"E-tail_x"),
434 additionalStepAttributes.at(
"E-tail_z"),
435 additionalStepAttributes.at(
"E-tail_y"));
456 }
catch (std::out_of_range & m) {
460 "some additional step attribute not found");
476 for(
size_t k = 0; k < IDZero; ++ k) {
477 if (bunch->
ID[k] == 0) {
485 const size_t skipID = IDZero;
487 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
489 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
490 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
> (buffer_ptr);
495 for(
size_t i = 0; i < skipID; ++ i)
496 f64buffer[i] = bunch->
R[i](0);
497 for (
size_t i = skipID; i < numLocalParticles; ++ i)
498 f64buffer[i] = bunch->
R[i + 1](0);
502 for(
size_t i = 0; i < skipID; ++ i)
503 f64buffer[i] = bunch->
R[i](1);
504 for (
size_t i = skipID; i < numLocalParticles; ++ i)
505 f64buffer[i] = bunch->
R[i + 1](1);
509 for(
size_t i = 0; i < skipID; ++ i)
510 f64buffer[i] = bunch->
R[i](2);
511 for (
size_t i = skipID; i < numLocalParticles; ++ i)
512 f64buffer[i] = bunch->
R[i + 1](2);
516 for(
size_t i = 0; i < skipID; ++ i)
517 f64buffer[i] = bunch->
P[i](0);
518 for (
size_t i = skipID; i < numLocalParticles; ++ i)
519 f64buffer[i] = bunch->
P[i + 1](0);
523 for(
size_t i = 0; i < skipID; ++ i)
524 f64buffer[i] = bunch->
P[i](1);
525 for (
size_t i = skipID; i < numLocalParticles; ++ i)
526 f64buffer[i] = bunch->
P[i + 1](1);
530 for(
size_t i = 0; i < skipID; ++ i)
531 f64buffer[i] = bunch->
P[i](2);
532 for (
size_t i = skipID; i < numLocalParticles; ++ i)
533 f64buffer[i] = bunch->
P[i + 1](2);
537 for(
size_t i = 0; i < skipID; ++ i)
538 f64buffer[i] = bunch->
Q[i];
539 for (
size_t i = skipID; i < numLocalParticles; ++ i)
540 f64buffer[i] = bunch->
Q[i + 1];
544 for(
size_t i = 0; i < skipID; ++ i)
545 f64buffer[i] = bunch->
M[i];
546 for (
size_t i = skipID; i < numLocalParticles; ++ i)
547 f64buffer[i] = bunch->
M[i + 1];
551 for(
size_t i = 0; i < skipID; ++ i)
552 i64buffer[i] = bunch->
ID[i];
553 for (
size_t i = skipID; i < numLocalParticles; ++ i)
554 i64buffer[i] = bunch->
ID[i + 1];
559 for(
size_t i = 0; i < skipID; ++ i)
560 i64buffer[i] = bunch->
Bin[i];
561 for (
size_t i = skipID; i < numLocalParticles; ++ i)
562 i64buffer[i] = bunch->
Bin[i + 1];
567 for (
size_t i = 0; i < skipID; ++ i)
569 for (
size_t i = skipID; i < numLocalParticles; ++ i)
570 i64buffer[i] = bunch->
bunchNum[i + 1];
574 for(
size_t i = 0; i < skipID; ++ i)
575 f64buffer[i] = bunch->
Ef[i](0);
576 for (
size_t i = skipID; i < numLocalParticles; ++ i)
577 f64buffer[i] = bunch->
Ef[i + 1](0);
581 for(
size_t i = 0; i < skipID; ++ i)
582 f64buffer[i] = bunch->
Ef[i](1);
583 for (
size_t i = skipID; i < numLocalParticles; ++ i)
584 f64buffer[i] = bunch->
Ef[i + 1](1);
588 for(
size_t i = 0; i < skipID; ++ i)
589 f64buffer[i] = bunch->
Ef[i](2);
590 for (
size_t i = skipID; i < numLocalParticles; ++ i)
591 f64buffer[i] = bunch->
Ef[i + 1](2);
595 for(
size_t i = 0; i < skipID; ++ i)
596 f64buffer[i] = bunch->
Bf[i](0);
597 for (
size_t i = skipID; i < numLocalParticles; ++ i)
598 f64buffer[i] = bunch->
Bf[i + 1](0);
602 for(
size_t i = 0; i < skipID; ++ i)
603 f64buffer[i] = bunch->
Bf[i](1);
604 for (
size_t i = skipID; i < numLocalParticles; ++ i)
605 f64buffer[i] = bunch->
Bf[i + 1](1);
609 for(
size_t i = 0; i < skipID; ++ i)
610 f64buffer[i] = bunch->
Bf[i](2);
611 for (
size_t i = skipID; i < numLocalParticles; ++ i)
612 f64buffer[i] = bunch->
Bf[i + 1](2);
623 idx[0].
min(), idx[0].
max(),
624 idx[1].
min(), idx[1].
max(),
625 idx[2].
min(), idx[2].
max()));
627 std::unique_ptr<h5_float64_t[]> data(
new h5_float64_t[(idx[0].
max() + 1) * (idx[1].
max() + 1) * (idx[2].
max() + 1)]);
633 for(
int i = idx[2].
min(); i <= idx[2].max(); ++ i) {
634 for(
int j = idx[1].
min(); j <= idx[1].max(); ++ j) {
635 for(
int k = idx[0].
min(); k <= idx[0].max(); ++ k) {
636 data[ii] = bunch->
getRho(k, j, i);
650 (h5_float64_t)bunch->
get_hr()(0),
651 (h5_float64_t)bunch->
get_hr()(1),
652 (h5_float64_t)bunch->
get_hr()(2)));
#define OPAL_PROJECT_VERSION
#define OPAL_PROJECT_NAME
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
#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)
std::map< AttributeType, std::string > attributeName
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
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
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
virtual FieldLayout_t & getFieldLayout()=0
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()