28 #include "h5core/h5_types.h"
41 if (restartStep == -1) {
42 restartStep = H5GetNumSteps(
file_m) - 1 ;
51 h5_int64_t numFileAttributes = H5GetNumFileAttribs(
file_m);
53 const h5_size_t lengthAttributeName = 256;
54 char attributeName[lengthAttributeName];
55 h5_int64_t attributeType;
56 h5_size_t numAttributeElements;
57 std::set<std::string> attributeNames;
59 for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
65 &numAttributeElements));
67 attributeNames.insert(attributeName);
70 if (attributeNames.find(
"dump frequency") != attributeNames.end()) {
76 if (attributeNames.find(
"dPhiGlobal") != attributeNames.end()) {
82 if (attributeNames.find(
"nAutoPhaseCavities") != attributeNames.end()) {
85 h5_int64_t numAutoPhaseCavities = 0;
86 if (!H5HasFileAttrib(
file_m,
"nAutoPhaseCavities") ||
87 H5ReadFileAttribInt64(
file_m,
"nAutoPhaseCavities", &numAutoPhaseCavities) != H5_SUCCESS) {
88 numAutoPhaseCavities = 0;
90 for (
long i = 0; i < numAutoPhaseCavities; ++ i) {
91 std::string elementName =
"Cav-" + std::to_string(i + 1) +
"-name";
92 std::string elementPhase =
"Cav-" + std::to_string(i + 1) +
"-value";
98 opal->setMaxPhase(
name, phase);
105 h5_ssize_t numStepsInSource = H5GetNumSteps(
file_m);
106 h5_ssize_t
readStep = numStepsInSource - 1;
116 bunch->
setT(actualT);
143 Quaternion rotation = rotTheta * (rotPhi * rotPsi);
149 if (lastParticle >= numParticles || firstParticle > lastParticle) {
151 "the provided particle numbers don't match the number of particles in the file");
156 numParticles = lastParticle - firstParticle + 1;
158 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
160 h5_float64_t* f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
161 h5_int32_t* i32buffer =
reinterpret_cast<h5_int32_t*
>(buffer_ptr);
164 for (
long int n = 0;
n < numParticles; ++
n) {
165 bunch->
R[
n](0) = f64buffer[
n];
170 for (
long int n = 0;
n < numParticles; ++
n) {
171 bunch->
R[
n](1) = f64buffer[
n];
175 for (
long int n = 0;
n < numParticles; ++
n) {
176 bunch->
R[
n](2) = f64buffer[
n];
180 for (
long int n = 0;
n < numParticles; ++
n) {
181 bunch->
P[
n](0) = f64buffer[
n];
185 for (
long int n = 0;
n < numParticles; ++
n) {
186 bunch->
P[
n](1) = f64buffer[
n];
190 for (
long int n = 0;
n < numParticles; ++
n) {
191 bunch->
P[
n](2) = f64buffer[
n];
195 for (
long int n = 0;
n < numParticles; ++
n) {
196 bunch->
Q[
n] = f64buffer[
n];
200 for (
long int n = 0;
n < numParticles; ++
n) {
201 bunch->
ID[
n] = i32buffer[
n];
208 std::stringstream OPAL_version;
293 open(H5_O_APPENDONLY);
302 double t = bunch->
getT();
320 double energySpread = bunch->
getdE();
322 double sigma = ((xsigma[0] * xsigma[0]) + (xsigma[1] * xsigma[1])) /
323 (2.0 * bunch->
get_gamma() * I_0 * (geomvareps[0] * geomvareps[0] + geomvareps[1] * geomvareps[1]));
328 double mass = 1.0e-9 * bunch->
getM();
331 h5_int64_t numBunch = 1;
332 h5_int64_t SteptoLastInj = 0;
340 char const* OPALFlavour =
"opal-t";
382 Vector_t referenceB(additionalStepAttributes.at(
"B-ref_x"),
383 additionalStepAttributes.at(
"B-ref_z"),
384 additionalStepAttributes.at(
"B-ref_y"));
385 Vector_t referenceE(additionalStepAttributes.at(
"E-ref_x"),
386 additionalStepAttributes.at(
"E-ref_z"),
387 additionalStepAttributes.at(
"E-ref_y"));
391 }
catch (std::out_of_range & m) {
395 "some additional step attribute not found");
406 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
408 h5_float64_t* f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
409 h5_int64_t* i64buffer =
reinterpret_cast<h5_int64_t*
>(buffer_ptr);
410 h5_int32_t* i32buffer =
reinterpret_cast<h5_int32_t*
>(buffer_ptr);
412 for (
size_t i = 0; i < numLocalParticles; ++ i)
413 f64buffer[i] = bunch->
R[i](0);
416 for (
size_t i = 0; i < numLocalParticles; ++ i)
417 f64buffer[i] = bunch->
R[i](1);
420 for (
size_t i = 0; i < numLocalParticles; ++ i)
421 f64buffer[i] = bunch->
R[i](2);
424 for (
size_t i = 0; i < numLocalParticles; ++ i)
425 f64buffer[i] = bunch->
P[i](0);
428 for (
size_t i = 0; i < numLocalParticles; ++ i)
429 f64buffer[i] = bunch->
P[i](1);
432 for (
size_t i = 0; i < numLocalParticles; ++ i)
433 f64buffer[i] = bunch->
P[i](2);
436 for (
size_t i = 0; i < numLocalParticles; ++ i)
437 f64buffer[i] = bunch->
Q[i];
440 for (
size_t i = 0; i < numLocalParticles; ++ i)
441 i64buffer[i] = bunch->
ID[i];
444 for (
size_t i = 0; i < numLocalParticles; ++ i)
445 i32buffer[i] = (h5_int32_t) bunch->
PType[i];
448 for (
size_t i = 0; i < numLocalParticles; ++ i)
449 i32buffer[i] = (h5_int32_t) bunch->
POrigin[i];
453 for (
size_t i = 0; i < numLocalParticles; ++ i)
454 f64buffer[i] = bunch->
Ef[i](0);
457 for (
size_t i = 0; i < numLocalParticles; ++ i)
458 f64buffer[i] = bunch->
Ef[i](1);
461 for (
size_t i = 0; i < numLocalParticles; ++ i)
462 f64buffer[i] = bunch->
Ef[i](2);
465 for (
size_t i = 0; i < numLocalParticles; ++ i)
466 f64buffer[i] = bunch->
Bf[i](0);
469 for (
size_t i = 0; i < numLocalParticles; ++ i)
470 f64buffer[i] = bunch->
Bf[i](1);
473 for (
size_t i = 0; i < numLocalParticles; ++ i)
474 f64buffer[i] = bunch->
Bf[i](2);
483 h5_err_t herr = H5Block3dSetView(
485 idx[0].
min(), idx[0].
max(),
486 idx[1].
min(), idx[1].
max(),
487 idx[2].
min(), idx[2].
max());
490 std::unique_ptr<h5_float64_t[]> data(
new h5_float64_t[(idx[0].
max() + 1) * (idx[1].
max() + 1) * (idx[2].
max() + 1)]);
496 for (
int i = idx[2].
min(); i <= idx[2].max(); ++ i) {
497 for (
int j = idx[1].
min(); j <= idx[1].max(); ++ j) {
498 for (
int k = idx[0].
min(); k <= idx[0].max(); ++ k) {
499 data[ii] = bunch->
getRho(k, j, i);
504 herr = H5Block3dWriteScalarFieldFloat64(
file_m,
"rho", data.get());
508 herr = H5Block3dSetFieldOrigin(
file_m,
"rho",
514 herr = H5Block3dSetFieldSpacing(
file_m,
"rho",
515 (h5_float64_t)bunch->
get_hr()(0),
516 (h5_float64_t)bunch->
get_hr()(1),
517 (h5_float64_t)bunch->
get_hr()(2));
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > sin(const Tps< T > &x)
Sine.
#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 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.
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &)
T * c_data(std::vector< T, A > &v)
std::string getGitRevision()
ParticleAttrib< Vector_t > Ef
double get_meanKineticEnergy() const
ParticleAttrib< int > Bin
double getQ() const
Access to reference data.
size_t getLocalNum() const
void setLocalTrackStep(long long n)
step in a TRACK command
size_t getTotalNum() const
ParticleAttrib< Vector_t > P
ParticleAttrib< ParticleType > PType
ParticleAttrib< ParticleOrigin > POrigin
Vector_t get_rrms() const
ParticleAttrib< double > Q
void calcBeamParameters()
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
CoordinateSystemTrafo toLabTrafo_m
long long getLocalTrackStep() 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
Vector_t get_pmean() const
ParticleAttrib< Vector_t > Bf
long long getGlobalTrackStep() const
virtual Vector_t get_hr() const
Vector_t get_emit() const
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
double getGlobalPhaseShift()
units: (sec)
void setGlobalPhaseShift(double shift)
units: (sec)
static OpalData * getInstance()
void setRestartStep(int s)
store the location where to restart
Quaternion getRotation() const
Vector_t rotate(const Vector_t &) const
Quaternion conjugate() const
size_t getNumParticles() const
void open(h5_int32_t flags)
static void reportOnError(h5_int64_t rc, const char *file, int line)
virtual ~H5PartWrapperForPT()
void writeStepData(PartBunchBase< double, 3 > *)
void readStepHeader(PartBunchBase< double, 3 > *)
virtual void writeHeader()
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &additionalStepAttributes)
void readStepData(PartBunchBase< double, 3 > *, h5_ssize_t, h5_ssize_t)
H5PartWrapperForPT(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
virtual void readHeader()
virtual void readStep(PartBunchBase< double, 3 > *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)
void writeStepHeader(PartBunchBase< double, 3 > *, const std::map< std::string, double > &)
The base class for all OPAL exceptions.
NDIndex< Dim > getLocalNDIndex()