Commit 5585461d authored by Christof Metzger-Kraus's avatar Christof Metzger-Kraus
Browse files

fixing #162; was introduced when both SBend and RBend were rewritten to be...

fixing #162; was introduced when both SBend and RBend were rewritten to be derived from 'Bend' class
parent 210365e3
......@@ -192,7 +192,7 @@ bool Bend::apply(const size_t &i,
const double &t,
Vector_t &E,
Vector_t &B) {
if(designRadius_m > 0.0) {
// Shift position to magnet frame.
......@@ -490,8 +490,8 @@ Vector_t Bend::calcEntranceFringeField(const Vector_t &R,
//double bYEntrance = (expFactor * engeFunc *
// (1.0 - 0.5 * trigFactor * pow(Rprime(1), 2.0)));
//double bZEntrance = expFactor * Rprime(1) * engeFuncDeriv;
// B(1) = (engeFunc *
// (1.0 - 0.5 * engeFuncSecDerivNorm * pow(Rprime(1), 2.0)));
......@@ -545,7 +545,7 @@ bool Bend::calculateMapField(const Vector_t &R, Vector_t &B) {
bool verticallyInside = (std::abs(R(1)) < 0.5 * gap_m);
bool horizontallyInside = false;
Vector_t rotationCenter(-designRadius_m * cosEntranceAngle_m, R(1), designRadius_m * sinEntranceAngle_m);
if(inMagnetCentralRegion(R)) {
if (verticallyInside) {
double deltaX = 0.0;//euclidian_norm(R - rotationCenter) - designRadius_m;
......@@ -564,14 +564,14 @@ bool Bend::calculateMapField(const Vector_t &R, Vector_t &B) {
Vector_t BEntrance(0.0), BExit(0.0);
verticallyInside = (std::abs(R(1)) < gap_m);
if (inMagnetEntranceRegion(R)) {
horizontallyInside = true;
if (verticallyInside) {
BEntrance = calcEntranceFringeField(R, R(0));
}
}
if (inMagnetExitRegion(R)) {
horizontallyInside = true;
if (verticallyInside) {
......@@ -861,7 +861,7 @@ bool Bend::findIdealBendParameters(double chordLength) {
rotationZAxis_m += Physics::pi;
}
designRadius_m = chordLength / (2.0 * std::sin(angle_m / 2.0));
fieldAmplitude_m = ((refCharge / std::abs(refCharge)) *
refBetaGamma * refMass /
(Physics::c * designRadius_m));
......@@ -1321,6 +1321,9 @@ bool Bend::setupBendGeometry(Inform &msg, double &startField, double &endField)
}
reinitialize_m = findIdealBendParameters(chordLength_m);
if (getType() == RBEND) {
setEntranceAngle(getEntranceAngle());
}
findReferenceExitOrigin(xExit_m, zExit_m);
/*
......@@ -1779,4 +1782,4 @@ bool Bend::isInside(const Vector_t &R) const {
}
return (std::abs(R(1)) < 0.5 * gap_m && inMagnetCentralRegion(R));
}
}
\ No newline at end of file
......@@ -100,7 +100,6 @@ public:
double &startField,
double &endField);
// double getBendAngle() const;
double getBendRadius() const;
double getEffectiveCenter() const;
double getEffectiveLength() const;
......
......@@ -152,8 +152,20 @@ bool RBend::findChordLength(Inform &msg,
* Find bend chord length. If this was not set by the user using the
* L (length) attribute, infer it from the field map.
*/
chordLength = std::abs(2 * getLength() * sin(0.5 * getBendAngle()) /
(sin(getEntranceAngle()) + sin(getBendAngle() - getEntranceAngle())));
const double angle = getBendAngle();
if (std::abs(angle) > 0.0) {
chordLength = 2 * getLength() * sin(0.5 * std::abs(angle)) /
(sin(getEntranceAngle()) + sin(std::abs(angle) - getEntranceAngle()));
} else {
double refMass = RefPartBunch_m->getM();
double refGamma = designEnergy_m / refMass + 1.0;
double refBetaGamma = sqrt(pow(refGamma, 2.0) - 1.0);
double refCharge = RefPartBunch_m->getQ();
double amplitude = (std::abs(bY_m) > 0.0? bY_m: bX_m);
double fieldAmplitude = refCharge * std::abs(amplitude / refCharge);
double designRadius = std::abs(refBetaGamma * refMass / (Physics::c * fieldAmplitude));
chordLength = sin(0.5 * (asin(getLength() / designRadius - sin(getEntranceAngle())) + getEntranceAngle())) * 2 * designRadius;
}
return true;
}
}
\ No newline at end of file
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