13 #include "h5core/h5_types.h"
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 = 0;
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);
125 Quaternion rotTheta(
cos(0.5 * TaitBryant[0]), 0,
sin(0.5 * TaitBryant[0]), 0);
126 Quaternion rotPhi(
cos(0.5 * TaitBryant[1]),
sin(0.5 * TaitBryant[1]), 0, 0);
127 Quaternion rotPsi(
cos(0.5 * TaitBryant[2]), 0, 0,
sin(0.5 * TaitBryant[2]));
128 Quaternion rotation = rotTheta * (rotPhi * rotPsi);
134 if (lastParticle >= numParticles || firstParticle > lastParticle) {
136 "the provided particle numbers don't match the number of particles in the file");
141 numParticles = lastParticle - firstParticle + 1;
143 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
144 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
145 h5_int32_t *i32buffer =
reinterpret_cast<h5_int32_t*
>(&buffer[0]);
148 for(
long int n = 0;
n < numParticles; ++
n) {
149 bunch->
R[
n](0) = f64buffer[
n];
154 for(
long int n = 0;
n < numParticles; ++
n) {
155 bunch->
R[
n](1) = f64buffer[
n];
159 for(
long int n = 0;
n < numParticles; ++
n) {
160 bunch->
R[
n](2) = f64buffer[
n];
164 for(
long int n = 0;
n < numParticles; ++
n) {
165 bunch->
P[
n](0) = f64buffer[
n];
169 for(
long int n = 0;
n < numParticles; ++
n) {
170 bunch->
P[
n](1) = f64buffer[
n];
174 for(
long int n = 0;
n < numParticles; ++
n) {
175 bunch->
P[
n](2) = f64buffer[
n];
179 for(
long int n = 0;
n < numParticles; ++
n) {
180 bunch->
Q[
n] = f64buffer[
n];
184 for(
long int n = 0;
n < numParticles; ++
n) {
185 bunch->
ID[
n] = i32buffer[
n];
192 std::stringstream OPAL_version;
277 open(H5_O_APPENDONLY);
287 double t = bunch->
getT();
305 double energySpread = bunch->
getdE();
307 double sigma = ((xsigma[0] * xsigma[0]) + (xsigma[1] * xsigma[1])) /
308 (2.0 * bunch->
get_gamma() * I_0 * (geomvareps[0] * geomvareps[0] + geomvareps[1] * geomvareps[1]));
313 double mass = 1.0e-9 * bunch->
getM();
316 h5_int64_t numBunch = 1;
317 h5_int64_t SteptoLastInj = 0;
325 char const *OPALFlavour =
"opal-t";
367 Vector_t referenceB(additionalStepAttributes.at(
"B-ref_x"),
368 additionalStepAttributes.at(
"B-ref_z"),
369 additionalStepAttributes.at(
"B-ref_y"));
370 Vector_t referenceE(additionalStepAttributes.at(
"E-ref_x"),
371 additionalStepAttributes.at(
"E-ref_z"),
372 additionalStepAttributes.at(
"E-ref_y"));
376 }
catch (std::out_of_range & m) {
380 "some additional step attribute not found");
391 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
392 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
393 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
>(&buffer[0]);
394 h5_int32_t *i32buffer =
reinterpret_cast<h5_int32_t*
>(&buffer[0]);
396 for(
size_t i = 0; i < numLocalParticles; ++ i)
397 f64buffer[i] = bunch->
R[i](0);
400 for(
size_t i = 0; i < numLocalParticles; ++ i)
401 f64buffer[i] = bunch->
R[i](1);
404 for(
size_t i = 0; i < numLocalParticles; ++ i)
405 f64buffer[i] = bunch->
R[i](2);
408 for(
size_t i = 0; i < numLocalParticles; ++ i)
409 f64buffer[i] = bunch->
P[i](0);
412 for(
size_t i = 0; i < numLocalParticles; ++ i)
413 f64buffer[i] = bunch->
P[i](1);
416 for(
size_t i = 0; i < numLocalParticles; ++ i)
417 f64buffer[i] = bunch->
P[i](2);
420 for(
size_t i = 0; i < numLocalParticles; ++ i)
421 f64buffer[i] = bunch->
Q[i];
424 for(
size_t i = 0; i < numLocalParticles; ++ i)
425 i64buffer[i] = bunch->
ID[i];
428 for(
size_t i = 0; i < numLocalParticles; ++ i)
429 i32buffer[i] = (h5_int32_t) bunch->
PType[i];
433 for(
size_t i = 0; i < numLocalParticles; ++ i)
434 f64buffer[i] = bunch->
Ef[i](0);
437 for(
size_t i = 0; i < numLocalParticles; ++ i)
438 f64buffer[i] = bunch->
Ef[i](1);
441 for(
size_t i = 0; i < numLocalParticles; ++ i)
442 f64buffer[i] = bunch->
Ef[i](2);
445 for(
size_t i = 0; i < numLocalParticles; ++ i)
446 f64buffer[i] = bunch->
Bf[i](0);
449 for(
size_t i = 0; i < numLocalParticles; ++ i)
450 f64buffer[i] = bunch->
Bf[i](1);
453 for(
size_t i = 0; i < numLocalParticles; ++ i)
454 f64buffer[i] = bunch->
Bf[i](2);
463 h5_err_t herr = H5Block3dSetView(
465 idx[0].
min(), idx[0].
max(),
466 idx[1].
min(), idx[1].
max(),
467 idx[2].
min(), idx[2].
max());
470 std::unique_ptr<h5_float64_t[]> data(
new h5_float64_t[(idx[0].
max() + 1) * (idx[1].
max() + 1) * (idx[2].
max() + 1)]);
476 for(
int i = idx[2].
min(); i <= idx[2].max(); ++ i) {
477 for(
int j = idx[1].
min(); j <= idx[1].max(); ++ j) {
478 for(
int k = idx[0].
min(); k <= idx[0].max(); ++ k) {
479 data[ii] = bunch->
getRho(k, j, i);
484 herr = H5Block3dWriteScalarFieldFloat64(
file_m,
"rho", data.get());
488 herr = H5Block3dSetFieldOrigin(
file_m,
"rho",
494 herr = H5Block3dSetFieldSpacing(
file_m,
"rho",
495 (h5_float64_t)bunch->
get_hr()(0),
496 (h5_float64_t)bunch->
get_hr()(1),
497 (h5_float64_t)bunch->
get_hr()(2));
ParticleAttrib< Vector_t > P
void open(h5_int32_t flags)
ParticleAttrib< Vector_t > Ef
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &elementName)
long long getLocalTrackStep() const
virtual void readHeader()
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
The base class for all OPAL exceptions.
Tps< T > sin(const Tps< T > &x)
Sine.
ParticleAttrib< double > Q
Vector_t get_rrms() const
double get_meanKineticEnergy() const
void setLocalTrackStep(long long n)
step in a TRACK command
#define WRITEDATA(type, file, name, value)
Vector_t get_emit() const
#define REPORTONERROR(rc)
void readStepData(PartBunchBase< double, 3 > *, h5_ssize_t, h5_ssize_t)
size_t getTotalNum() const
Vector_t get_prms() const
#define WRITESTRINGSTEPATTRIB(file, name, value)
virtual void writeHeader()
static OpalData * getInstance()
#define OPAL_PROJECT_NAME
void calcBeamParameters()
Vector_t get_pmean() const
Vector_t get_maxExtent() const
ParticleAttrib< short > PType
double getGlobalPhaseShift()
units: (sec)
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
constexpr double pi
The value of .
Quaternion getRotation() const
constexpr double c
The velocity of light in m/s.
H5PartWrapperForPT(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
void get_PBounds(Vector_t &min, Vector_t &max) const
CoordinateSystemTrafo toLabTrafo_m
Vector_t get_norm_emit() const
#define OPAL_PROJECT_VERSION
void readStepHeader(PartBunchBase< double, 3 > *)
static void reportOnError(h5_int64_t rc, const char *file, int line)
Vector_t get_origin() const
virtual FieldLayout_t & getFieldLayout()=0
size_t getLocalNum() const
#define WRITESTEPATTRIB(type, file, name, value, length)
Vector_t get_centroid() const
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)
void setGlobalPhaseShift(double shift)
units: (sec)
virtual Vector_t get_hr() const
Tps< T > cos(const Tps< T > &x)
Cosine.
virtual void readStep(PartBunchBase< double, 3 > *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)
virtual ~H5PartWrapperForPT()
Vector_t rotate(const Vector_t &) const
double getQ() const
Access to reference data.
ParticleAttrib< int > Bin
std::string getGitRevision()
#define WRITEFILEATTRIB(type, file, name, value, length)
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
ParticleAttrib< Vector_t > Bf
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &additionalStepAttributes)
Quaternion conjugate() const
virtual double getRho(int x, int y, int z)=0
#define READDATA(type, file, name, value)
size_t getNumParticles() const
void writeStepData(PartBunchBase< double, 3 > *)
NDIndex< Dim > getLocalNDIndex()
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
#define READFILEATTRIB(type, file, name, value)
Inform & endl(Inform &inf)
#define WRITESTRINGFILEATTRIB(file, name, value)
void setGlobalTrackStep(long long n)
step in multiple TRACK commands
void setRestartStep(int s)
store the location where to restart
long long getGlobalTrackStep() const
void writeStepHeader(PartBunchBase< double, 3 > *, const std::map< std::string, double > &)