29#include "h5core/h5_types.h"
40 const std::string& fileName,
int restartStep, std::string sourceFile, h5_int32_t flags)
42 if (restartStep == -1) {
43 restartStep = H5GetNumSteps(
file_m) - 1;
52 h5_int64_t numFileAttributes = H5GetNumFileAttribs(
file_m);
54 const h5_size_t lengthAttributeName = 256;
55 char attributeName[lengthAttributeName];
56 h5_int64_t attributeType;
57 h5_size_t numAttributeElements;
58 std::set<std::string> attributeNames;
60 for (h5_int64_t i = 0; i < numFileAttributes; ++i) {
62 file_m, i, attributeName, lengthAttributeName, &attributeType, &numAttributeElements));
64 attributeNames.insert(attributeName);
67 if (attributeNames.find(
"dump frequency") != attributeNames.end()) {
73 if (attributeNames.find(
"dPhiGlobal") != attributeNames.end()) {
79 if (attributeNames.find(
"nAutoPhaseCavities") != attributeNames.end()) {
82 h5_int64_t numAutoPhaseCavities = 0;
83 if (!H5HasFileAttrib(
file_m,
"nAutoPhaseCavities")
84 || H5ReadFileAttribInt64(
file_m,
"nAutoPhaseCavities", &numAutoPhaseCavities)
86 numAutoPhaseCavities = 0;
88 for (
long i = 0; i < numAutoPhaseCavities; ++i) {
89 std::string elementName =
"Cav-" + std::to_string(i + 1) +
"-name";
90 std::string elementPhase =
"Cav-" + std::to_string(i + 1) +
"-value";
96 opal->setMaxPhase(name, phase);
103 PartBunch_t* bunch, h5_ssize_t firstParticle, h5_ssize_t lastParticle) {
104 h5_ssize_t numStepsInSource = H5GetNumSteps(
file_m);
105 h5_ssize_t
readStep = numStepsInSource - 1;
115 bunch->
setT(actualT);
139 Quaternion rotTheta(std::cos(0.5 * TaitBryant[0]), 0, std::sin(0.5 * TaitBryant[0]), 0);
140 Quaternion rotPhi(std::cos(0.5 * TaitBryant[1]), std::sin(0.5 * TaitBryant[1]), 0, 0);
141 Quaternion rotPsi(std::cos(0.5 * TaitBryant[2]), 0, 0, std::sin(0.5 * TaitBryant[2]));
142 Quaternion rotation = rotTheta * (rotPhi * rotPsi);
148 PartBunch_t* bunch, h5_ssize_t firstParticle, h5_ssize_t lastParticle) {
150 if (lastParticle >= numParticles || firstParticle > lastParticle) {
152 "H5PartWrapperForPT::readStepData",
153 "the provided particle numbers don't match the number of particles in the file");
158 numParticles = lastParticle - firstParticle + 1;
160 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
162 h5_float64_t* f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
163 h5_int32_t* i32buffer =
reinterpret_cast<h5_int32_t*
>(buffer_ptr);
166 for (
long int n = 0; n < numParticles; ++n) {
172 for (
long int n = 0; n < numParticles; ++n) {
177 for (
long int n = 0; n < numParticles; ++n) {
182 for (
long int n = 0; n < numParticles; ++n) {
187 for (
long int n = 0; n < numParticles; ++n) {
192 for (
long int n = 0; n < numParticles; ++n) {
197 for (
long int n = 0; n < numParticles; ++n) {
202 for (
long int n = 0; n < numParticles; ++n) {
210 std::stringstream OPAL_version;
293 PartBunch_t* bunch,
const std::map<std::string, double>& additionalStepAttributes) {
298 open(H5_O_APPENDONLY);
306 PartBunch_t* bunch,
const std::map<std::string, double>& additionalStepAttributes) {
308 double t = bunch->
getT();
327 double energySpread = bunch->
getdE();
330 double sigma = ((xsigma[0] * xsigma[0]) + (xsigma[1] * xsigma[1]))
332 * (geomvareps[0] * geomvareps[0] + geomvareps[1] * geomvareps[1]));
340 h5_int64_t numBunch = 1;
341 h5_int64_t SteptoLastInj = 0;
349 char const* OPALFlavour =
"opal-t";
392 additionalStepAttributes.at(
"B-ref_x"), additionalStepAttributes.at(
"B-ref_z"),
393 additionalStepAttributes.at(
"B-ref_y"));
395 additionalStepAttributes.at(
"E-ref_x"), additionalStepAttributes.at(
"E-ref_z"),
396 additionalStepAttributes.at(
"E-ref_y"));
400 }
catch (std::out_of_range& m) {
404 "H5PartWrapperForPC::writeStepHeader",
"some additional step attribute not found");
415 auto rView = Kokkos::create_mirror_view(rViewDevice);
416 Kokkos::deep_copy(rView,rViewDevice);
419 std::vector<char> buffer(numLocalParticles *
sizeof(h5_float64_t));
421 h5_float64_t* f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
423 h5_int32_t* i32buffer =
reinterpret_cast<h5_int32_t*
>(buffer_ptr);
425 for (
size_t i = 0; i < numLocalParticles; ++i)
426 f64buffer[i] = rView(i)(0);
429 for (
size_t i = 0; i < numLocalParticles; ++i)
430 f64buffer[i] = rView(i)(1);
433 for (
size_t i = 0; i < numLocalParticles; ++i)
434 f64buffer[i] = rView(i)(1);
438 auto pView = Kokkos::create_mirror_view(pViewDevice);
439 Kokkos::deep_copy(pView,pViewDevice);
441 for (
long unsigned i = 0; i < numLocalParticles; i++)
442 f64buffer[i] = pView(i)(0);
445 for (
size_t i = 0; i < numLocalParticles; ++i)
446 f64buffer[i] = pView(i)(1);
449 for (
size_t i = 0; i < numLocalParticles; ++i)
450 f64buffer[i] = pView(i)(2);
454 auto qView = Kokkos::create_mirror_view(qViewDevice);
455 Kokkos::deep_copy(qView,qViewDevice);
457 for (
size_t i = 0; i < numLocalParticles; ++i)
458 f64buffer[i] = qView(i);
474 auto binView = Kokkos::create_mirror_view(binViewDevice);
475 Kokkos::deep_copy(binView,binViewDevice);
477 for (
size_t i = 0; i < numLocalParticles; ++i)
478 i32buffer[i] = binView(i);
482 auto spView = Kokkos::create_mirror_view(spViewDevice);
483 Kokkos::deep_copy(spView,spViewDevice);
486 for (
size_t i = 0; i < numLocalParticles; ++i)
487 i32buffer[i] = spView(i);
493 auto EView = Kokkos::create_mirror_view(EViewDevice);
494 Kokkos::deep_copy(EView,EViewDevice);
496 for (
size_t i = 0; i < numLocalParticles; ++i)
497 f64buffer[i] = EView(i)(0);
500 for (
size_t i = 0; i < numLocalParticles; ++i)
501 f64buffer[i] = EView(i)(1);
504 for (
size_t i = 0; i < numLocalParticles; ++i)
505 f64buffer[i] = EView(i)(2);
509 auto BView = Kokkos::create_mirror_view(BViewDevice);
510 Kokkos::deep_copy(BView,BViewDevice);
512 for (
size_t i = 0; i < numLocalParticles; ++i)
513 f64buffer[i] = BView(i)(0);
516 for (
size_t i = 0; i < numLocalParticles; ++i)
517 f64buffer[i] = BView(i)(1);
520 for (
size_t i = 0; i < numLocalParticles; ++i)
521 f64buffer[i] = BView(i)(2);
#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)
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.
T * c_data(std::vector< T, A > &v)
std::string getGitRevision()
std::unique_ptr< Inform > Error
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
Vector_t< T, Dim > get_prms() const
void setLocalTrackStep(long long n)
step in a TRACK command
void calcBeamParameters()
Vector_t< T, Dim > get_maxExtent() const
Vector_t< T, Dim > get_pmean() const
double getQ() const
Access to reference data.
double getCharge() const
get the total charge per simulation particle
Vector_t< T, Dim > get_rrms() const
Vector_t< T, Dim > get_origin() const
Vector_t< T, Dim > RefPartR_m
Reference particle structures.
std::shared_ptr< ParticleContainer_t > getParticleContainer()
double get_meanKineticEnergy()
long long getLocalTrackStep() const
void set_sPos(double s)
get the spos of the primary beam
size_t getLocalNum() const
Vector_t< T, Dim > get_emit() const
Vector_t< T, Dim > get_centroid() const
void setGlobalTrackStep(long long n)
step in multiple TRACK commands
long long getGlobalTrackStep() const
size_t getTotalNum() const
Vector_t< T, Dim > RefPartP_m
Vector_t< T, Dim > get_norm_emit() const
size_t getNumParticles() const
void open(h5_int32_t flags)
virtual ~H5PartWrapperForPT()
virtual void readStep(PartBunch_t *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)
virtual void writeStep(PartBunch_t *, const std::map< std::string, double > &additionalStepAttributes)
virtual void writeHeader()
H5PartWrapperForPT(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
void readStepData(PartBunch_t *, h5_ssize_t, h5_ssize_t)
void readStepHeader(PartBunch_t *)
void writeStepHeader(PartBunch_t *, const std::map< std::string, double > &)
virtual void readHeader()
void writeStepData(PartBunch_t *)
The base class for all OPAL exceptions.