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);
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) {
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) {
401 *ippl::Error << m.what() << endl;
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);
527 if (Options::rhoDump) {
528 NDIndex<3> idx = bunch->getFieldLayout().getLocalNDIndex();
530 h5_err_t herr = H5Block3dSetView(
531 file_m, idx[0].min(), idx[0].max(), idx[1].min(), idx[1].max(), idx[2].min(),
533 reportOnError(herr, __FILE__, __LINE__);
535 std::unique_ptr<h5_float64_t[]> data(
536 new h5_float64_t[(idx[0].max() + 1) * (idx[1].max() + 1) * (idx[2].max() + 1)]);
539 // h5block uses the fortran convention of storing data:
540 // INTEGER, DIMENSION(2,3) :: a
541 // => {a(1,1), a(2,1), a(1,2), a(2,2), a(1,3), a(2,3)}
542 for (int i = idx[2].min(); i <= idx[2].max(); ++i) {
543 for (int j = idx[1].min(); j <= idx[1].max(); ++j) {
544 for (int k = idx[0].min(); k <= idx[0].max(); ++k) {
545 data[ii] = bunch->getRho(k, j, i);
550 herr = H5Block3dWriteScalarFieldFloat64(file_m, "rho", data.get());
551 reportOnError(herr, __FILE__, __LINE__);
554 herr = H5Block3dSetFieldOrigin(
555 file_m, "rho", (h5_float64_t)bunch->get_origin()(0),
556 (h5_float64_t)bunch->get_origin()(1), (h5_float64_t)bunch->get_origin()(2));
557 reportOnError(herr, __FILE__, __LINE__);
559 herr = H5Block3dSetFieldSpacing(
560 file_m, "rho", (h5_float64_t)bunch->get_hr()(0), (h5_float64_t)bunch->get_hr()(1),
561 (h5_float64_t)bunch->get_hr()(2));
562 reportOnError(herr, __FILE__, __LINE__);