18 #ifndef PART_BUNCH_BASE_HPP
19 #define PART_BUNCH_BASE_HPP
40 template <
class T,
unsigned Dim>
90 template <
class T,
unsigned Dim>
95 if (isBeamEmitted > 0)
104 template <
class T,
unsigned Dim>
111 return lastEmittedBin;
115 template <
class T,
unsigned Dim>
121 template <
class T,
unsigned Dim>
127 template <
class T,
unsigned Dim>
132 if (isBeamEmitting > 0) {
133 *gmsg <<
"*****************************************************" <<
endl
134 <<
"Warning: attempted to rebin, but not all distribution" <<
endl
135 <<
"particles have been emitted. Rebin failed." <<
endl
136 <<
"*****************************************************" <<
endl;
144 template <
class T,
unsigned Dim>
146 bingamma_m = std::unique_ptr<double[]>(
new double[numberOfEnergyBins]);
147 binemitted_m = std::unique_ptr<size_t[]>(
new size_t[numberOfEnergyBins]);
148 for (
int i = 0; i < numberOfEnergyBins; i++)
153 template <
class T,
unsigned Dim>
163 template <
class T,
unsigned Dim>
168 "Cannot make a unitless PartBunch unitless");
170 bool hasToReset =
false;
171 if (!
R.isDirty()) hasToReset =
true;
175 if (use_dt_per_particle)
183 if (hasToReset)
R.resetDirtyFlag();
187 template <
class T,
unsigned Dim>
192 "Cannot apply units twice to PartBunch");
194 bool hasToReset =
false;
195 if (!
R.isDirty()) hasToReset =
true;
199 if (use_dt_per_particle)
207 if (hasToReset)
R.resetDirtyFlag();
211 template <
class T,
unsigned Dim>
217 template <
class T,
unsigned Dim>
219 std::vector<Distribution*> addedDistributions,
221 Inform m(
"setDistribution " );
231 template <
class T,
unsigned Dim>
233 size_t numberOfParticles,
241 template <
class T,
unsigned Dim>
247 template <
class T,
unsigned Dim>
249 return (
pbin_m !=
nullptr);
253 template <
class T,
unsigned Dim>
259 template <
class T,
unsigned Dim>
265 template <
class T,
unsigned Dim>
274 template <
class T,
unsigned Dim>
283 template <
class T,
unsigned Dim>
291 template <
class T,
unsigned Dim>
298 template <
class T,
unsigned Dim>
304 template <
class T,
unsigned Dim>
312 template <
class T,
unsigned Dim>
321 template <
class T,
unsigned Dim>
330 template <
class T,
unsigned Dim>
338 template <
class T,
unsigned Dim>
345 for (
int i = 0; i < emittedBins; i++)
351 std::unique_ptr<size_t[]> particlesInBin(
new size_t[emittedBins]);
354 for (
int i = 0; i < emittedBins; i++) {
355 size_t &pInBin = particlesInBin[i];
359 <<
" gamma = " << std::setw(8) << std::scientific
361 <<
"; NpInBin= " << std::setw(8)
362 << std::setfill(
' ') << pInBin <<
endl);
369 particlesInBin.reset();
375 if (emittedBins >= 2) {
376 for (
int i = 1; i < emittedBins; i++) {
379 <<
"between bin " << i - 1 <<
" and " << i <<
endl);
385 template <
class T,
unsigned Dim>
390 for (
int i = 0; i < emittedBins; i++)
393 if ( this->
Bin[
n] > -1 ) {
400 for (
int i = 0; i < emittedBins; i++) {
412 template <
class T,
unsigned Dim>
419 template <
class T,
unsigned Dim>
425 template <
class T,
unsigned Dim>
431 template <
class T,
unsigned Dim>
437 template <
class T,
unsigned Dim>
440 std::size_t localnum = 0;
444 if (
std::abs(
R[k](0) - meanR(0)) > x(0) ||
455 std::plus<size_t>());
470 template <
class T,
unsigned Dim>
472 std::vector<double>& lineDensity,
473 std::pair<double, double>& meshInfo) {
483 double length = rmax(2) - rmin(2);
484 double zmin = rmin(2) -
dh_m * length, zmax = rmax(2) +
dh_m * length;
485 double hz = (zmax - zmin) / (nBins - 2);
486 double perMeter = 1.0 / hz;
489 lineDensity.resize(nBins, 0.0);
490 std::fill(lineDensity.begin(), lineDensity.end(), 0.0);
493 for (
unsigned int i = 0; i < lN; ++ i) {
494 const double z =
R[i](2) - 0.5 * hz;
495 unsigned int idx = (z - zmin) / hz;
496 double tau = (z - zmin) / hz - idx;
498 lineDensity[idx] +=
Q[i] * (1.0 - tau) * perMeter;
499 lineDensity[idx + 1] +=
Q[i] * tau * perMeter;
502 reduce(&(lineDensity[0]), &(lineDensity[0]) + nBins, &(lineDensity[0]),
OpAddAssign());
504 meshInfo.first = zmin;
505 meshInfo.second = hz;
509 template <
class T,
unsigned Dim>
522 const int dimIdx = (
dcBeam_m? 2: 3);
537 for (
int i = 0; i < dimIdx; i++) {
539 if (length < 1
e-10) {
544 rmin_m[i] -=
dh_m * length;
550 hr_m[2] = periodLength_m / (
nr_m[2] - 1);
552 for (
int i = 0; i < dimIdx; ++ i) {
560 if (percent < 1.0 && percent > 0.0) {
562 rmin_m[2] =
rmax_m[2] - length / percent;
567 rmin_m[2] -=
dh_m * length;
610 template <
class T,
unsigned Dim>
614 const int dimIdx = 3;
617 std::unique_ptr<size_t[]> countLost;
620 countLost = std::unique_ptr<size_t[]>(
new size_t[tempN]);
621 for (
int ii = 0; ii < tempN; ii++) countLost[ii] = 0;
635 if (checkfactor != 0) {
640 if(checkfactor < 0) {
642 if (len[0] > checkfactor * rrms[0] ||
643 len[1] > checkfactor * rrms[1] ||
644 len[2] > checkfactor * rrms[2])
646 for(
unsigned int ii = 0; ii < this->
getLocalNum(); ii++) {
650 if (
std::abs(
R[ii](0) - rmean(0)) > checkfactor * rrms[0] ||
651 std::abs(
R[ii](1) - rmean(1)) > checkfactor * rrms[1] ||
652 std::abs(
R[ii](2) - rmean(2)) > checkfactor * rrms[2])
658 countLost[
Bin[ii]] += 1 ;
667 if (len[0] > checkfactor * rrms[0] ||
668 len[2] > checkfactor * rrms[2])
670 for(
unsigned int ii = 0; ii < this->
getLocalNum(); ii++) {
674 if (
std::abs(
R[ii](0) - rmean(0)) > checkfactor * rrms[0] ||
675 std::abs(
R[ii](2) - rmean(2)) > checkfactor * rrms[2])
681 countLost[
Bin[ii]] += 1 ;
691 for (
int i = 0; i < dimIdx; i++) {
694 rmin_m[i] -=
dh_m * length;
718 template <
class T,
unsigned Dim>
723 std::vector<size_t> tmpbinemitted;
733 if (haveEnergyBins) {
736 for (
unsigned int i = 0; i < localNum; i++) {
740 }
else if (haveEnergyBins) {
741 tmpbinemitted[
Bin[i]]++;
750 if (haveEnergyBins) {
752 for (
int i = 0; i < lastBin; i++) {
761 template <
class T,
unsigned Dim>
764 std::unique_ptr<size_t[]> tmpbinemitted;
773 tmpbinemitted[i] = 0;
775 for (
unsigned int i = 0; i < localNum; i++) {
780 tmpbinemitted[
Bin[i]]++;
784 for (
size_t i = 0; i < localNum; i++) {
801 for (
int i = 0; i < lastBin; i++) {
810 return totalNum - newTotalNum;
814 template <
class T,
unsigned Dim>
819 template <
class T,
unsigned Dim>
824 template <
class T,
unsigned Dim>
829 template <
class T,
unsigned Dim>
834 template <
class T,
unsigned Dim>
840 template <
class T,
unsigned Dim>
842 return this->
R[i](0);
846 template <
class T,
unsigned Dim>
848 return this->
R[i](1);
852 template <
class T,
unsigned Dim>
854 return this->
R[i](2);
858 template <
class T,
unsigned Dim>
864 template <
class T,
unsigned Dim>
870 template <
class T,
unsigned Dim>
875 template <
class T,
unsigned Dim>
882 for (
unsigned int i = 0; i <
Dim; ++i) {
884 min[2*i + 1] = -rmax[i];
887 allreduce(min, 2*Dim, std::less<double>());
889 for (
unsigned int i = 0; i <
Dim; ++i) {
891 rmax[i] = -min[2*i + 1];
896 template <
class T,
unsigned Dim>
900 double maxValue = 1e8;
901 rmin =
Vector_t(maxValue, maxValue, maxValue);
902 rmax =
Vector_t(-maxValue, -maxValue, -maxValue);
908 for (
size_t i = 1; i < localNum; ++ i) {
909 for (
unsigned short d = 0; d < 3u; ++ d) {
910 if (rmin(d) >
R[i](d)) rmin(d) =
R[i](d);
911 else if (rmax(d) <
R[i](d)) rmax(d) =
R[i](d);
917 template <
class T,
unsigned Dim>
922 std::pair<Vector_t, double> sphere;
923 sphere.first = 0.5 * (rmin + rmax);
924 sphere.second =
std::sqrt(
dot(rmax - sphere.first, rmax - sphere.first));
930 template <
class T,
unsigned Dim>
935 std::pair<Vector_t, double> sphere;
936 sphere.first = 0.5 * (rmin + rmax);
937 sphere.second =
std::sqrt(
dot(rmax - sphere.first, rmax - sphere.first));
943 template <
class T,
unsigned Dim>
950 R[i] = particle.
getR();
951 P[i] = particle.
getP();
954 msg <<
"Created one particle i= " << i <<
endl;
958 template <
class T,
unsigned Dim>
969 template <
class T,
unsigned Dim>
971 R[ii] = particle.
getR();
972 P[ii] = particle.
getP();
976 template <
class T,
unsigned Dim>
980 R[ii](2),
Q[ii],
M[ii]);
985 template <
class T,
unsigned Dim>
987 double& axmax,
double& aymax) {
991 for (
unsigned int ii = 0; ii <
getLocalNum(); ii++) {
1018 template <
class T,
unsigned Dim>
1024 template <
class T,
unsigned Dim>
1030 template <
class T,
unsigned Dim>
1036 template <
class T,
unsigned Dim>
1042 template <
class T,
unsigned Dim>
1048 template <
class T,
unsigned Dim>
1054 template <
class T,
unsigned Dim>
1060 template <
class T,
unsigned Dim>
1066 template <
class T,
unsigned Dim>
1072 template <
class T,
unsigned Dim>
1077 template <
class T,
unsigned Dim>
1082 template <
class T,
unsigned Dim>
1087 template <
class T,
unsigned Dim>
1092 template <
class T,
unsigned Dim>
1098 template <
class T,
unsigned Dim>
1104 template <
class T,
unsigned Dim>
1110 template <
class T,
unsigned Dim>
1116 template <
class T,
unsigned Dim>
1122 template <
class T,
unsigned Dim>
1128 template <
class T,
unsigned Dim>
1134 template <
class T,
unsigned Dim>
1140 template <
class T,
unsigned Dim>
1145 double gamma = 0.1 /
getM() + 1;
1150 template <
class T,
unsigned Dim>
1156 template <
class T,
unsigned Dim>
1162 template <
class T,
unsigned Dim>
1167 template <
class T,
unsigned Dim>
1172 template <
class T,
unsigned Dim>
1177 template <
class T,
unsigned Dim>
1182 template <
class T,
unsigned Dim>
1187 template <
class T,
unsigned Dim>
1192 template <
class T,
unsigned Dim>
1197 template <
class T,
unsigned Dim>
1202 template <
class T,
unsigned Dim>
1207 template <
class T,
unsigned Dim>
1213 template <
class T,
unsigned Dim>
1219 template <
class T,
unsigned Dim>
1225 template <
class T,
unsigned Dim>
1231 template <
class T,
unsigned Dim>
1237 template <
class T,
unsigned Dim>
1243 template <
class T,
unsigned Dim>
1254 template <
class T,
unsigned Dim>
1260 template <
class T,
unsigned Dim>
1266 template <
class T,
unsigned Dim>
1275 template <
class T,
unsigned Dim>
1281 template <
class T,
unsigned Dim>
1287 template <
class T,
unsigned Dim>
1293 WARNMSG(
"Could not set total charge in PartBunch::setCharge based on getTotalNum" <<
endl);
1297 template <
class T,
unsigned Dim>
1303 template <
class T,
unsigned Dim>
1310 template <
class T,
unsigned Dim>
1316 template <
class T,
unsigned Dim>
1322 template <
class T,
unsigned Dim>
1327 template <
class T,
unsigned Dim>
1332 template <
class T,
unsigned Dim>
1350 template <
class T,
unsigned Dim>
1360 template <
class T,
unsigned Dim>
1370 template <
class T,
unsigned Dim>
1376 template <
class T,
unsigned Dim>
1382 template <
class T,
unsigned Dim>
1388 template <
class T,
unsigned Dim>
1394 template <
class T,
unsigned Dim>
1400 template <
class T,
unsigned Dim>
1406 template <
class T,
unsigned Dim>
1412 template <
class T,
unsigned Dim>
1420 template <
class T,
unsigned Dim>
1426 template <
class T,
unsigned Dim>
1433 template <
class T,
unsigned Dim>
1440 template <
class T,
unsigned Dim>
1447 template <
class T,
unsigned Dim>
1454 template <
class T,
unsigned Dim>
1461 for (
size_t i = 0; i < this->
getLocalNum(); ++i) {
1473 throw OpalException(
"PartBunchBase::countTotalNumPerBunch()",
1474 "Sum of total number of particles per bunch (" +
1475 std::to_string(totalnum) +
") != total number of particles (" +
1480 template <
class T,
unsigned Dim>
1486 template <
class T,
unsigned Dim>
1492 template <
class T,
unsigned Dim>
1499 template <
class T,
unsigned Dim>
1505 template <
class T,
unsigned Dim>
1511 template <
class T,
unsigned Dim>
1517 template <
class T,
unsigned Dim>
1521 double phi[emittedBins];
1522 double px[emittedBins];
1523 double py[emittedBins];
1524 double meanPhi = 0.0;
1526 for (
int ii = 0; ii < emittedBins; ii++) {
1532 for (
unsigned int ii = 0; ii <
getLocalNum(); ii++) {
1533 px[
Bin[ii]] +=
P[ii](0);
1534 py[Bin[ii]] +=
P[ii](1);
1539 for (
int ii = 0; ii < emittedBins; ii++) {
1545 meanPhi /= emittedBins;
1556 template <
class T,
unsigned Dim>
1563 size_t partInBin[maxbin];
1564 for (
int ii = 0; ii < maxbin; ii++) partInBin[ii] = 0;
1566 double pMin0 = 1.0e9;
1568 double maxbinIndex = 0;
1572 if (pMin0 > temp_betagamma)
1573 pMin0 = temp_betagamma;
1578 double asinh0 = std::asinh(pMin);
1582 int itsBinID =
std::floor((std::asinh(temp_betagamma) - asinh0) / eta + 1.0E-6);
1584 if (maxbinIndex < itsBinID) {
1585 maxbinIndex = itsBinID;
1588 if (itsBinID >= maxbin) {
1589 ERRORMSG(
"The bin number limit is " << maxbin <<
", please increase the energy interval and try again" <<
endl);
1592 partInBin[itsBinID]++;
1607 template <
class T,
unsigned Dim>
1610 std::size_t partInBin[maxbin];
1611 for (
int i = 0; i < maxbin; ++i) {
1616 partInBin[
Bin[i]]++;
1629 template <
class T,
unsigned Dim>
1635 template <
class T,
unsigned Dim>
1641 template <
class T,
unsigned Dim>
1647 template <
class T,
unsigned Dim>
1653 template <
class T,
unsigned Dim>
1658 template <
class T,
unsigned Dim>
1664 template <
class T,
unsigned Dim>
1669 template <
class T,
unsigned Dim>
1675 template <
class T,
unsigned Dim>
1681 template <
class T,
unsigned Dim>
1687 template <
class T,
unsigned Dim>
1693 template <
class T,
unsigned Dim>
1699 template <
class T,
unsigned Dim>
1705 template <
class T,
unsigned Dim>
1711 template <
class T,
unsigned Dim>
1717 template <
class T,
unsigned Dim>
1723 template <
class T,
unsigned Dim>
1729 template <
class T,
unsigned Dim>
1735 template <
class T,
unsigned Dim>
1741 template <
class T,
unsigned Dim>
1747 template <
class T,
unsigned Dim>
1753 template <
class T,
unsigned Dim>
1758 template <
class T,
unsigned Dim>
1766 os << std::scientific;
1768 os <<
"* ************** B U N C H ********************************************************* \n";
1778 os <<
"* rms momenta = " << std::setw(12) << std::setprecision(5) <<
get_prms() <<
" [beta gamma]\n";
1780 os <<
"* mean momenta = " << std::setw(12) << std::setprecision(5) <<
get_pmean() <<
" [beta gamma]\n";
1781 os <<
"* rms emittance = " << std::setw(12) << std::setprecision(5) <<
get_emit() <<
" (not normalized)\n";
1782 os <<
"* rms correlation = " << std::setw(12) << std::setprecision(5) <<
get_rprms() <<
"\n";
1785 os <<
"* dh = " << std::setw(13) << std::setprecision(5) <<
dh_m * 100 <<
" [%]\n";
1789 os <<
"* ********************************************************************************** " <<
endl;
1796 template <
class T,
unsigned Dim>
1798 double thetaXY =
atan2(y, x);
1804 template <
class T,
unsigned Dim>
1805 Inform& operator<<(Inform &os, PartBunchBase<T, Dim>& p) {
1814 template <
class T,
unsigned Dim>
1816 throw OpalException(
"PartBunchBase<T, Dim>::runTests() ",
"No test supported.");
1820 template <
class T,
unsigned Dim>
1825 template <
class T,
unsigned Dim>
1829 std::swap(
R[i],
R[j]);
1830 std::swap(
P[i],
P[j]);
1831 std::swap(
Q[i],
Q[j]);
1832 std::swap(
M[i],
M[j]);
1833 std::swap(
Phi[i],
Phi[j]);
1834 std::swap(
Ef[i],
Ef[j]);
1836 std::swap(
Bf[i],
Bf[j]);
1837 std::swap(
Bin[i],
Bin[j]);
1838 std::swap(
dt[i],
dt[j]);
1847 template <
class T,
unsigned Dim>
1849 throw OpalException(
"PartBunchBase<T, Dim>::setBCAllPeriodic() ",
"Not supported BC.");
1853 template <
class T,
unsigned Dim>
1855 throw OpalException(
"PartBunchBase<T, Dim>::setBCAllOpen() ",
"Not supported BC.");
1859 template <
class T,
unsigned Dim>
1861 throw OpalException(
"PartBunchBase<T, Dim>::setBCForDCBeam() ",
"Not supported BC.");
1865 template <
class T,
unsigned Dim>
1870 template <
class T,
unsigned Dim>
1905 template <
class T,
unsigned Dim>
1907 return pbase_m->getTotalNum();
1910 template <
class T,
unsigned Dim>
1912 return pbase_m->getLocalNum();
1916 template <
class T,
unsigned Dim>
1918 return pbase_m->getDestroyNum();
1921 template <
class T,
unsigned Dim>
1923 return pbase_m->getGhostNum();
1926 template <
class T,
unsigned Dim>
1931 template <
class T,
unsigned Dim>
1936 template <
class T,
unsigned Dim>
1941 template <
class T,
unsigned Dim>
1946 template <
class T,
unsigned Dim>
1948 return pbase_m->getUpdateFlag(f);
1951 template <
class T,
unsigned Dim>
1953 pbase_m->setUpdateFlag(f, val);
1956 template <
class T,
unsigned Dim>
1958 return pbase_m->singleInitNode();
1961 template <
class T,
unsigned Dim>
1966 template <
class T,
unsigned Dim>
1975 template <
class T,
unsigned Dim>
1984 template <
class T,
unsigned Dim>
1989 template <
class T,
unsigned Dim>
1994 template <
class T,
unsigned Dim>
1999 template <
class T,
unsigned Dim>
2001 pbase_m->destroy(M, I, doNow);
2004 template <
class T,
unsigned Dim>
2006 pbase_m->performDestroy(updateLocalNum);
2009 template <
class T,
unsigned Dim>
2014 template <
class T,
unsigned Dim>
2019 template <
class T,
unsigned Dim>
2024 for (
unsigned int i = 0; i <
Dim; i++) {
2030 for (
unsigned int i = 0; i < 2 *
Dim; i++) {
2031 for (
unsigned int j = 0; j <= i; j++) {
2033 sigmaMatrix[j][i] = sigmaMatrix[i][j];
A templated representation for vectors.
void resetBins()
If the bunch object rebins we need to call resetBins()
static OpalData * getInstance()
Tps< T > sqrt(const Tps< T > &x)
Square root.
ParticleOrigin refPOrigin_m
ParticleAttrib< short > cavityGapCrossed
virtual void setZ(int i, double zcoo)
double get_rmsDensity() const
void setTotalNum(size_t n)
constexpr double c
The velocity of light in m/s.
double getPx() const
Get horizontal momentum (no dimension).
void push_back(OpalParticle const &p)
void setMass(double mass)
double getStdKineticEnergy() const
Vector_t getNormalizedEmittance() const
Vector_t getStandardDeviationPosition() const
void setGlobalToLocalQuaternion(Quaternion_t globalToLocalQuaternion)
size_t getNumberOfEmissionSteps()
virtual double getX0(int i)
double getQ() const
The constant charge per particle.
Vector_t get95Percentile() const
static ParticleType getParticleType(const std::string &str)
Vector_t get_normalizedEps_99Percentile() const
ParticleAttrib< ParticleOrigin > POrigin
Vector_t getNormalizedEmittance99_99Percentile() const
virtual void do_binaryRepart()
void setPBins(PartBins *pbin)
ParticleAttrib< int > TriID
double calculateAngle(double x, double y)
angle range [0~2PI) degree
IpplTimings::TimerRef boundpUpdateTimer_m
void setLocalBinCount(size_t num, int bin)
constexpr double two_pi
The value of .
virtual void setBCForDCBeam()
void setLocalTrackStep(long long n)
step in a TRACK command
Vector_t getGlobalMeanR()
std::pair< Vector_t, double > getLocalBoundingSphere()
long long globalTrackStep_m
if multiple TRACK commands
void setGlobalTrackStep(long long n)
step in multiple TRACK commands
size_t getTotalNumPerBin(int b)
How many particles are in the bin b.
std::pair< Vector_t, double > getBoundingSphere()
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
virtual void initialize(FieldLayout_t *fLayout)=0
void createWithID(unsigned id)
Vector_t get_emit() const
void setMassZeroPart(double mass)
Vector_t get_rprms() const
Vector_t hr_m
meshspacing of cartesian mesh
ParticleAttrib< Vector_t > P
size_t emitParticles(PartBunchBase< double, 3 > *beam, double eZ)
void switchOffUnitlessPositions(bool use_dt_per_particle=false)
virtual void addAttribute(ParticleAttribBase &pa)=0
std::vector< size_t > bunchLocalNum_m
ParticleAttrib< ParticleType > PType
size_t getDestroyNum() const
std::unique_ptr< double[]> bingamma_m
holds the gamma of the bin
Vektor< double, 3 > Vector_t
int getLastEmittedEnergyBin()
void computeMeanKineticEnergy(PartBunchBase< double, 3 > const &)
IpplTimings::TimerRef distrCreate_m
virtual double getPx0(int i)
DistributionMoments momentsComputer_m
Vector_t getStandardDeviationRP() const
void destroy(size_t M, size_t I, bool doNow=false)
ParticleAttrib< Vector_t > Ef
Inform & print(Inform &os)
Vector_t get_centroid() const
void setPType(const std::string &type)
void calcGammas()
Compute the gammas of all bins.
ParticleAttrib< short > bunchNum
Vektor< int, 3 > nr_m
meshsize of cartesian mesh
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
double getCouplingConstant() const
Vector_t get_pmean_Distribution() const
ParticleAttrib< double > M
long long localTrackStep_m
step in a TRACK command
long long getLocalTrackStep() const
double getPercentageEmitted() const
Vector_t get_pmean() const
void calcBeamParameters()
int distDump_m
counter to store the distribution dump
UnitState_t stateOfLastBoundP_
An abstract sequence of beam line components.
void bounds(const PETE_Expr< T1 > &expr, Vektor< T2, D > &minval, Vektor< T2, D > &maxval)
void createOpalT(PartBunchBase< double, 3 > *beam, std::vector< Distribution * > addedDistributions, size_t &numberOfParticles)
const Vector_t & getR() const
Get position in m.
ParticleLayout< T, Dim > & getLayout()
double getPy() const
Get vertical momentum (no dimension).
double getBeta() const
The relativistic beta per particle.
void setUpdateFlag(UpdateFlags_t f, bool val)
IpplTimings::TimerRef boundpBoundsTimer_m
double getM() const
The constant mass per particle.
Vector_t get_rrms() const
virtual void updateFields(const Vector_t &hr, const Vector_t &origin)
double getQ() const
Access to reference data.
virtual Vector_t get_hr() const
Inform & endl(Inform &inf)
size_t getGhostNum() const
double get_plasmaParameter() const
double getTemperature() const
Vector_t getMeanPosition() const
Vector_t getNormalizedEmittance99Percentile() const
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
virtual double getinteractionRadius() const
Vector_t get_prms() const
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
double getEmissionDeltaT()
std::unique_ptr< std::ofstream > f_stream
size_t getNumberOfEmissionSteps()
void resetPartInBin_cyc(size_t newPartNum[], int binID)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
void setTEmission(double t)
virtual double getY0(int i)
ParticleAttrib< double > Phi
void setSteptoLastInj(int n)
ParticleAttrib< Vector_t > Bf
size_t emitParticles(double eZ)
Emit particles in the given bin i.e. copy the particles from the bin structure into the particle cont...
virtual double getPz(int i)
double getPlasmaParameter() const
Vector_t get68Percentile() const
virtual double getZ(int i)
static void startTimer(TimerRef t)
std::ios_base::fmtflags FmtFlags_t
void update(PyOpalObjectNS::PyOpalObject< C > pyelement)
void setBeamFrequency(double v)
ParticleOrigin getPOrigin() const
std::string getTimeString(double time, unsigned int precision=3)
void switchToUnitlessPositions(bool use_dt_per_particle=false)
IpplTimings::TimerRef statParamTimer_m
IpplTimings::TimerRef selfFieldTimer_m
timer for selfField calculation
double getInitialGamma() const
virtual const std::string & where() const
virtual void set_meshEnlargement(double dh)
void setTotalNumPerBunch(size_t numpart, short n)
std::vector< size_t > bunchTotalNum_m
number of particles per bunch
Vector_t getNormalizedEmittance95Percentile() const
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
size_t getTotalNum() const
size_t getLoadBalance(int p) const
void setParticle(FVector< double, 6 > z, int ii)
double spos_m
the position along design trajectory
virtual void resetInterpolationCache(bool clearCache=false)
The base class for all OPAL exceptions.
Vector_t getGeometricEmittance() const
FieldLayout_t * getFieldLayout()
int getStepsPerTurn() const
Vector_t get_origin() const
void setEnergyBins(int numberOfEnergyBins)
void setPartNum(int bin, long long num)
FieldSolver * fs_m
stores the used field solver
ParticleType getPType() const
ParticleAttrib< Vector_t > Eftmp
size_t getLocalNum() const
int getNumberOfEnergyBins()
double getPz() const
Get relative momentum error (no dimension).
virtual const char * what() const
double getInitialBeta() const
int getNumberOfEnergyBins()
double getZ() const
Get longitudinal displacement c*t in m.
FieldSolverType getFieldSolverType() const
short numBunch_m
current bunch number
double getMeanKineticEnergy() const
std::unique_ptr< size_t[]> globalPartPerNode_m
void setChargeZeroPart(double q)
IpplTimings::TimerRef distrReload_m
timer for IC, can not be in Distribution.h
void setPOrigin(ParticleOrigin)
double getEmissionDeltaT()
void calcDebyeLength()
Compute the (global) Debye length for the beam.
virtual void updateDomainLength(Vektor< int, 3 > &grid)=0
void allreduce(const T *input, T *output, int count, Op op)
long long getGlobalTrackStep() const
void setLocalNum(size_t n)
virtual double getX(int i)
IpplTimings::TimerRef boundpTimer_m
ParticleAttrib< double > Q
void setDistribution(Distribution *d, std::vector< Distribution * > addedDistributions, size_t &np)
virtual void swap(unsigned int i, unsigned int j)
std::string getEnergyString(double energyInMeV, unsigned int precision=3)
double getBinGamma(int bin)
Get gamma of one bin.
bool singleInitNode() const
Vector_t getNormalizedEmittance68Percentile() const
FMatrix< double, 2 *Dim, 2 *Dim > getSigmaMatrix() const
void getLocalBounds(Vector_t &rmin, Vector_t &rmax) const
IpplTimings::TimerRef histoTimer_m
ParticleAttrib< double > dt
const Vector_t & getP() const
Get momentum.
Quaternion_t getGlobalToLocalQuaternion()
int getLastEmittedEnergyBin()
void initSolver(PartBunchBase< double, 3 > *b)
double getChargePerParticle() const
get the macro particle charge
Vector_t get99Percentile() const
double getMassPerParticle() const
double getE() const
The constant reference Energy per particle.
virtual void setBinCharge(int bin, double q)
Set the charge of one bin to the value of q and all other to zero.
double getDebyeLength() const
void setStepsPerTurn(int n)
void get_PBounds(Vector_t &min, Vector_t &max) const
bool resetPartBinID2(const double eta)
reset Bin[] for each particle according to the method given in paper PAST-AB(064402) by G...
std::unique_ptr< Inform > pmsg_m
Vector_t get99_99Percentile() const
double getY() const
Get vertical displacement in m.
Vector_t get_rmean() const
double dt_m
holds the timestep in seconds
virtual double getY(int i)
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)
const PartData * reference
void setNumBunch(short n)
Vector_t get_norm_emit() const
std::string getChargeString(double charge, unsigned int precision=3)
void gatherLoadBalanceStatistics()
void boundp_destroyCycl()
void setGlobalMeanR(Vector_t globalMeanR)
double getMomentumTolerance() const
Get the momentum tolerance.
double dh_m
Mesh enlargement.
std::unique_ptr< size_t[]> binemitted_m
void setLocalNumPerBunch(size_t numpart, short n)
void createOpalCycl(PartBunchBase< double, 3 > *beam, size_t numberOfParticles, double current, const Beamline &bl)
void maximumAmplitudes(const FMatrix< double, 6, 6 > &D, double &axmax, double &aymax)
Return maximum amplitudes.
Vector_t get_99Percentile() const
virtual void setBCAllOpen()
void countTotalNumPerBunch()
void computeDebyeLength(PartBunchBase< double, 3 > const &, double)
Quaternion_t globalToLocalQuaternion_m
void updatePartInBin_cyc(size_t countLost[])
bool eq(double x, double y)
static TimerRef getTimer(const char *nm)
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.
double getCharge() const
get the total charge per simulation particle
virtual bool weHaveBins()
constexpr double e
The value of .
void setup(AbstractParticle< T, Dim > *pb)
void ghostDestroy(size_t M, size_t I)
Vector_t get_99_99Percentile() const
PETE_TBTree< OpNE, Index::PETE_Expr_t, PETE_Scalar< double > > ne(const Index &idx, double x)
DistributionType getType() const
OpalParticle getParticle(int ii)
void iterateEmittedBin(int binNumber)
Inform & level2(Inform &inf)
const PartData * getReference() const
void gather(const T *input, T *output, int count, int root=0)
void performDestroy(bool updateLocalNum=false)
bool fixed_grid
if the grid does not have to adapt
double get_meanKineticEnergy() const
double getP() const
The constant reference momentum per particle.
ParticleAttrib< int > Bin
short getNumBunch() const
FieldSolverType getFieldSolverType() const
Return the fieldsolver type if we have a fieldsolver.
std::shared_ptr< AbstractParticle< T, Dim > > pbase_m
Vector_t get_normalizedEps_68Percentile() const
virtual double getPy(int i)
virtual double getGamma(int i)
void compute(const std::vector< OpalParticle >::const_iterator &, const std::vector< OpalParticle >::const_iterator &)
DistributionType getDistType() const
std::string getLengthString(double spos, unsigned int precision=3)
Vector_t get_maxExtent() const
PoissonSolver * solver_m
the actual solver, should be a base object
size_t calcNumPartsOutside(Vector_t x)
returns the number of particles outside of a box defined by x
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Vector_t get_halo() const
double tEmission_m
relative enlargement of the mesh
virtual double getPy0(int i)
static void stopTimer(TimerRef t)
double getMeanGamma() const
int stepsPerTurn_m
steps per turn for OPAL-cycl
void globalCreate(size_t np)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Vector_t rmin_m
minimal extend of particles
double get_temperature() const
bool getUpdateFlag(UpdateFlags_t f) const
double t_m
holds the actual time of the integration
Vector_t getStandardDeviationMomentum() const
virtual double getBeta(int i)
virtual double getPx(int i)
Vector_t get_95Percentile() const
Vector_t get_normalizedEps_95Percentile() const
Inform & level1(Inform &inf)
double couplingConstant_m
PartBunchBase(AbstractParticle< T, Dim > *pb, const PartData *ref)
double get_debyeLength() const
virtual void setBCAllPeriodic()
Vector_t getMeanMomentum() const
size_t getTotalNumPerBunch(short n) const
FMatrix< double, 6, 6 > getMoments6x6() const
Vector_t get_pmean() const
size_t getLocalNumPerBunch(short n) const
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
double getX() const
Get horizontal position in m.
double calcMeanPhi()
calculate average angle of longitudinal direction of bins
Vector_t get_normalizedEps_99_99Percentile() const
double getMomentumTolerance() const
Vector_t get_68Percentile() const
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
int getSteptoLastInj() const
virtual void setSolver(FieldSolver *fs)
Vector_t rmax_m
maximal extend of particles
double getGamma() const
The relativistic gamma per particle.
void setCouplingConstant(double c)