14 #include <boost/filesystem.hpp>
26 if (restartStep == -1) {
27 restartStep = H5GetNumSteps(
file_m) - 1 ;
36 h5_int64_t numFileAttributes = H5GetNumFileAttribs(
file_m);
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;
44 for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
50 &numAttributeElements));
52 attributeNames.insert(attributeName);
55 if (attributeNames.find(
"dump frequency") != attributeNames.end()) {
61 if (attributeNames.find(
"dPhiGlobal") != attributeNames.end()) {
67 if (attributeNames.find(
"nAutoPhaseCavities") != attributeNames.end()) {
70 h5_int64_t numAutoPhaseCavities;
71 if (!H5HasFileAttrib(
file_m,
"nAutoPhaseCavities") ||
72 H5ReadFileAttribInt64(
file_m,
"nAutoPhaseCavities", &numAutoPhaseCavities) != H5_SUCCESS) {
73 numAutoPhaseCavities = 0;
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";
83 opal->setMaxPhase(name, phase);
90 h5_ssize_t numStepsInSource = H5GetNumSteps(
file_m);
91 h5_ssize_t
readStep = numStepsInSource - 1;
101 bunch->
setT(actualT);
106 if (lastParticle >= numParticles || firstParticle > lastParticle) {
108 "the provided particle numbers don't match the number of particles in the file");
115 numParticles = lastParticle - firstParticle + 1;
117 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
118 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
121 for(
long int n = 0;
n < numParticles; ++
n) {
122 ebunch->
setX(
n, f64buffer[
n]);
126 for(
long int n = 0;
n < numParticles; ++
n) {
127 ebunch->
setY(
n, f64buffer[
n]);
131 for(
long int n = 0;
n < numParticles; ++
n) {
132 ebunch->
setZ(
n, f64buffer[
n]);
136 for(
long int n = 0;
n < numParticles; ++
n) {
137 ebunch->
setPx(
n, f64buffer[
n]);
141 for(
long int n = 0;
n < numParticles; ++
n) {
142 ebunch->
setPy(
n, f64buffer[
n]);
146 for(
long int n = 0;
n < numParticles; ++
n) {
151 for(
long int n = 0;
n < numParticles; ++
n) {
152 ebunch->
setX0(
n, f64buffer[
n]);
156 for(
long int n = 0;
n < numParticles; ++
n) {
157 ebunch->
setY0(
n, f64buffer[
n]);
161 for(
long int n = 0;
n < numParticles; ++
n) {
166 for(
long int n = 0;
n < numParticles; ++
n) {
176 std::stringstream OPAL_version;
229 if (static_cast<EnvelopeBunch*>(bunch)->getTotalNum() == 0)
return;
231 open(H5_O_APPENDONLY);
238 const std::map<std::string, double> &additionalStepAttributes) {
243 double t = ebunch->
getT();
253 double mass = 1.0e-9 * ebunch->
getM();
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]));
272 char const *OPALFlavour =
"opal-env";
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"));
332 }
catch (std::out_of_range & m) {
336 "some additional step attribute not found");
346 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
347 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
351 for(
size_t i = 0; i < numLocalParticles; ++ i)
352 f64buffer[i] = ebunch->
getX(i);
355 for(
size_t i = 0; i < numLocalParticles; ++ i)
356 f64buffer[i] = ebunch->
getY(i);
359 for(
size_t i = 0; i < numLocalParticles; ++ i)
360 f64buffer[i] = ebunch->
getZ(i);
363 for(
size_t i = 0; i < numLocalParticles; ++ i)
364 f64buffer[i] = ebunch->
getPx(i);
367 for(
size_t i = 0; i < numLocalParticles; ++ i)
368 f64buffer[i] = ebunch->
getPy(i);
371 for(
size_t i = 0; i < numLocalParticles; ++ i)
372 f64buffer[i] = ebunch->
getPz(i);
375 for(
size_t i = 0; i < numLocalParticles; ++ i)
376 f64buffer[i] = ebunch->
getBeta(i);
379 for(
size_t i = 0; i < numLocalParticles; ++ i)
380 f64buffer[i] = ebunch->
getX0(i);
383 for(
size_t i = 0; i < numLocalParticles; ++ i)
384 f64buffer[i] = ebunch->
getY0(i);
387 for(
size_t i = 0; i < numLocalParticles; ++ i)
388 f64buffer[i] = ebunch->
getPx0(i);
391 for(
size_t i = 0; i < numLocalParticles; ++ i)
392 f64buffer[i] = ebunch->
getPy0(i);
471 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
472 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
475 for(
int step = 0; step <
numSteps_m; ++ step) {
515 for(
size_t i = 0; i < numLocalParticles; i++)
518 for(
size_t i = 0; i < numLocalParticles; i++)
521 for(
size_t i = 0; i < numLocalParticles; i++)
524 for(
size_t i = 0; i < numLocalParticles; i++)
527 for(
size_t i = 0; i < numLocalParticles; i++)
530 for(
size_t i = 0; i < numLocalParticles; i++)
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 .
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
virtual ~H5PartWrapperForPS()
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.
void setZ(int i, double coo)
set Z coordinate of slice i
std::vector< Vektor< h5_float64_t, 3 > > stash_Ehead
std::vector< Vektor< h5_float64_t, 3 > > stash_Btail
#define WRITEDATA(type, file, name, value)
#define REPORTONERROR(rc)
void setX(int i, double val)
double getX0(int i)
returns X coordinate of the centroid of slice i
#define WRITESTRINGSTEPATTRIB(file, name, value)
virtual void writeHeader()
Vector_t sigmax()
returns vector with rms position
std::vector< size_t > stash_nLoc
static OpalData * getInstance()
#define OPAL_PROJECT_NAME
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)
std::vector< Vektor< h5_float64_t, 3 > > stash_rmin
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
constexpr double pi
The value of .
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.
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
void dumpStashedPhaseSpaceEnvelope()
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
Vektor< double, 3 > Vector_t
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)
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.
double getCharge() const
get the total charge per simulation particle
#define READSTEPATTRIB(type, file, name, value)
std::vector< h5_float64_t > stash_actPos
void setY(int i, double val)
double getY(int i)
returns Y coordinate of slice i
std::vector< Vektor< h5_float64_t, 3 > > stash_Bhead
std::vector< h5_float64_t > stash_sposHead
void setGlobalPhaseShift(double shift)
units: (sec)
virtual void readHeader()
double getQ() const
Access to reference data.
void setY0(int i, double val)
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()
double getBeta(int i)
returns beta of slice i
#define WRITEFILEATTRIB(type, file, name, value, length)
void setPx0(int i, double val)
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
Vector_t sigmap()
returns vector with rms momenta
void stashPhaseSpaceEnvelope(EnvelopeBunch &bunch, Vector_t FDext[], double sposHead, double sposRef, double sposTail)
double getPx(int i)
returns X momenta of slice i
#define READDATA(type, file, name, value)
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)
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)
#define WRITESTRINGFILEATTRIB(file, name, value)
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
double getX(int i)
returns X coordinate of slice i