18#ifndef PART_BUNCH_BASE_HPP
19#define PART_BUNCH_BASE_HPP
44template <
class T,
unsigned Dim>
54 stateOfLastBoundP_(unitless),
58 globalMeanR_m(
Vector_t({0.0, 0.0, 0.0})),
59 globalToLocalQuaternion_m(
Quaternion_t(1.0, 0.0, 0.0, 0.0)),
66 couplingConstant_m(0.0),
68 massPerParticle_m(0.0),
73 binemitted_m(
nullptr),
81 globalPartPerNode_m(
nullptr),
94template <
class T,
unsigned Dim>
96 if (dist_m !=
nullptr) {
97 size_t isBeamEmitted = dist_m->getIfDistEmitting();
99 if (isBeamEmitted > 0)
108template <
class T,
unsigned Dim>
113 int lastEmittedBin = dist_m->getLastEmittedEnergyBin();
115 return lastEmittedBin;
119template <
class T,
unsigned Dim>
121 return dist_m->getNumberOfEmissionSteps();
125template <
class T,
unsigned Dim>
127 return dist_m->getNumberOfEnergyBins();
131template <
class T,
unsigned Dim>
134 size_t isBeamEmitting = dist_m->getIfDistEmitting();
136 if (isBeamEmitting > 0) {
137 *
gmsg <<
"*****************************************************" <<
endl
138 <<
"Warning: attempted to rebin, but not all distribution" <<
endl
139 <<
"particles have been emitted. Rebin failed." <<
endl
140 <<
"*****************************************************" <<
endl;
148template <
class T,
unsigned Dim>
150 bingamma_m = std::unique_ptr<double[]>(
new double[numberOfEnergyBins]);
151 binemitted_m = std::unique_ptr<size_t[]>(
new size_t[numberOfEnergyBins]);
152 for (
int i = 0; i < numberOfEnergyBins; i++)
157template <
class T,
unsigned Dim>
160 if (dist_m !=
nullptr)
161 return dist_m->getNumberOfEnergyBins() > 0;
167template <
class T,
unsigned Dim>
170 if (unit_state_ == unitless)
172 "Cannot make a unitless PartBunch unitless");
174 bool hasToReset =
false;
175 if (!R.isDirty()) hasToReset =
true;
177 for (
size_t i = 0; i < getLocalNum(); i++) {
179 if (use_dt_per_particle)
185 unit_state_ = unitless;
187 if (hasToReset) R.resetDirtyFlag();
191template <
class T,
unsigned Dim>
194 if (unit_state_ == units)
196 "Cannot apply units twice to PartBunch");
198 bool hasToReset =
false;
199 if (!R.isDirty()) hasToReset =
true;
201 for (
size_t i = 0; i < getLocalNum(); i++) {
203 if (use_dt_per_particle)
211 if (hasToReset) R.resetDirtyFlag();
215template <
class T,
unsigned Dim>
221template <
class T,
unsigned Dim>
223 std::vector<Distribution*> addedDistributions,
225 Inform m(
"setDistribution " );
235template <
class T,
unsigned Dim>
237 size_t numberOfParticles,
245template <
class T,
unsigned Dim>
251template <
class T,
unsigned Dim>
253 return (pbin_m !=
nullptr);
257template <
class T,
unsigned Dim>
263template <
class T,
unsigned Dim>
269template <
class T,
unsigned Dim>
271 if (dist_m !=
nullptr)
272 return dist_m->getIfDistEmitting();
278template <
class T,
unsigned Dim>
280 if (pbin_m !=
nullptr)
281 return pbin_m->weHaveBins();
287template <
class T,
unsigned Dim>
291 setEnergyBins(pbin_m->getNBins());
295template <
class T,
unsigned Dim>
298 setEnergyBins(pbin_m->getNBins());
302template <
class T,
unsigned Dim>
304 return dist_m->emitParticles(
this, eZ);
308template <
class T,
unsigned Dim>
310 size_t numParticles = getLocalNum();
312 setTotalNum(numParticles);
316template <
class T,
unsigned Dim>
325template <
class T,
unsigned Dim>
327 if (pbin_m !=
nullptr)
328 return pbin_m->getLastemittedBin();
334template <
class T,
unsigned Dim>
336 if (pbin_m !=
nullptr) {
337 pbin_m->setPartNum(bin, num);
342template <
class T,
unsigned Dim>
345 const int emittedBins = dist_m->getNumberOfEnergyBins();
349 for (
int i = 0; i < emittedBins; i++)
352 for (
unsigned int n = 0; n < getLocalNum(); n++)
353 bingamma_m[this->Bin[n]] += std::sqrt(1.0 +
dot(this->P[n], this->P[n]));
355 std::unique_ptr<size_t[]> particlesInBin(
new size_t[emittedBins]);
356 reduce(bingamma_m.get(), bingamma_m.get() + emittedBins, bingamma_m.get(),
OpAddAssign());
357 reduce(binemitted_m.get(), binemitted_m.get() + emittedBins, particlesInBin.get(),
OpAddAssign());
358 for (
int i = 0; i < emittedBins; i++) {
359 size_t &pInBin = particlesInBin[i];
361 bingamma_m[i] /= pInBin;
363 <<
" gamma = " << std::setw(8) << std::scientific
364 << std::setprecision(5) << bingamma_m[i]
365 <<
"; NpInBin= " << std::setw(8)
366 << std::setfill(
' ') << pInBin << endl);
373 particlesInBin.reset();
377 ERRORMSG(
"sum(Bins)= " << s <<
" != sum(R)= " << getTotalNum() << endl;);
379 if (emittedBins >= 2) {
380 for (
int i = 1; i < emittedBins; i++) {
381 if (binemitted_m[i - 1] != 0 && binemitted_m[i] != 0)
382 INFOMSG(
level2 <<
"d(gamma)= " << 100.0 * std::abs(bingamma_m[i - 1] - bingamma_m[i]) / bingamma_m[i] <<
" [%] "
383 <<
"between bin " << i - 1 <<
" and " << i <<
endl);
389template <
class T,
unsigned Dim>
392 const int emittedBins = pbin_m->getLastemittedBin();
394 for (
int i = 0; i < emittedBins; i++)
396 for (
unsigned int n = 0; n < getLocalNum(); n++) {
397 if ( this->Bin[n] > -1 ) {
398 bingamma_m[this->Bin[n]] += std::sqrt(1.0 +
dot(this->P[n], this->P[n]));
402 allreduce(*bingamma_m.get(), emittedBins, std::plus<double>());
404 for (
int i = 0; i < emittedBins; i++) {
405 if (pbin_m->getTotalNumPerBin(i) > 0) {
406 bingamma_m[i] /= pbin_m->getTotalNumPerBin(i);
410 INFOMSG(
"Bin " << i <<
" : particle number = " << pbin_m->getTotalNumPerBin(i)
411 <<
" gamma = " << bingamma_m[i] << endl);
416template <
class T,
unsigned Dim>
418 momentsComputer_m.computeDebyeLength(*
this, rmsDensity_m);
423template <
class T,
unsigned Dim>
425 return bingamma_m[bin];
429template <
class T,
unsigned Dim>
431 this->Q =
where(
eq(this->Bin, bin), q, 0.0);
435template <
class T,
unsigned Dim>
437 this->Q =
where(
eq(this->Bin, bin), this->qi_m, 0.0);
441template <
class T,
unsigned Dim>
444 std::size_t localnum = 0;
447 for (
unsigned long k = 0; k < getLocalNum(); ++ k)
448 if (std::abs(R[k](0) - meanR(0)) > x(0) ||
449 std::abs(R[k](1) - meanR(1)) > x(1) ||
450 std::abs(R[k](2) - meanR(2)) > x(2)) {
455 gather(&localnum, &globalPartPerNode_m[0], 1);
457 size_t npOutside = std::accumulate(globalPartPerNode_m.get(),
459 std::plus<size_t>());
474template <
class T,
unsigned Dim>
476 std::vector<double>& lineDensity,
477 std::pair<double, double>& meshInfo) {
479 get_bounds(rmin, rmax);
483 this->updateDomainLength(grid);
487 double length = rmax(2) - rmin(2);
488 double zmin = rmin(2) - dh_m * length, zmax = rmax(2) + dh_m * length;
489 double hz = (zmax - zmin) / (nBins - 2);
490 double perMeter = 1.0 / hz;
493 lineDensity.resize(nBins, 0.0);
494 std::fill(lineDensity.begin(), lineDensity.end(), 0.0);
496 const unsigned int lN = getLocalNum();
497 for (
unsigned int i = 0; i < lN; ++ i) {
498 const double z = R[i](2) - 0.5 * hz;
499 unsigned int idx = (z - zmin) / hz;
500 double tau = (z - zmin) / hz - idx;
502 lineDensity[idx] += Q[i] * (1.0 - tau) * perMeter;
503 lineDensity[idx + 1] += Q[i] * tau * perMeter;
508 meshInfo.first = zmin;
509 meshInfo.second = hz;
513template <
class T,
unsigned Dim>
521 if ( !(R.isDirty() || ID.isDirty() ) && stateOfLastBoundP_ == unit_state_)
return;
523 stateOfLastBoundP_ = unit_state_;
525 if (!isGridFixed()) {
526 const int dimIdx = (dcBeam_m? 2: 3);
534 this->updateDomainLength(nr_m);
536 getSolverMeshBounds(rmin_m, rmax_m);
541 for (
int i = 0; i < dimIdx; i++) {
542 double length = std::abs(rmax_m[i] - rmin_m[i]);
543 if (length < 1e-10) {
547 rmax_m[i] += dh_m * length;
548 rmin_m[i] -= dh_m * length;
550 hr_m[i] = (rmax_m[i] - rmin_m[i]) / (nr_m[i] - 1);
553 rmax_m[2] = rmin_m[2] + periodLength_m;
554 hr_m[2] = periodLength_m / (nr_m[2] - 1);
556 for (
int i = 0; i < dimIdx; ++ i) {
557 volume *= std::abs(rmax_m[i] - rmin_m[i]);
560 if (getIfBeamEmitting() && dist_m !=
nullptr) {
562 double percent = std::max(1.0 / (nr_m[2] - 1), dist_m->getPercentageEmitted());
563 double length = std::abs(rmax_m[2] - rmin_m[2]) / (1.0 + 2 * dh_m);
564 if (percent < 1.0 && percent > 0.0) {
565 rmax_m[2] -= dh_m * length;
566 rmin_m[2] = rmax_m[2] - length / percent;
570 rmax_m[2] += dh_m * length;
571 rmin_m[2] -= dh_m * length;
573 hr_m[2] = (rmax_m[2] - rmin_m[2]) / (nr_m[2] - 1);
577 if (volume < 1e-21 && getTotalNum() > 1 && std::abs(
sum(Q)) > 0.0) {
582 if (hr_m[0] * hr_m[1] * hr_m[2] <= 0) {
588 scMeshMin_m = rmin_m;
589 scMeshMax_m = rmax_m;
592 Vector_t origin = rmin_m -
Vector_t({hr_m[0] / 2.0, hr_m[1] / 2.0, hr_m[2] / 2.0});
593 this->updateFields(hr_m, origin);
600 double gammaz =
sum(this->P)[2] / getTotalNum();
602 gammaz = std::sqrt(gammaz + 1.0);
620template <
class T,
unsigned Dim>
624 const int dimIdx = 3;
627 std::unique_ptr<size_t[]> countLost;
629 const int tempN = pbin_m->getLastemittedBin();
630 countLost = std::unique_ptr<size_t[]>(
new size_t[tempN]);
631 for (
int ii = 0; ii < tempN; ii++) countLost[ii] = 0;
634 this->updateDomainLength(nr_m);
637 get_bounds(rmin_m, rmax_m);
640 len = rmax_m - rmin_m;
642 calcBeamParameters();
645 if (checkfactor != 0) {
648 Vector_t rmean = momentsComputer_m.getMeanPosition();
649 Vector_t rrms = momentsComputer_m.getStandardDeviationPosition();
650 if(checkfactor < 0) {
652 if (len[0] > checkfactor * rrms[0] ||
653 len[1] > checkfactor * rrms[1] ||
654 len[2] > checkfactor * rrms[2])
656 for(
unsigned int ii = 0; ii < this->getLocalNum(); ii++) {
660 if (std::abs(R[ii](0) - rmean(0)) > checkfactor * rrms[0] ||
661 std::abs(R[ii](1) - rmean(1)) > checkfactor * rrms[1] ||
662 std::abs(R[ii](2) - rmean(2)) > checkfactor * rrms[2])
668 countLost[Bin[ii]] += 1 ;
681 if (len[0] > checkfactor * rrms[0] ||
682 len[2] > checkfactor * rrms[2])
684 for(
unsigned int ii = 0; ii < this->getLocalNum(); ii++) {
688 if (std::abs(R[ii](0) - rmean(0)) > checkfactor * rrms[0] ||
689 std::abs(R[ii](2) - rmean(2)) > checkfactor * rrms[2])
695 countLost[Bin[ii]] += 1 ;
714 getSolverMeshBounds(rmin_m, rmax_m);
718 for (
int i = 0; i < dimIdx; i++) {
719 double length = std::abs(rmax_m[i] - rmin_m[i]);
720 if (length < 1e-10) {
724 rmax_m[i] += dh_m * length;
725 rmin_m[i] -= dh_m * length;
727 hr_m[i] = (rmax_m[i] - rmin_m[i]) / (nr_m[i] - 1);
732 scMeshMin_m = rmin_m;
733 scMeshMax_m = rmax_m;
740 Vector_t origin = rmin_m -
Vector_t({hr_m[0] / 2.0, hr_m[1] / 2.0, hr_m[2] / 2.0});
741 this->updateFields(hr_m, origin);
744 pbin_m->updatePartInBin_cyc(countLost.get());
760 countTotalNumPerBunch();
766template <
class T,
unsigned Dim>
769 this->updateDomainLength(nr_m);
771 std::vector<size_t> tmpbinemitted;
776 const size_t localNum = getLocalNum();
778 double rzmean = momentsComputer_m.getMeanPosition()(2);
779 double rzrms = momentsComputer_m.getStandardDeviationPosition()(2);
780 const bool haveEnergyBins = weHaveEnergyBins();
781 if (haveEnergyBins) {
782 tmpbinemitted.resize(getNumberOfEnergyBins(), 0.0);
784 for (
unsigned int i = 0; i < localNum; i++) {
788 }
else if (haveEnergyBins) {
789 tmpbinemitted[Bin[i]]++;
795 calcBeamParameters();
796 gatherLoadBalanceStatistics();
798 if (haveEnergyBins) {
799 const int lastBin = dist_m->getLastEmittedEnergyBin();
800 for (
int i = 0; i < lastBin; i++) {
801 binemitted_m[i] = tmpbinemitted[i];
809template <
class T,
unsigned Dim>
812 std::unique_ptr<size_t[]> tmpbinemitted;
814 const size_t localNum = getLocalNum();
815 const size_t totalNum = getTotalNum();
818 if (weHaveEnergyBins()) {
819 tmpbinemitted = std::unique_ptr<size_t[]>(
new size_t[getNumberOfEnergyBins()]);
820 for (
int i = 0; i < getNumberOfEnergyBins(); i++) {
821 tmpbinemitted[i] = 0;
823 for (
unsigned int i = 0; i < localNum; i++) {
828 tmpbinemitted[Bin[i]]++;
832 for (
size_t i = 0; i < localNum; i++) {
841 performDestroy(
true);
844 calcBeamParameters();
845 gatherLoadBalanceStatistics();
847 if (weHaveEnergyBins()) {
848 const int lastBin = dist_m->getLastEmittedEnergyBin();
849 for (
int i = 0; i < lastBin; i++) {
850 binemitted_m[i] = tmpbinemitted[i];
853 size_t newTotalNum = getLocalNum();
856 setTotalNum(newTotalNum);
858 return totalNum - newTotalNum;
862template <
class T,
unsigned Dim>
867template <
class T,
unsigned Dim>
872template <
class T,
unsigned Dim>
877template <
class T,
unsigned Dim>
882template <
class T,
unsigned Dim>
888template <
class T,
unsigned Dim>
890 return this->R[i](0);
894template <
class T,
unsigned Dim>
896 return this->R[i](1);
900template <
class T,
unsigned Dim>
902 return this->R[i](2);
906template <
class T,
unsigned Dim>
912template <
class T,
unsigned Dim>
918template <
class T,
unsigned Dim>
923template <
class T,
unsigned Dim>
926 this->getLocalBounds(rmin, rmax);
930 for (
unsigned int i = 0; i <
Dim; ++i) {
932 min[2*i + 1] = -rmax[i];
937 for (
unsigned int i = 0; i <
Dim; ++i) {
939 rmax[i] = -
min[2*i + 1];
944template <
class T,
unsigned Dim>
946 const size_t localNum = getLocalNum();
948 double maxValue = 1e8;
949 rmin =
Vector_t({maxValue, maxValue, maxValue});
950 rmax =
Vector_t({-maxValue, -maxValue, -maxValue});
956 for (
size_t i = 1; i < localNum; ++ i) {
957 for (
unsigned short d = 0; d < 3u; ++ d) {
958 if (rmin(d) > R[i](d)) rmin(d) = R[i](d);
959 else if (rmax(d) < R[i](d)) rmax(d) = R[i](d);
965template <
class T,
unsigned Dim>
968 get_bounds(rmin, rmax);
970 std::pair<Vector_t, double> sphere;
971 sphere.first = 0.5 * (rmin + rmax);
972 sphere.second = std::sqrt(
dot(rmax - sphere.first, rmax - sphere.first));
978template <
class T,
unsigned Dim>
981 getLocalBounds(rmin, rmax);
983 std::pair<Vector_t, double> sphere;
984 sphere.first = 0.5 * (rmin + rmax);
985 sphere.second = std::sqrt(
dot(rmax - sphere.first, rmax - sphere.first));
991template <
class T,
unsigned Dim>
995 size_t i = getLocalNum();
998 R[i] = particle.
getR();
999 P[i] = particle.
getP();
1002 msg <<
"Created one particle i= " << i <<
endl;
1006template <
class T,
unsigned Dim>
1017template <
class T,
unsigned Dim>
1019 R[ii] = particle.
getR();
1020 P[ii] = particle.
getP();
1024template <
class T,
unsigned Dim>
1027 Vector_t({R[ii](0), R[ii](1), 0}), P[ii],
1028 R[ii](2), Q[ii], M[ii]);
1033template <
class T,
unsigned Dim>
1035 double& axmax,
double& aymax) {
1036 axmax = aymax = 0.0;
1039 for (
unsigned int ii = 0; ii < getLocalNum(); ii++) {
1041 particle = getParticle(ii);
1060 axmax = std::max(axmax, (std::pow(result[0], 2) + std::pow(result[1], 2)));
1061 aymax = std::max(aymax, (std::pow(result[2], 2) + std::pow(result[3], 2)));
1066template <
class T,
unsigned Dim>
1072template <
class T,
unsigned Dim>
1078template <
class T,
unsigned Dim>
1084template <
class T,
unsigned Dim>
1090template <
class T,
unsigned Dim>
1096template <
class T,
unsigned Dim>
1102template <
class T,
unsigned Dim>
1108template <
class T,
unsigned Dim>
1110 return momentsComputer_m.getMeanGamma();
1114template <
class T,
unsigned Dim>
1116 return momentsComputer_m.getMeanKineticEnergy();
1120template <
class T,
unsigned Dim>
1122 return momentsComputer_m.getTemperature();
1125template <
class T,
unsigned Dim>
1127 return momentsComputer_m.getDebyeLength();
1130template <
class T,
unsigned Dim>
1132 return momentsComputer_m.getPlasmaParameter();
1135template <
class T,
unsigned Dim>
1137 return rmsDensity_m;
1140template <
class T,
unsigned Dim>
1146template <
class T,
unsigned Dim>
1152template <
class T,
unsigned Dim>
1154 return momentsComputer_m.getMeanPosition();
1158template <
class T,
unsigned Dim>
1160 return momentsComputer_m.getStandardDeviationPosition();
1164template <
class T,
unsigned Dim>
1166 return momentsComputer_m.getStandardDeviationRP();
1170template <
class T,
unsigned Dim>
1172 return momentsComputer_m.getMeanPosition();
1176template <
class T,
unsigned Dim>
1178 return momentsComputer_m.getStandardDeviationMomentum();
1182template <
class T,
unsigned Dim>
1184 return momentsComputer_m.getMeanMomentum();
1188template <
class T,
unsigned Dim>
1191 return dist_m->get_pmean();
1193 double gamma = 0.1 / getM() + 1;
1194 return Vector_t({0, 0, std::sqrt(std::pow(gamma, 2) - 1)});
1198template <
class T,
unsigned Dim>
1200 return momentsComputer_m.getGeometricEmittance();
1204template <
class T,
unsigned Dim>
1206 return momentsComputer_m.getNormalizedEmittance();
1210template <
class T,
unsigned Dim>
1212 return momentsComputer_m.getHalo();
1215template <
class T,
unsigned Dim>
1217 return momentsComputer_m.get68Percentile();
1220template <
class T,
unsigned Dim>
1222 return momentsComputer_m.get95Percentile();
1225template <
class T,
unsigned Dim>
1227 return momentsComputer_m.get99Percentile();
1230template <
class T,
unsigned Dim>
1232 return momentsComputer_m.get99_99Percentile();
1235template <
class T,
unsigned Dim>
1237 return momentsComputer_m.getNormalizedEmittance68Percentile();
1240template <
class T,
unsigned Dim>
1242 return momentsComputer_m.getNormalizedEmittance95Percentile();
1245template <
class T,
unsigned Dim>
1247 return momentsComputer_m.getNormalizedEmittance99Percentile();
1250template <
class T,
unsigned Dim>
1252 return momentsComputer_m.getNormalizedEmittance99_99Percentile();
1255template <
class T,
unsigned Dim>
1257 return momentsComputer_m.getDx();
1261template <
class T,
unsigned Dim>
1263 return momentsComputer_m.getDy();
1267template <
class T,
unsigned Dim>
1269 return momentsComputer_m.getDDx();
1273template <
class T,
unsigned Dim>
1275 return momentsComputer_m.getDDy();
1279template <
class T,
unsigned Dim>
1285template <
class T,
unsigned Dim>
1291template <
class T,
unsigned Dim>
1314 meshFit_m = meshFit;
1318 scRepartitionDue_m =
false;
1319 scHasSolved_m =
false;
1322 scCoreMesh_m =
false;
1328template <
class T,
unsigned Dim>
1334template <
class T,
unsigned Dim>
1336 meshFitSolveStep_m = solveStep;
1340template <
class T,
unsigned Dim>
1346template <
class T,
unsigned Dim>
1353template <
class T,
unsigned Dim>
1357 for (
unsigned short d = 0; d < 3u; ++ d) {
1358 const double length = std::abs(rmax[d] - rmin[d]);
1359 const double margin = (length < 1e-10) ? 1e-10 : dh_m * length;
1360 hr[d] = ((rmax[d] + margin) - (rmin[d] - margin)) / (nr_m[d] - 1);
1366template <
class T,
unsigned Dim>
1372template <
class T,
unsigned Dim>
1378template <
class T,
unsigned Dim>
1384template <
class T,
unsigned Dim>
1390template <
class T,
unsigned Dim>
1393 return scStatistics_m;
1397template <
class T,
unsigned Dim>
1400 scStatistics_m.turnFullSolves = 0;
1405template <
class T,
unsigned Dim>
1407 if ((scWarned_m & warning) == 0) {
1408 scWarned_m |= warning;
1409 *
gmsg <<
"* Warning: SC mesh fit at integration step " << getLocalTrackStep() + 1
1410 <<
": " << message <<
" (at most once per turn)" <<
endl;
1415template <
class T,
unsigned Dim>
1417 get_bounds(rmin, rmax);
1428 const size_t localNum = getLocalNum();
1431 localNum > 0 ? &Qc[0] :
nullptr,
1432 localNum > 0 ? &Binc[0] :
nullptr,
1433 localNum, meshFit_m.nSigma, meshFit_m.clip,
1440 if (meshFitSolveStep_m) {
1445 const bool switched = (scMode_m.mode != previous.
mode);
1446 scRepartitionDue_m = (switched || !scHasSolved_m);
1447 scHasSolved_m =
true;
1449 scCore_m = selection;
1454 scStatistics_m.numFlagged = 0;
1455 ++ scStatistics_m.turnSolves;
1457 ++ scStatistics_m.fullSolves;
1458 ++ scStatistics_m.turnFullSolves;
1461 ++ scStatistics_m.modeSwitches;
1463 *
gmsg <<
"* SC mesh fit at integration step " << getLocalTrackStep() + 1
1464 <<
": the mesh is fitted to " << (toFull ?
"all particles" :
"the core")
1465 <<
" from now on (MESHFIT mode " << (toFull ?
"FULL" :
"CORE") <<
"), "
1467 <<
" live particles in the core, far charge "
1473 std::ostringstream message;
1475 <<
" % of the live charge (MESHFITMAXFAR "
1476 << 100.0 * meshFit_m.maxFarFraction <<
" %)";
1477 warnMeshFitOnce(FarChargeWarning, message.str());
1483 warnMeshFitOnce(FullBoxWarning,
"the core bounds equal the bounds of all "
1484 "particles, although there are far particles");
1489 scNumCore_m = selection.
numCore;
1498 localNum > 0 ? &Binc[0] :
nullptr,
1499 localNum, selection, meshFit_m.nSigma,
1508template <
class T,
unsigned Dim>
1518 static_cast<Layout_t*
>(&getLayout())->getLayout().getDomain();
1520 const size_t localNum = getLocalNum();
1521 double counts[2] = {0.0,
static_cast<double>(localNum)};
1522 for (
size_t i = 0; i < localNum; ++ i) {
1523 for (
unsigned int d = 0; d <
Dim; ++ d) {
1524 if (!(Rc[i](d) >= domain[d].
min() && Rc[i](d) < domain[d].
max())) {
1530 allreduce(counts, 2, std::plus<double>());
1531 scStatistics_m.numOutside =
static_cast<size_t>(counts[0]);
1534 const double numNotCore = std::max(counts[1] -
static_cast<double>(scNumCore_m), 0.0);
1535 if (counts[0] > 2.0 * numNotCore + 100.0) {
1537 "FIELDSOLVER, MESHFIT=\"CORE\": " +
1538 std::to_string(scStatistics_m.numOutside) +
" of " +
1539 std::to_string(
static_cast<size_t>(counts[1])) +
1540 " particles are outside the space-charge mesh, but only " +
1541 std::to_string(
static_cast<size_t>(numNotCore)) +
1542 " are outside the core of the last mesh fit. The particles were "
1543 "updated in a frame the mesh was not fitted to.");
1548template <
class T,
unsigned Dim>
1552 globalPartPerNode_m[i] = 0;
1554 std::size_t localnum = getLocalNum();
1555 gather(&localnum, &globalPartPerNode_m[0], 1);
1559template <
class T,
unsigned Dim>
1561 return globalPartPerNode_m[p];
1565template <
class T,
unsigned Dim>
1571template <
class T,
unsigned Dim>
1575 get_bounds(rmin_m, rmax_m);
1576 momentsComputer_m.compute(*
this);
1580template <
class T,
unsigned Dim>
1582 return couplingConstant_m;
1586template <
class T,
unsigned Dim>
1588 couplingConstant_m = c;
1592template <
class T,
unsigned Dim>
1595 if (getTotalNum() != 0)
1598 WARNMSG(
"Could not set total charge in PartBunch::setCharge based on getTotalNum" <<
endl);
1602template <
class T,
unsigned Dim>
1608template <
class T,
unsigned Dim>
1610 massPerParticle_m = mass;
1611 if (getTotalNum() != 0)
1615template <
class T,
unsigned Dim>
1617 massPerParticle_m = mass;
1621template <
class T,
unsigned Dim>
1627template <
class T,
unsigned Dim>
1632template <
class T,
unsigned Dim>
1634 return massPerParticle_m;
1637template <
class T,
unsigned Dim>
1640 fs_m->initSolver(
this);
1647 this->initialize(fs_m->getFieldLayout());
1655template <
class T,
unsigned Dim>
1658 return fs_m->hasValidSolver();
1665template <
class T,
unsigned Dim>
1668 return fs_m->getFieldSolverType();
1675template <
class T,
unsigned Dim>
1681template <
class T,
unsigned Dim>
1683 return stepsPerTurn_m;
1687template <
class T,
unsigned Dim>
1689 globalTrackStep_m = n;
1693template <
class T,
unsigned Dim>
1695 return globalTrackStep_m;
1699template <
class T,
unsigned Dim>
1701 localTrackStep_m = n;
1705template <
class T,
unsigned Dim>
1707 globalTrackStep_m++; localTrackStep_m++;
1711template <
class T,
unsigned Dim>
1713 return localTrackStep_m;
1717template <
class T,
unsigned Dim>
1720 bunchTotalNum_m.resize(n);
1721 bunchLocalNum_m.resize(n);
1725template <
class T,
unsigned Dim>
1731template <
class T,
unsigned Dim>
1733 PAssert_LT(n, (
short)bunchTotalNum_m.size());
1734 bunchTotalNum_m[n] = totalnum;
1738template <
class T,
unsigned Dim>
1740 PAssert_LT(n, (
short)bunchTotalNum_m.size());
1741 return bunchTotalNum_m[n];
1745template <
class T,
unsigned Dim>
1747 PAssert_LT(n, (
short)bunchLocalNum_m.size());
1748 bunchLocalNum_m[n] = localnum;
1752template <
class T,
unsigned Dim>
1754 PAssert_LT(n, (
short)bunchLocalNum_m.size());
1755 return bunchLocalNum_m[n];
1759template <
class T,
unsigned Dim>
1761 bunchTotalNum_m.clear();
1762 bunchTotalNum_m.resize(numBunch_m);
1763 bunchLocalNum_m.clear();
1764 bunchLocalNum_m.resize(numBunch_m);
1766 for (
size_t i = 0; i < this->getLocalNum(); ++i) {
1768 ++bunchLocalNum_m[this->bunchNum[i]];
1771 allreduce(bunchLocalNum_m.data(), bunchTotalNum_m.data(),
1772 bunchLocalNum_m.size(), std::plus<size_t>());
1774 size_t totalnum = std::accumulate(bunchTotalNum_m.begin(),
1775 bunchTotalNum_m.end(), 0);
1777 if ( totalnum != this->getTotalNum() )
1778 throw OpalException(
"PartBunchBase::countTotalNumPerBunch()",
1779 "Sum of total number of particles per bunch (" +
1780 std::to_string(totalnum) +
") != total number of particles (" +
1781 std::to_string(this->getTotalNum()) +
")");
1785template <
class T,
unsigned Dim>
1787 globalMeanR_m = globalMeanR;
1791template <
class T,
unsigned Dim>
1793 return globalMeanR_m;
1797template <
class T,
unsigned Dim>
1800 globalToLocalQuaternion_m = globalToLocalQuaternion;
1804template <
class T,
unsigned Dim>
1806 return globalToLocalQuaternion_m;
1810template <
class T,
unsigned Dim>
1812 SteptoLastInj_m = n;
1816template <
class T,
unsigned Dim>
1818 return SteptoLastInj_m;
1822template <
class T,
unsigned Dim>
1825 const int emittedBins = pbin_m->getLastemittedBin();
1826 std::vector<double> phi(emittedBins);
1827 std::vector<double> px(emittedBins);
1828 std::vector<double> py(emittedBins);
1829 double meanPhi = 0.0;
1831 for (
int ii = 0; ii < emittedBins; ii++) {
1837 for (
unsigned int ii = 0; ii < getLocalNum(); ii++) {
1838 px[Bin[ii]] += P[ii](0);
1839 py[Bin[ii]] += P[ii](1);
1844 for (
int ii = 0; ii < emittedBins; ii++) {
1845 phi[ii] = calculateAngle(px[ii], py[ii]);
1850 meanPhi /= emittedBins;
1861template <
class T,
unsigned Dim>
1867 int maxbin = pbin_m->getNBins();
1868 std::vector<size_t> partInBin(maxbin);
1869 for (
int ii = 0; ii < maxbin; ii++) partInBin[ii] = 0;
1871 double pMin0 = 1.0e9;
1873 double maxbinIndex = 0;
1875 for (
unsigned long int n = 0; n < getLocalNum(); n++) {
1876 double temp_betagamma = std::sqrt(std::pow(P[n](0), 2) + std::pow(P[n](1), 2));
1877 if (pMin0 > temp_betagamma)
1878 pMin0 = temp_betagamma;
1883 double asinh0 = std::asinh(pMin);
1884 for (
unsigned long int n = 0; n < getLocalNum(); n++) {
1886 double temp_betagamma = std::sqrt(std::pow(P[n](0), 2) + std::pow(P[n](1), 2));
1887 int itsBinID = std::floor((std::asinh(temp_betagamma) - asinh0) / eta + 1.0E-6);
1889 if (maxbinIndex < itsBinID) {
1890 maxbinIndex = itsBinID;
1893 if (itsBinID >= maxbin) {
1894 ERRORMSG(
"The bin number limit is " << maxbin <<
", please increase the energy interval and try again" <<
endl);
1897 partInBin[itsBinID]++;
1902 pbin_m->resetPartInBin_cyc(partInBin.data(), maxbinIndex);
1912template <
class T,
unsigned Dim>
1914 int maxbin = pbin_m->getNBins();
1915 std::vector<size_t> partInBin(maxbin);
1916 for (
int i = 0; i < maxbin; ++i) {
1920 for (std::size_t i = 0; i < getLocalNum(); ++i) {
1921 partInBin[Bin[i]]++;
1925 pbin_m->resetPartInBin_cyc(partInBin.data(), numBunch_m - 1);
1934template <
class T,
unsigned Dim>
1936 return reference->getQ();
1940template <
class T,
unsigned Dim>
1942 return reference->getM();
1946template <
class T,
unsigned Dim>
1948 return reference->getP();
1952template <
class T,
unsigned Dim>
1954 return reference->getE();
1958template <
class T,
unsigned Dim>
1960 return refPOrigin_m;
1963template <
class T,
unsigned Dim>
1965 refPOrigin_m = origin;
1969template <
class T,
unsigned Dim>
1974template <
class T,
unsigned Dim>
1980template <
class T,
unsigned Dim>
1982 return dist_m->getType();
1986template <
class T,
unsigned Dim>
1988 return reference->getMomentumTolerance();
1992template <
class T,
unsigned Dim>
1994 const_cast<PartData *
>(reference)->setQ(q);
1998template <
class T,
unsigned Dim>
2000 const_cast<PartData *
>(reference)->setM(m);
2004template <
class T,
unsigned Dim>
2006 return momentsComputer_m.getStdKineticEnergy();
2010template <
class T,
unsigned Dim>
2016template <
class T,
unsigned Dim>
2018 return reference->getGamma();
2022template <
class T,
unsigned Dim>
2028template <
class T,
unsigned Dim>
2034template <
class T,
unsigned Dim>
2040template <
class T,
unsigned Dim>
2046template <
class T,
unsigned Dim>
2048 return dist_m->getEmissionDeltaT();
2052template <
class T,
unsigned Dim>
2054 binemitted_m[binNumber]++;
2058template <
class T,
unsigned Dim>
2060 momentsComputer_m.computeMeanKineticEnergy(*
this);
2063template <
class T,
unsigned Dim>
2066 if (getTotalNum() != 0) {
2069 double pathLength = get_sPos();
2071 os << std::scientific;
2073 os <<
"* ************** B U N C H ********************************************************* \n";
2074 os <<
"* NP = " << getTotalNum() <<
"\n";
2081 if (getTotalNum() >= 2) {
2083 os <<
"* rms momenta = " << std::setw(12) << std::setprecision(5) << get_prms() <<
" [beta gamma]\n";
2085 os <<
"* mean momenta = " << std::setw(12) << std::setprecision(5) << get_pmean() <<
" [beta gamma]\n";
2086 os <<
"* rms emittance = " << std::setw(12) << std::setprecision(5) << get_emit() <<
" (not normalized)\n";
2087 os <<
"* rms correlation = " << std::setw(12) << std::setprecision(5) << get_rprms() <<
"\n";
2090 os <<
"* dh = " << std::setw(13) << std::setprecision(5) << dh_m * 100 <<
" [%]\n";
2094 os <<
"* ********************************************************************************** " <<
endl;
2101template <
class T,
unsigned Dim>
2103 double thetaXY = std::atan2(y, x);
2109template <
class T,
unsigned Dim>
2119template <
class T,
unsigned Dim>
2121 throw OpalException(
"PartBunchBase<T, Dim>::runTests() ",
"No test supported.");
2125template <
class T,
unsigned Dim>
2130template <
class T,
unsigned Dim>
2132 if (i >= getLocalNum() || j >= getLocalNum() || i == j)
return;
2134 std::swap(R[i], R[j]);
2135 std::swap(P[i], P[j]);
2136 std::swap(Q[i], Q[j]);
2137 std::swap(M[i], M[j]);
2138 std::swap(Phi[i], Phi[j]);
2139 std::swap(Ef[i], Ef[j]);
2140 std::swap(Eftmp[i], Eftmp[j]);
2141 std::swap(Bf[i], Bf[j]);
2142 std::swap(Bin[i], Bin[j]);
2143 std::swap(dt[i], dt[j]);
2144 std::swap(PType[i], PType[j]);
2145 std::swap(POrigin[i], POrigin[j]);
2146 std::swap(TriID[i], TriID[j]);
2147 std::swap(cavityGapCrossed[i], cavityGapCrossed[j]);
2148 std::swap(bunchNum[i], bunchNum[j]);
2152template <
class T,
unsigned Dim>
2154 throw OpalException(
"PartBunchBase<T, Dim>::setBCAllPeriodic() ",
"Not supported BC.");
2158template <
class T,
unsigned Dim>
2160 throw OpalException(
"PartBunchBase<T, Dim>::setBCAllOpen() ",
"Not supported BC.");
2164template <
class T,
unsigned Dim>
2166 throw OpalException(
"PartBunchBase<T, Dim>::setBCForDCBeam() ",
"Not supported BC.");
2170template <
class T,
unsigned Dim>
2175template <
class T,
unsigned Dim>
2204 globalPartPerNode_m = std::unique_ptr<size_t[]>(
new size_t[
Ippl::getNodes()]);
2210template <
class T,
unsigned Dim>
2212 return pbase_m->getTotalNum();
2215template <
class T,
unsigned Dim>
2217 return pbase_m->getLocalNum();
2221template <
class T,
unsigned Dim>
2223 return pbase_m->getDestroyNum();
2226template <
class T,
unsigned Dim>
2228 return pbase_m->getGhostNum();
2231template <
class T,
unsigned Dim>
2233 pbase_m->setTotalNum(n);
2236template <
class T,
unsigned Dim>
2238 pbase_m->setLocalNum(n);
2241template <
class T,
unsigned Dim>
2243 return pbase_m->getLayout();
2246template <
class T,
unsigned Dim>
2248 return pbase_m->getLayout();
2251template <
class T,
unsigned Dim>
2256template <
class T,
unsigned Dim>
2258 pbase_m->setUpdateFlag(f, val);
2261template <
class T,
unsigned Dim>
2263 return pbase_m->singleInitNode();
2266template <
class T,
unsigned Dim>
2271template <
class T,
unsigned Dim>
2278 checkMeshFitOutside();
2281template <
class T,
unsigned Dim>
2284 pbase_m->update(canSwap);
2288 checkMeshFitOutside();
2291template <
class T,
unsigned Dim>
2293 pbase_m->createWithID(
id);
2296template <
class T,
unsigned Dim>
2301template <
class T,
unsigned Dim>
2303 pbase_m->globalCreate(np);
2306template <
class T,
unsigned Dim>
2308 pbase_m->destroy(M, I, doNow);
2311template <
class T,
unsigned Dim>
2313 pbase_m->performDestroy(updateLocalNum);
2316template <
class T,
unsigned Dim>
2318 pbase_m->ghostDestroy(M, I);
2321template <
class T,
unsigned Dim>
2326template <
class T,
unsigned Dim>
2331 for (
unsigned int i = 0; i <
Dim; i++) {
2332 rpmean(2*i)= get_rmean()(i);
2333 rpmean((2*i)+1)= get_pmean()(i);
2337 for (
unsigned int i = 0; i < 2 *
Dim; i++) {
2338 for (
unsigned int j = 0; j <= i; j++) {
2339 sigmaMatrix[i][j] = momentsComputer_m.getMoments6x6()[i][j] - rpmean(i) * rpmean(j);
2340 sigmaMatrix[j][i] = sigmaMatrix[i][j];
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Inform & operator<<(Inform &os, PartBunchBase< T, Dim > &p)
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)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
PETE_TTTree< OpWhere, typename Cond_t::PETE_Expr_t, typename True_t::PETE_Expr_t, PETE_Scalar< Vektor< T, Dim > > > where(const PETE_Expr< Cond_t > &c, const PETE_Expr< True_t > &t, const Vektor< T, Dim > &f)
void bounds(const PETE_Expr< T1 > &expr, Vektor< T2, D > &minval, Vektor< T2, D > &maxval)
void allreduce(const T *input, T *output, int count, Op op)
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
void gather(const T *input, T *output, int count, int root=0)
PETE_TBTree< OpNE, Index::PETE_Expr_t, PETE_Scalar< double > > ne(const Index &idx, double x)
PETE_TBTree< OpEQ, Index::PETE_Expr_t, PETE_Scalar< double > > eq(const Index &idx, double x)
Inform & level2(Inform &inf)
Inform & endl(Inform &inf)
Inform & level1(Inform &inf)
CoreSelection selectCore(const Vector_t *R, const double *Q, const int *bin, std::size_t localNum, double nSigma, double clip, const Reducer &reducer)
constexpr double warnFarFraction
The solve warns when the far charge fraction exceeds this.
ModeState decideMode(const ModeState &previous, std::size_t numCore, std::size_t numLive, double farChargeFraction, double maxFarFraction, unsigned int minDwell)
void getMeshBox(const Vector_t *R, const int *bin, std::size_t localNum, const CoreSelection &selection, double nSigma, const Reducer &reducer, Vector_t &boxMin, Vector_t &boxMax)
constexpr double two_pi
The value of.
constexpr double e
The value of.
constexpr double c
The velocity of light in m/s.
int repartFreq
The frequency to do particles repartition for better load balance between nodes.
std::string getChargeString(double charge, unsigned int precision=3)
std::string getEnergyString(double energyInMeV, unsigned int precision=3)
std::string getTimeString(double time, unsigned int precision=3)
std::string getLengthString(double spos, unsigned int precision=3)
void update(PyOpalObjectNS::PyOpalObject< C > pyelement)
ParticleLayout< T, Dim > & getLayout()
void setEnergyBins(int numberOfEnergyBins)
double get_meanKineticEnergy() const
void setDistribution(Distribution *d, std::vector< Distribution * > addedDistributions, size_t &np)
virtual void resetInterpolationCache(bool clearCache=false)
void getMeshFitFullBounds(Vector_t &rmin, Vector_t &rmax) const
MESHFIT=CORE: the bounds of all particles of the same fit.
void setPType(const std::string &type)
const PartData * getReference() const
ParticleOrigin getPOrigin() const
void setMass(double mass)
int getSteptoLastInj() const
Vector_t get_99Percentile() const
void boundp_destroyCycl()
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
bool resetPartBinID2(const double eta)
reset Bin[] for each particle according to the method given in paper PAST-AB(064402) by G....
void setNumBunch(short n)
const MeshFitParameters & getMeshFit() const
double getMassPerParticle() const
double getQ() const
Access to reference data.
double getCouplingConstant() const
Vector_t get_normalizedEps_99Percentile() const
double getChargePerParticle() const
get the macro particle charge
virtual void set_meshEnlargement(double dh)
void getSolverMeshBounds(Vector_t &rmin, Vector_t &rmax)
virtual double getBeta(int i)
virtual double getPx0(int i)
size_t getLocalNum() const
FMatrix< double, 2 *Dim, 2 *Dim > getSigmaMatrix() const
void setMeshFit(const MeshFitParameters &meshFit)
FIELDSOLVER, MESHFIT: the particles the space-charge mesh is fitted to.
void setLocalTrackStep(long long n)
step in a TRACK command
void setLocalBinCount(size_t num, int bin)
double get_debyeLength() const
bool getUpdateFlag(UpdateFlags_t f) const
void setParticle(FVector< double, 6 > z, int ii)
size_t emitParticles(double eZ)
Emit particles in the given bin i.e. copy the particles from the bin structure into the particle cont...
void maximumAmplitudes(const FMatrix< double, 6, 6 > &D, double &axmax, double &aymax)
Return maximum amplitudes.
double get_plasmaParameter() const
void setMassZeroPart(double mass)
size_t getTotalNum() const
virtual void updateFields(const Vector_t &hr, const Vector_t &origin)
Vector_t get_95Percentile() const
virtual void setZ(int i, double zcoo)
void checkMeshFitOutside()
bool isMeshFitToCore() const
double calcMeanPhi()
calculate average angle of longitudinal direction of bins
Quaternion_t getGlobalToLocalQuaternion()
void setBeamFrequency(double v)
Vector_t get_normalizedEps_68Percentile() const
void switchToUnitlessPositions(bool use_dt_per_particle=false)
size_t calcNumPartsOutside(Vector_t x)
returns the number of particles outside of a box defined by x
Inform & print(Inform &os)
FieldSolverType getFieldSolverType() const
Return the fieldsolver type if we have a fieldsolver.
double getEmissionDeltaT()
void setLocalNumPerBunch(size_t numpart, short n)
size_t getLocalNumPerBunch(short n) const
void setGlobalToLocalQuaternion(Quaternion_t globalToLocalQuaternion)
Vector_t get_rrms() const
void setMeshFitMode(const CoreFitSC::ModeState &mode)
MESHFIT=CORE: restores the mode, from the step attributes of an H5 restart.
double get_rmsDensity() const
virtual double getPy(int i)
double getBinGamma(int bin)
Get gamma of one bin.
double getInitialBeta() const
int getLastEmittedEnergyBin()
void calcBeamParameters()
void getLocalBounds(Vector_t &rmin, Vector_t &rmax) const
void setSteptoLastInj(int n)
virtual double getX0(int i)
double getInitialGamma() const
virtual void setBCAllPeriodic()
void setChargeZeroPart(double q)
virtual double getY0(int i)
ParticleType getPType() const
Vector_t get_origin() const
Vector_t get_prms() const
void createWithID(unsigned id)
const CoreFitSC::CoreSelection & getMeshFitCore() const
PartBunchBase(AbstractParticle< T, Dim > *pb, const PartData *ref)
double getCharge() const
get the total charge per simulation particle
virtual double getPy0(int i)
double get_temperature() const
size_t getTotalNumPerBunch(short n) const
virtual double getPx(int i)
Vector_t get_pmean_Distribution() const
size_t getNumberOfEmissionSteps()
void calcLineDensity(unsigned int nBins, std::vector< double > &lineDensity, std::pair< double, double > &meshInfo)
calculates the 1d line density (not normalized) and append it to a file.
Vector_t get_68Percentile() const
void setup(AbstractParticle< T, Dim > *pb)
virtual void setBCAllOpen()
void setTotalNum(size_t n)
Vector_t getMeshSpacing(const Vector_t &rmin, const Vector_t &rmax) const
Mesh spacing that boundp() gives to particles within [rmin, rmax].
long long getLocalTrackStep() const
void warnMeshFitOnce(MeshFitWarning warning, const std::string &message)
void setGlobalMeanR(Vector_t globalMeanR)
void setCouplingConstant(double c)
short getNumBunch() const
virtual void do_binaryRepart()
Vector_t get_norm_emit() const
void calcGammas()
Compute the gammas of all bins.
int getStepsPerTurn() const
Vector_t get_rprms() const
void setPOrigin(ParticleOrigin)
bool isMeshFitRepartitionDue() const
Vector_t get_maxExtent() const
Vector_t get_normalizedEps_95Percentile() const
void gatherLoadBalanceStatistics()
void countTotalNumPerBunch()
DistributionType getDistType() const
void get_PBounds(Vector_t &min, Vector_t &max) const
virtual void setBinCharge(int bin, double q)
Set the charge of one bin to the value of q and all other to zero.
Vector_t get_halo() const
void performDestroy(bool updateLocalNum=false)
Vector_t getGlobalMeanR()
void ghostDestroy(size_t M, size_t I)
int getNumberOfEnergyBins()
void setGlobalTrackStep(long long n)
step in multiple TRACK commands
std::pair< Vector_t, double > getBoundingSphere()
void setMeshFitSolveStep(bool solveStep)
Vector_t get_centroid() const
Vector_t get_99_99Percentile() const
void push_back(OpalParticle const &p)
virtual double getX(int i)
virtual double getPz(int i)
void setLocalNum(size_t n)
Vector_t get_pmean() const
void setTotalNumPerBunch(size_t numpart, short n)
virtual void setBCForDCBeam()
void destroy(size_t M, size_t I, bool doNow=false)
void globalCreate(size_t np)
Vector_t get_normalizedEps_99_99Percentile() const
double getMomentumTolerance() const
const CoreFitSC::ModeState & getMeshFitMode() const
OpalParticle getParticle(int ii)
virtual void swap(unsigned int i, unsigned int j)
void setPBins(PartBins *pbin)
size_t getDestroyNum() const
virtual double getGamma(int i)
virtual void setSolver(FieldSolver *fs)
long long getGlobalTrackStep() const
size_t getGhostNum() const
void setTEmission(double t)
size_t getLoadBalance(int p) const
std::pair< Vector_t, double > getLocalBoundingSphere()
virtual Vector_t get_hr() const
Vector_t get_emit() const
double calculateAngle(double x, double y)
angle range [0~2PI) degree
void calcDebyeLength()
Compute the (global) Debye length for the beam.
void iterateEmittedBin(int binNumber)
MeshFitWarning
MESHFIT=CORE: the warnings of the solve, each given at most once per turn.
bool singleInitNode() const
void setUpdateFlag(UpdateFlags_t f, bool val)
virtual double getY(int i)
void switchOffUnitlessPositions(bool use_dt_per_particle=false)
void setStepsPerTurn(int n)
const MeshFitStatistics & getMeshFitStatistics() const
virtual double getZ(int i)
Vector_t get_rmean() const
static OpalData * getInstance()
All IPPL nodes, through allreduce().
Result of selectCore(), the same on every rank.
double getFarChargeFraction() const
Far charge over live charge, 0 without live charge.
std::size_t numLive
particles with Bin >= 0
Vector_t boundsMin
minimum over the core particles [m]
std::size_t numFar
the other live particles
std::size_t numCore
live particles within nSigma * sigma in every axis
double getPy() const
Get vertical momentum (no dimension).
const Vector_t & getR() const
Get position in m.
const Vector_t & getP() const
Get momentum.
double getPz() const
Get relative momentum error (no dimension).
double getY() const
Get vertical displacement in m.
double getZ() const
Get longitudinal displacement c*t in m.
double getPx() const
Get horizontal momentum (no dimension).
double getX() const
Get horizontal position in m.
MESHFIT=CORE: statistics of the solves of this TRACK/RUN, for the stat file and the log.
size_t turnSolves
solves in this turn
double getBeta() const
The relativistic beta per particle.
An abstract sequence of beam line components.
A templated representation for matrices.
A templated representation for vectors.
static ParticleType getParticleType(std::string_view str) noexcept
void createOpalCycl(PartBunchBase< double, 3 > *beam, size_t numberOfParticles, double current, const Beamline &bl)
void createOpalT(PartBunchBase< double, 3 > *beam, std::vector< Distribution * > addedDistributions, size_t &numberOfParticles)
Parameters of the mesh fit, passed to the bunch (PartBunchBase::setMeshFit())
The base class for all OPAL exceptions.
virtual void addAttribute(ParticleAttribBase &pa)=0
void setOutsideToNearest(bool outsideToNearest)
void setCacheDimension(int d, T length)
bool getUpdateFlag(UpdateFlags f) const
std::ios_base::fmtflags FmtFlags_t
virtual const char * what() const
virtual const std::string & where() const
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)
Vektor< double, 3 > Vector_t