Commit 3d4f7c0f authored by kraus's avatar kraus

fix position of particles, spos and position of reference particle in temporal...

fix position of particles, spos and position of reference particle in temporal monitor; fix positioning of monitor in 3D space
parent 131ad823
...@@ -74,15 +74,17 @@ bool Monitor::apply(const size_t &i, const double &t, Vector_t &/*E*/, Vector_t ...@@ -74,15 +74,17 @@ bool Monitor::apply(const size_t &i, const double &t, Vector_t &/*E*/, Vector_t
const Vector_t &R = RefPartBunch_m->R[i]; const Vector_t &R = RefPartBunch_m->R[i];
const Vector_t &P = RefPartBunch_m->P[i]; const Vector_t &P = RefPartBunch_m->P[i];
const double &dt = RefPartBunch_m->dt[i]; const double &dt = RefPartBunch_m->dt[i];
const double recpgamma = Physics::c * dt / Util::getGamma(P); const Vector_t singleStep = Physics::c * dt * Util::getBeta(P);
const double middle = 0.5 * getElementLength();
if (online_m && type_m == SPATIAL) { if (online_m && type_m == SPATIAL) {
if (dt * R(2) < dt * middle && // multiply with dt to allow back tracking if (dt * R(2) < 0.0 &&
dt * (R(2) + P(2) * recpgamma) > dt * middle) { dt * (R(2) + singleStep(2)) > 0.0) {
double frac = (middle - R(2)) / (P(2) * recpgamma); double frac = R(2) / singleStep(2);
lossDs_m->addParticle(R + frac * recpgamma * P, lossDs_m->addParticle(R + frac * singleStep,
P, RefPartBunch_m->ID[i], t + frac * dt, 0); P,
RefPartBunch_m->ID[i],
t + frac * dt,
0);
} }
} }
...@@ -96,15 +98,15 @@ bool Monitor::applyToReferenceParticle(const Vector_t &R, ...@@ -96,15 +98,15 @@ bool Monitor::applyToReferenceParticle(const Vector_t &R,
Vector_t &) { Vector_t &) {
if (!OpalData::getInstance()->isInPrepState()) { if (!OpalData::getInstance()->isInPrepState()) {
const double dt = RefPartBunch_m->getdT(); const double dt = RefPartBunch_m->getdT();
const double recpgamma = Physics::c * dt / Util::getGamma(P); const double cdt = Physics::c * dt;
const double middle = 0.5 * getElementLength(); const Vector_t singleStep = cdt * Util::getBeta(P);
if (dt * R(2) < dt * middle && // multiply with dt to allow back tracking if (dt * R(2) < 0.0 &&
dt * (R(2) + P(2) * recpgamma) > dt * middle) { dt * (R(2) + singleStep(2)) > 0.0) {
double frac = (middle - R(2)) / (P(2) * recpgamma); double frac = -R(2) / singleStep(2);
double time = t + frac * dt; double time = t + frac * dt;
Vector_t dR = frac * P * recpgamma; Vector_t dR = frac * singleStep;
double ds = euclidean_norm(dR); double ds = euclidean_norm(dR + 0.5 * singleStep);
lossDs_m->addReferenceParticle(csTrafoGlobal2Local_m.transformFrom(R + dR), lossDs_m->addReferenceParticle(csTrafoGlobal2Local_m.transformFrom(R + dR),
csTrafoGlobal2Local_m.rotateFrom(P), csTrafoGlobal2Local_m.rotateFrom(P),
time, time,
...@@ -115,8 +117,8 @@ bool Monitor::applyToReferenceParticle(const Vector_t &R, ...@@ -115,8 +117,8 @@ bool Monitor::applyToReferenceParticle(const Vector_t &R,
const unsigned int localNum = RefPartBunch_m->getLocalNum(); const unsigned int localNum = RefPartBunch_m->getLocalNum();
for (unsigned int i = 0; i < localNum; ++ i) { for (unsigned int i = 0; i < localNum; ++ i) {
const double recpgamma = Physics::c * dt / Util::getGamma(RefPartBunch_m->P[i]); Vector_t shift = ((frac - 0.5) * cdt * Util::getBeta(RefPartBunch_m->P[i])
Vector_t shift = frac * recpgamma * RefPartBunch_m->P[i] - Vector_t(0, 0, middle); - singleStep);
lossDs_m->addParticle(RefPartBunch_m->R[i] + shift, lossDs_m->addParticle(RefPartBunch_m->R[i] + shift,
RefPartBunch_m->P[i], RefPartBunch_m->P[i],
RefPartBunch_m->ID[i], RefPartBunch_m->ID[i],
......
...@@ -107,6 +107,8 @@ public: ...@@ -107,6 +107,8 @@ public:
static void writeStatistics(); static void writeStatistics();
virtual int getRequiredNumberOfTimeSteps() const override; virtual int getRequiredNumberOfTimeSteps() const override;
virtual bool isInside(const Vector_t &r) const override;
private: private:
// Not implemented. // Not implemented.
...@@ -133,4 +135,12 @@ int Monitor::getRequiredNumberOfTimeSteps() const ...@@ -133,4 +135,12 @@ int Monitor::getRequiredNumberOfTimeSteps() const
return 1; return 1;
} }
inline
bool Monitor::isInside(const Vector_t &r) const
{
const double length = getElementLength();
return std::abs(r(2)) <= 0.5 * length && isInsideTransverse(r);
}
#endif // CLASSIC_Monitor_HH #endif // CLASSIC_Monitor_HH
\ No newline at end of file
...@@ -28,6 +28,11 @@ namespace Util { ...@@ -28,6 +28,11 @@ namespace Util {
return std::sqrt(dot(p, p) + 1.0); return std::sqrt(dot(p, p) + 1.0);
} }
inline
Vector_t getBeta(Vector_t p) {
return p / getGamma(p);
}
inline inline
double getKineticEnergy(Vector_t p, double mass) { double getKineticEnergy(Vector_t p, double mass) {
return (getGamma(p) - 1.0) * mass; return (getGamma(p) - 1.0) * mass;
...@@ -45,7 +50,7 @@ namespace Util { ...@@ -45,7 +50,7 @@ namespace Util {
double convertMomentumeVToBetaGamma(double p, double mass) { double convertMomentumeVToBetaGamma(double p, double mass) {
return p / mass; return p / mass;
} }
inline inline
std::string getTimeString(double time, unsigned int precision = 3) { std::string getTimeString(double time, unsigned int precision = 3) {
std::string timeUnit(" [ps]"); std::string timeUnit(" [ps]");
...@@ -170,7 +175,7 @@ namespace Util { ...@@ -170,7 +175,7 @@ namespace Util {
} }
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &elementName = ""); Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &elementName = "");
std::string toUpper(const std::string &str); std::string toUpper(const std::string &str);
std::string combineFilePath(std::initializer_list<std::string>); std::string combineFilePath(std::initializer_list<std::string>);
......
...@@ -291,9 +291,6 @@ void OpalBeamline::compute3DLattice() { ...@@ -291,9 +291,6 @@ void OpalBeamline::compute3DLattice() {
if (element->getType() == ElementBase::SOURCE) { if (element->getType() == ElementBase::SOURCE) {
beginThis3D(2) -= thisLength; beginThis3D(2) -= thisLength;
} }
if (element->getType() == ElementBase::MONITOR) {
beginThis3D(2) -= 0.5 * thisLength;
}
Vector_t endThis3D; Vector_t endThis3D;
if (element->getType() == ElementBase::SBEND || if (element->getType() == ElementBase::SBEND ||
......
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