Commit 96b1e5b4 authored by kraus's avatar kraus
Browse files

working version of kickers

parent 1a9033fa
......@@ -316,7 +316,7 @@ void Collimator::initialise(PartBunch *bunch, double &startField, double &endFie
lossDs_m = std::unique_ptr<LossDataSink>(new LossDataSink(filename_m.substr(0, filename_m.rfind(".")), !Options::asciidump));
}
goOnline();
goOnline(-1e6);
}
void Collimator::initialise(PartBunch *bunch, const double &scaleFactor) {
......@@ -331,7 +331,7 @@ void Collimator::initialise(PartBunch *bunch, const double &scaleFactor) {
lossDs_m = std::unique_ptr<LossDataSink>(new LossDataSink(filename_m.substr(0, filename_m.rfind(".")), !Options::asciidump));
}
goOnline();
goOnline(-1e6);
}
void Collimator::finalise()
......@@ -341,7 +341,7 @@ void Collimator::finalise()
*gmsg << "* Finalize probe" << endl;
}
void Collimator::goOnline() {
void Collimator::goOnline(const double &) {
if(RefPartBunch_m == NULL) {
if(!informed_m) {
std::string errormsg = Fieldmap::typeset_msg("BUNCH SIZE NOT SET", "warning");
......
......@@ -85,7 +85,7 @@ public:
virtual bool bends() const;
virtual void goOnline();
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
......
......@@ -87,7 +87,7 @@ trackMap(FVps<double, 6> &, const PartData &, bool, bool) const {
"Called for component \"" + getName() + "\".");
}
void Component::goOnline() {
void Component::goOnline(const double &) {
online_m = true;
}
......
......@@ -116,7 +116,7 @@ public:
// virtual bool determineEntryPoint(const double &kineticEnergy, const double &tolerance) = 0;
virtual void goOnline();
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
......@@ -207,4 +207,4 @@ inline void Component::setOrientation(const Vector_t &direction)
inline void Component::setExitFaceSlope(const double &m)
{ exit_face_slope_m = m; }
#endif // CLASSIC_Component_HH
\ No newline at end of file
#endif // CLASSIC_Component_HH
......@@ -20,7 +20,8 @@
#include "AbsBeamline/Corrector.h"
#include "AbsBeamline/BeamlineVisitor.h"
#include "Algorithms/PartBunch.h"
#include "Physics/Physics.h"
// Class Corrector
// ------------------------------------------------------------------------
......@@ -77,20 +78,28 @@ bool Corrector::apply(const Vector_t &R, const Vector_t &centroid, const double
}
void Corrector::initialise(PartBunch *bunch, double &startField, double &endField, const double &scaleFactor) {
Inform m("Corrector::initialise ");
endField_m = endField = startField + getElementLength();
RefPartBunch_m = bunch;
startField_m = startField;
BDipoleField f = getField();
kickField_m = Vector_t(f.getBx(),f.getBy(),0.0);
m << "B= " << kickField_m << endl;
}
void Corrector::finalise()
{ }
void Corrector::goOnline(const double &kineticEnergy) {
if (kineticEnergy < 0.0) {
throw GeneralClassicException("Corrector::goOnline", "given kinetic energy is negative");
}
const double pathLength = getGeometry().getElementLength();
const double momentum = sqrt(std::pow(kineticEnergy * 1e6, 2.0) + 2.0 * kineticEnergy * 1e6 * RefPartBunch_m->getM());
const double magnitude = momentum / (Physics::c * pathLength);
kickField_m = magnitude * RefPartBunch_m->getQ() * Vector_t(kickY_m, -kickX_m, 0.0);
INFOMSG("Corrector::goOnline " << "at Ekin= " << kineticEnergy << " MeV, B= " << kickField_m << " T"<< endl);
online_m = true;
}
bool Corrector::bends() const {
return false;
}
......@@ -104,12 +113,4 @@ void Corrector::getDimensions(double &zBegin, double &zEnd) const
const std::string &Corrector::getType() const {
static const std::string type("Corrector");
return type;
}
void Corrector::SetKickX(double k) {kickX_m = k; }
void Corrector::SetKickY(double k) {kickY_m = k; }
double Corrector::GetKickX() const {return kickX_m; }
double Corrector::GetKickY() const {return kickY_m; }
}
\ No newline at end of file
......@@ -85,6 +85,8 @@ public:
virtual void initialise(PartBunch *bunch, double &startField, double &endField, const double &scaleFactor);
virtual void goOnline(const double &kineticEnergy);
virtual void finalise();
virtual bool bends() const;
......@@ -93,16 +95,16 @@ public:
virtual void getDimensions(double &zBegin, double &zEnd) const;
void SetKickX(double k);
void setKickX(double k);
void SetKickY(double k);
void setKickY(double k);
double GetKickX() const;
double getKickX() const;
double GetKickY() const;
double getKickY() const;
private:
private:
double startField_m;
double endField_m;
double kickX_m;
......@@ -123,4 +125,24 @@ protected:
};
#endif // CLASSIC_Corrector_HH
inline
void Corrector::setKickX(double k) {
kickX_m = k;
}
inline
void Corrector::setKickY(double k) {
kickY_m = k;
}
inline
double Corrector::getKickX() const {
return kickX_m;
}
inline
double Corrector::getKickY() const {
return kickY_m;
}
#endif // CLASSIC_Corrector_HH
\ No newline at end of file
......@@ -185,7 +185,7 @@ bool CyclotronValley::bends() const {
}
void CyclotronValley::goOnline() {
void CyclotronValley::goOnline(const double &) {
Fieldmap::readMap(filename_m);
online_m = true;
}
......
......@@ -72,7 +72,7 @@ public:
virtual bool bends() const;
virtual void goOnline();
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
......
......@@ -166,7 +166,7 @@ void Degrader::finalise()
*gmsg << "* Finalize Degrader" << endl;
}
void Degrader::goOnline() {
void Degrader::goOnline(const double &) {
Inform msg("Degrader::goOnline ");
if(RefPartBunch_m == NULL) {
if(!informed_m) {
......@@ -245,4 +245,4 @@ void Degrader::setZSize(double z) {
double Degrader::getZSize() {
return deg_width_m;
}
}
\ No newline at end of file
......@@ -74,7 +74,7 @@ public:
virtual bool bends() const;
virtual void goOnline();
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
......
......@@ -109,7 +109,7 @@ void Monitor::finalise() {
}
void Monitor::goOnline() {
void Monitor::goOnline(const double &) {
if(RefPartBunch_m == NULL) {
if(!informed_m) {
Inform msg("Monitor ");
......
......@@ -83,7 +83,7 @@ public:
virtual bool bends() const;
virtual void goOnline();
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
......
......@@ -215,17 +215,6 @@ bool ParallelPlate::bends() const {
return false;
}
void ParallelPlate::goOnline() {
online_m = true;
}
void ParallelPlate::goOffline() {
online_m = false;
}
void ParallelPlate::getDimensions(double &zBegin, double &zEnd) const {
zBegin = startField_m;
zEnd = endField_m;
......
......@@ -82,13 +82,6 @@ public:
virtual bool bends() const;
virtual void goOnline();
virtual void goOffline();
private:
std::string filename_m; /**< The name of the inputfile*/
......@@ -106,4 +99,4 @@ private:
void operator=(const ParallelPlate &);
};
#endif // CLASSIC_ParallelPlate_HH
#endif // CLASSIC_ParallelPlate_HH
\ No newline at end of file
......@@ -129,9 +129,6 @@ void Probe::finalise() {
bool Probe::bends() const {
return false;
}
void Probe::goOnline() {
online_m = true;
}
void Probe::goOffline() {
online_m = false;
......
......@@ -57,7 +57,6 @@ public:
virtual void finalise();
virtual bool bends() const;
virtual void goOnline();
virtual void goOffline();
......@@ -107,4 +106,4 @@ private:
void operator=(const Probe &);
};
#endif // CLASSIC_Probe_HH
#endif // CLASSIC_Probe_HH
\ No newline at end of file
......@@ -297,26 +297,6 @@ bool RBend::apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) {
if(designRadius_m > 0.0) {
// Check if we need to reinitialize the bend field amplitude.
if(reinitialize_m) {
reinitialize_m = Reinitialize();
recalcRefTraj_m = false;
}
/*
* Always recalculate the reference trajectory on first call even
* if we do not reinitialize the bend. The reference trajectory
* has to be calculated at the same energy as the actual beam or
* we do not get accurate values for the magnetic field in the output
* file.
*/
if(recalcRefTraj_m) {
double angleX = 0.0;
double angleY = 0.0;
CalculateRefTrajectory(angleX, angleY);
recalcRefTraj_m = false;
}
// Shift position to magnet frame.
Vector_t X = RefPartBunch_m->X[i];
X(2) += startField_m - elementEdge_m;
......@@ -404,6 +384,31 @@ void RBend::finalise() {
online_m = false;
}
void RBend::goOnline(const double &) {
// Check if we need to reinitialize the bend field amplitude.
if(reinitialize_m) {
reinitialize_m = Reinitialize();
recalcRefTraj_m = false;
}
/*
* Always recalculate the reference trajectory on first call even
* if we do not reinitialize the bend. The reference trajectory
* has to be calculated at the same energy as the actual beam or
* we do not get accurate values for the magnetic field in the output
* file.
*/
if(recalcRefTraj_m) {
double angleX = 0.0;
double angleY = 0.0;
CalculateRefTrajectory(angleX, angleY);
recalcRefTraj_m = false;
}
online_m = true;
}
void RBend::getDimensions(double &sBegin, double &sEnd) const {
sBegin = startField_m;
sEnd = endField_m;
......@@ -1370,22 +1375,19 @@ void RBend::ReadFieldMap(Inform &msg) {
bool RBend::Reinitialize() {
if(designEnergy_m != RefPartBunch_m->get_meanEnergy() * 1.0e6) {
designEnergy_m = RefPartBunch_m->get_meanEnergy() * 1.0e6;
SetBendStrength();
double bendAngleX = 0.0;
double bendAngleY = 0.0;
CalculateRefTrajectory(bendAngleX, bendAngleY);
designEnergy_m = RefPartBunch_m->get_meanEnergy() * 1.0e6;
SetBendStrength();
double bendAngleX = 0.0;
double bendAngleY = 0.0;
CalculateRefTrajectory(bendAngleX, bendAngleY);
Inform msg("SBend ");
msg << "Bend design energy changed to: "
<< designEnergy_m * 1.0e-6
<< " MeV"
<< endl;
Print(msg, bendAngleX, bendAngleY);
Inform msg("RBend ");
msg << "Bend design energy changed to: "
<< designEnergy_m * 1.0e-6
<< " MeV"
<< endl;
Print(msg, bendAngleX, bendAngleY);
}
return false;
}
......@@ -1659,4 +1661,4 @@ bool RBend::TreatAsDrift(Inform &msg) {
} else
return false;
}
}
\ No newline at end of file
......@@ -196,6 +196,8 @@ public:
/// Indicates that element bends the beam.
virtual bool bends() const;
virtual void goOnline(const double &kineticEnergy);
virtual void finalise();
virtual void getDimensions(double &sBegin, double &sEnd) const;
virtual const std::string &getType() const;
......
......@@ -565,7 +565,7 @@ bool RFCavity::bends() const {
}
void RFCavity::goOnline() {
void RFCavity::goOnline(const double &) {
std::vector<string>::iterator fmap_it;
for(fmap_it = multiFilenames_m.begin(); fmap_it != multiFilenames_m.end(); ++ fmap_it) {
Fieldmap::readMap(*fmap_it);
......
......@@ -116,7 +116,7 @@ public:
virtual bool bends() const;
virtual void goOnline();
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
......
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