OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Corrector.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Corrector.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Corrector
10 // Defines the abstract interface for a orbit corrector.
11 //
12 // ------------------------------------------------------------------------
13 // Class category: AbsBeamline
14 // ------------------------------------------------------------------------
15 //
16 // $Date: 2000/03/27 09:32:31 $
17 // $Author: fci $
18 //
19 // ------------------------------------------------------------------------
20 
21 #include "AbsBeamline/Corrector.h"
24 #include "Physics/Physics.h"
26 #include "Utilities/Util.h"
27 
28 extern Inform *gmsg;
29 
30 // Class Corrector
31 // ------------------------------------------------------------------------
32 
34  Corrector("")
35 { }
36 
37 
39  Component(right),
40  kickX_m(right.kickX_m),
41  kickY_m(right.kickY_m),
42  designEnergy_m(right.designEnergy_m),
43  designEnergyChangeable_m(right.designEnergyChangeable_m),
44  kickFieldSet_m(right.kickFieldSet_m),
45  kickField_m(right.kickField_m)
46 { }
47 
48 
49 Corrector::Corrector(const std::string &name):
50  Component(name),
51  kickX_m(0.0),
52  kickY_m(0.0),
53  designEnergy_m(0.0),
54  designEnergyChangeable_m(true),
55  kickFieldSet_m(false),
56  kickField_m(0.0)
57 { }
58 
59 
61 { }
62 
63 
64 void Corrector::accept(BeamlineVisitor &visitor) const {
65  visitor.visitCorrector(*this);
66 }
67 
68 bool Corrector::apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) {
69  Vector_t &R = RefPartBunch_m->R[i];
70  Vector_t &P = RefPartBunch_m->P[i];
71 
72  return apply(R, P, t, E, B);
73 }
74 
76  const Vector_t &P,
77  const double &t,
78  Vector_t &E,
79  Vector_t &B) {
80 
81  if (R(2) >= 0.0 && R(2) < getElementLength()) {
82  if (!isInsideTransverse(R)) return true;
83 
84  double tau = 1.0;
85  const double &dt = RefPartBunch_m->getdT();
86  const double stepSize = dt * Physics::c * P(2) / Util::getGamma(P);
87 
88  if (R(2) < stepSize) {
89  tau = R(2) / stepSize + 0.5;
90  }
91  if (getElementLength() - R(2) < stepSize) {
92  tau += (getElementLength() - R(2)) / stepSize - 0.5;
93  }
94 
95  B += kickField_m * tau;
96  }
97 
98  return false;
99 }
100 
101 void Corrector::initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) {
102  endField = startField + getElementLength();
103  RefPartBunch_m = bunch;
104 }
105 
107 { }
108 
109 void Corrector::goOnline(const double &) {
110  const double pathLength = getGeometry().getElementLength();
111  const double minLength = Physics::c * RefPartBunch_m->getdT();
112  if (pathLength < minLength) {
113  throw GeneralClassicException("Corrector::goOnline",
114  "length of corrector, L= " + std::to_string(pathLength) +
115  ", shorter than distance covered during one time step, dS= " + std::to_string(minLength));
116  }
117 
118  if (!kickFieldSet_m) {
119  const double momentum = sqrt(std::pow(designEnergy_m, 2.0) + 2.0 * designEnergy_m * RefPartBunch_m->getM());
120  const double magnitude = momentum / (Physics::c * pathLength);
121  kickField_m = magnitude * RefPartBunch_m->getQ() * Vector_t(kickY_m, -kickX_m, 0.0);
122  }
123 
124  online_m = true;
125 }
126 
127 void Corrector::setDesignEnergy(const double& ekin, bool changeable) {
129  designEnergy_m = ekin;
130  designEnergyChangeable_m = changeable;
131  }
132  if (RefPartBunch_m) {
133  if (!kickFieldSet_m) {
134  const double pathLength = getGeometry().getElementLength();
135  const double momentum = sqrt(std::pow(designEnergy_m, 2.0) + 2.0 * designEnergy_m * RefPartBunch_m->getM());
136  const double magnitude = momentum / (Physics::c * pathLength);
137  kickField_m = magnitude * RefPartBunch_m->getQ() * Vector_t(kickY_m, -kickX_m, 0.0);
138  }
139  }
140 }
141 
142 bool Corrector::bends() const {
143  return false;
144 }
145 
146 void Corrector::getDimensions(double &zBegin, double &zEnd) const
147 {
148  zBegin = 0.0;
149  zEnd = getElementLength();
150 }
151 
153  return CORRECTOR;
154 }
virtual ElementBase::ElementType getType() const
Get element type std::string.
Definition: Corrector.cpp:152
ParticleAttrib< Vector_t > P
virtual void accept(BeamlineVisitor &) const
Apply a visitor to Corrector.
Definition: Corrector.cpp:64
virtual void finalise()
Definition: Corrector.cpp:106
double kickY_m
Definition: Corrector.h:116
Vector_t kickField_m
Definition: Corrector.h:121
bool kickFieldSet_m
Definition: Corrector.h:119
double getdT() const
Inform * gmsg
Definition: Main.cpp:21
double getM() const
Interface for general corrector.
Definition: Corrector.h:35
bool online_m
Definition: Component.h:201
virtual bool bends() const
Definition: Corrector.cpp:142
virtual void goOnline(const double &kineticEnergy)
Definition: Corrector.cpp:109
virtual void setDesignEnergy(const double &ekin, bool changeable=true)
Definition: Corrector.cpp:127
double getGamma(Vector_t p)
Definition: Util.h:24
virtual void getDimensions(double &zBegin, double &zEnd) const
Definition: Corrector.cpp:146
bool designEnergyChangeable_m
Definition: Corrector.h:118
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:511
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:200
virtual StraightGeometry & getGeometry()=0
Return the corrector geometry.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
virtual void visitCorrector(const Corrector &)=0
Apply the algorithm to a closed orbit corrector.
double getQ() const
Access to reference data.
const std::string name
virtual double getElementLength() const
Get design length.
virtual ~Corrector()
Definition: Corrector.cpp:60
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField)
Definition: Corrector.cpp:101
double designEnergy_m
Definition: Corrector.h:117
ParticlePos_t & R
bool isInsideTransverse(const Vector_t &r, double f=1) const
Definition: ElementBase.h:645
Interface for a single beam element.
Definition: Component.h:51
Abstract algorithm.
Definition: Inform.h:41
double kickX_m
Definition: Corrector.h:115
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
Definition: Corrector.cpp:68