Commit 79d7c0c6 authored by adelmann's avatar adelmann 🎗
Browse files

correct Ekin to match energy in input file

parent d5058870
......@@ -2067,6 +2067,23 @@ void PartBunch::calcBeamParameters_cycl() {
eps_m = eps_norm_m / Vector_t(betagamma);
}
void PartBunch::correctEnergy(double avrgp_m) {
const double totalNp = static_cast<double>(this->getTotalNum());
const double locNp = static_cast<double>(this->getLocalNum());
double avrgp = 0.0;
for(unsigned int k = 0; k < locNp; k++)
avrgp += sqrt(dot(P[k], P[k]));
reduce(avrgp, avrgp, OpAddAssign());
avrgp /= totalNp;
for(unsigned int k = 0; k < locNp; k++)
P[k](2) = P[k](2) - avrgp + avrgp_m;
}
void PartBunch::calcEMean() {
const double totalNp = static_cast<double>(this->getTotalNum());
......@@ -2080,17 +2097,6 @@ void PartBunch::calcEMean() {
reduce(eKin_m, eKin_m, OpAddAssign());
eKin_m /= totalNp;
/*
std::for_each(P.begin(), P.end(), [&](Vector_t x) { pm += x; });
double bega = std::sqrt(dot(pm,pm));
reduce(bega, bega, OpAddAssign());
bega /= totalNp;
double ga = std::sqrt(bega*bega + 1.0);
eKin_m = (ga-1.0) * getM() * 1e-6;
*/
}
......
......@@ -517,10 +517,10 @@ private:
double calculateAngle(double x, double y);
double calculateAngle2(double x, double y);
double pSqr(Vector_t p1, Vector_t p2) const;
public:
void calcEMean(); // update eKin_m;
void correctEnergy(double avrgp);
private:
/*
Member variables starts here
......@@ -682,12 +682,6 @@ private:
};
inline double PartBunch::pSqr(Vector_t p1, Vector_t p2) const {
return p1[0]*p2[0] + p1[0]*p2[1] + p1[0]*p2[2] + p1[1]*p2[0] + p1[1]*p2[1] + p1[1]*p2[2] + p1[2]*p2[0] + p1[2]*p2[1] + p1[2]*p2[2];
}
inline
bool PartBunch::isDcBeam() { return dcBeam_m;}
......
......@@ -2714,7 +2714,6 @@ void Distribution::GenerateGaussZ(size_t numberOfParticles) {
gsl_matrix_set (m, i, j, 0.0);
}
}
gsl_matrix_set (m,0,1, distCorr_m.at(0));
gsl_matrix_set (m,1,0, distCorr_m.at(0));
gsl_matrix_set (m,2,3, distCorr_m.at(1));
......@@ -2731,7 +2730,7 @@ void Distribution::GenerateGaussZ(size_t numberOfParticles) {
gsl_matrix_set (m,0,4, distCorr_m.at(5));
gsl_matrix_set (m,4,1, distCorr_m.at(6));
gsl_matrix_set (m,1,4, distCorr_m.at(6));
#define DISTDBG1
#ifdef DISTDBG1
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
......@@ -2758,7 +2757,7 @@ void Distribution::GenerateGaussZ(size_t numberOfParticles) {
}
}
gsl_matrix_transpose(m);
#define DISTDBG2
#ifdef DISTDBG2
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
......@@ -2818,8 +2817,8 @@ void Distribution::GenerateGaussZ(size_t numberOfParticles) {
tOrZDist_m.push_back( sigmaR_m[2]*gsl_vector_get(ry, 4));
pzDist_m.push_back(avrgpz_m +(sigmaP_m[2]*gsl_vector_get(ry, 5)));
}
}
/*
//std::for_each(v.rbegin(), v.rend(), [&](int n) { sum_of_elements += n; });
double pxm = std::accumulate(pxDist_m.begin(), pxDist_m.end(), 0.0);
......@@ -3133,7 +3132,9 @@ void Distribution::InjectBeam(PartBunch &beam) {
beam.boundp();
beam.correctEnergy(avrgpz_m);
beam.calcEMean();
}
bool Distribution::GetIfDistEmitting() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment