OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
TravelingWave.h
Go to the documentation of this file.
1 #ifndef CLASSIC_TravelingWave_HH
2 #define CLASSIC_TravelingWave_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: TravelingWave.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: TravelingWave
13 // Defines the abstract interface for an accelerating structure.
14 //
15 // ------------------------------------------------------------------------
16 // Class category: AbsBeamline
17 // ------------------------------------------------------------------------
18 //
19 // $Date: 2000/03/27 09:32:31 $
20 // $Author: fci $
21 //
22 // ------------------------------------------------------------------------
23 
24 
25 #include "AbsBeamline/RFCavity.h"
26 #include "Physics/Physics.h"
27 
28 class Fieldmap;
29 
30 
31 // Class TravelingWave
32 // ------------------------------------------------------------------------
34 // Class TravelingWave defines the abstract interface for Traveling Wave.
35 
36 
37 class TravelingWave: public RFCavity {
38 
39 public:
40 
41  enum CavityType { SW, TW };
43  explicit TravelingWave(const std::string &name);
44 
45  TravelingWave();
47  virtual ~TravelingWave();
48 
50  virtual void accept(BeamlineVisitor &) const override;
51 
53  virtual double getAmplitude() const override = 0;
54 
56  virtual double getFrequency() const override = 0;
57 
59  virtual double getPhase() const override = 0;
60 
61  virtual void setPhasem(double phase) override;
62 
63  void setNumCells(int NumCells);
64 
65  void setMode(double mode);
66 
67  virtual double getAutoPhaseEstimate(const double & E0, const double & t0, const double & q, const double & m) override;
68 
69  virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
70 
71  virtual bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override;
72 
73  virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override;
74 
75  virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override;
76 
77  virtual void finalise() override;
78 
79  virtual bool bends() const override;
80 
81  virtual void goOnline(const double &kineticEnergy) override;
82 
83  virtual void goOffline() override;
84 
85  virtual ElementBase::ElementType getType() const override;
86 
87  virtual void getDimensions(double &zBegin, double &zEnd) const override;
88 
89  virtual bool isInside(const Vector_t &r) const override;
90 
91  virtual void getElementDimensions(double &begin,
92  double &end) const override;
93 
94  virtual CoordinateSystemTrafo getEdgeToBegin() const override;
95  virtual CoordinateSystemTrafo getEdgeToEnd() const override;
96 
97 private:
98  double scaleCore_m;
100 
101  double phaseCore1_m;
102  double phaseCore2_m;
103  double phaseExit_m;
104 
108 
111  double CellLength_m;
112  double Mode_m;
113 
114  inline double getdE(const int & i,
115  const int & I,
116  const std::vector<double> & t,
117  const double & phi,
118  const std::vector<std::pair<double, double> > & F) const;
119 
120  inline double getdT(const int & i,
121  const int & I,
122  const std::vector<double> & E,
123  const std::vector<std::pair<double, double> > & F,
124  const double mass) const;
125 
126  inline double getdA(const int & i,
127  const int & I,
128  const std::vector<double> & t,
129  const double & phi,
130  const std::vector<std::pair<double, double> > & F) const;
131 
132  inline double getdB(const int & i,
133  const int & I,
134  const std::vector<double> & t,
135  const double & phi,
136  const std::vector<std::pair<double, double> > & F) const;
137  // Not implemented.
138  void operator=(const TravelingWave &);
139 };
140 
141 double TravelingWave::getdE(const int & i,
142  const int & I,
143  const std::vector<double> & t,
144  const double & phi,
145  const std::vector<std::pair<double, double> > & F) const {
146  return (F[I].first - F[I-1].first) / (frequency_m * frequency_m * (t[i] - t[i-1]) * (t[i] - t[i-1])) *
147  (frequency_m * (t[i] - t[i-1]) * (F[I].second * std::sin(frequency_m * t[i] + phi) - F[I-1].second * std::sin(frequency_m * t[i-1] + phi)) +
148  (F[I].second - F[I-1].second) * (std::cos(frequency_m * t[i] + phi) - std::cos(frequency_m * t[i-1] + phi)));
149 }
150 
151 double TravelingWave::getdT(const int & i,
152  const int & I,
153  const std::vector<double> & E,
154  const std::vector<std::pair<double, double> > & F,
155  const double mass) const {
156  double gamma1 = 1. + (19. * E[i-1] + 1. * E[i]) / (20. * mass);
157  double gamma2 = 1. + (17. * E[i-1] + 3. * E[i]) / (20. * mass);
158  double gamma3 = 1. + (15. * E[i-1] + 5. * E[i]) / (20. * mass);
159  double gamma4 = 1. + (13. * E[i-1] + 7. * E[i]) / (20. * mass);
160  double gamma5 = 1. + (11. * E[i-1] + 9. * E[i]) / (20. * mass);
161  double gamma6 = 1. + (9. * E[i-1] + 11. * E[i]) / (20. * mass);
162  double gamma7 = 1. + (7. * E[i-1] + 13. * E[i]) / (20. * mass);
163  double gamma8 = 1. + (5. * E[i-1] + 15. * E[i]) / (20. * mass);
164  double gamma9 = 1. + (3. * E[i-1] + 17. * E[i]) / (20. * mass);
165  double gamma10 = 1. + (1. * E[i-1] + 19. * E[i]) / (20. * mass);
166  return (F[I].first - F[I-1].first) *
167  (1. / std::sqrt(1. - 1. / (gamma1 * gamma1)) +
168  1. / std::sqrt(1. - 1. / (gamma2 * gamma2)) +
169  1. / std::sqrt(1. - 1. / (gamma3 * gamma3)) +
170  1. / std::sqrt(1. - 1. / (gamma4 * gamma4)) +
171  1. / std::sqrt(1. - 1. / (gamma5 * gamma5)) +
172  1. / std::sqrt(1. - 1. / (gamma6 * gamma6)) +
173  1. / std::sqrt(1. - 1. / (gamma7 * gamma7)) +
174  1. / std::sqrt(1. - 1. / (gamma8 * gamma8)) +
175  1. / std::sqrt(1. - 1. / (gamma9 * gamma9)) +
176  1. / std::sqrt(1. - 1. / (gamma10 * gamma10))) / (10. * Physics::c);
177 }
178 
179 double TravelingWave::getdA(const int & i,
180  const int & I,
181  const std::vector<double> & t,
182  const double & phi,
183  const std::vector<std::pair<double, double> > & F) const {
184  double dt = t[i] - t[i-1];
185  return (F[I].first - F[I-1].first) / (frequency_m * frequency_m * dt * dt) *
186  (frequency_m * dt * (F[I].second * std::cos(frequency_m * t[i] + phi) - F[I-1].second * std::cos(frequency_m * t[i-1] + phi)) -
187  (F[I].second - F[I-1].second) * (std::sin(frequency_m * t[i] + phi) - std::sin(frequency_m * t[i-1] + phi)));
188 }
189 
190 double TravelingWave::getdB(const int & i,
191  const int & I,
192  const std::vector<double> & t,
193  const double & phi,
194  const std::vector<std::pair<double, double> > & F) const {
195  double dt = t[i] - t[i-1];
196  return (F[I].first - F[I-1].first) / (frequency_m * frequency_m * dt * dt) *
197  (frequency_m * dt * (F[I].second * std::sin(frequency_m * t[i] + phi) - F[I-1].second * std::sin(frequency_m * t[i-1] + phi)) +
198  (F[I].second - F[I-1].second) * (std::cos(frequency_m * t[i] + phi) - std::cos(frequency_m * t[i-1] + phi)));
199 }
200 
201 inline
202 void TravelingWave::setPhasem(double phase) {
203  phase_m = phase;
207 }
208 
209 inline
210 void TravelingWave::setNumCells(int NumCells) {
211  NumCells_m = NumCells;
212 }
213 
214 inline
215 void TravelingWave::setMode(double mode) {
216  Mode_m = mode;
217 }
218 
219 inline
222  Quaternion(1, 0, 0, 0));
223  return ret;
224 }
225 
226 inline
229  Quaternion(1, 0, 0, 0));
230  return ret;
231 }
232 
233 #endif // CLASSIC_TravelingWave_HH
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:733
const std::string name
constexpr double two_pi
The value of.
Definition: Physics.h:33
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
constexpr double pi
The value of.
Definition: Physics.h:30
Interface for RF cavity.
Definition: RFCavity.h:37
CavityType
Definition: RFCavity.h:41
double frequency_m
Definition: RFCavity.h:221
virtual double getElementLength() const override
Get design length.
Definition: RFCavity.cpp:722
double phase_m
Definition: RFCavity.h:219
Interface for Traveling Wave.
Definition: TravelingWave.h:37
double CellLength_m
double mappedStartExitField_m
double getdA(const int &i, const int &I, const std::vector< double > &t, const double &phi, const std::vector< std::pair< double, double > > &F) const
virtual double getAmplitude() const override=0
Get RF amplitude.
virtual double getPhase() const override=0
Get RF phase.
double phaseCore2_m
virtual bool bends() const override
virtual void accept(BeamlineVisitor &) const override
Apply visitor to TravelingWave.
virtual void getDimensions(double &zBegin, double &zEnd) const override
virtual double getFrequency() const override=0
Get RF frequencey.
virtual ElementBase::ElementType getType() const override
Get element type std::string.
void setNumCells(int NumCells)
void setMode(double mode)
double phaseExit_m
void operator=(const TravelingWave &)
double getdB(const int &i, const int &I, const std::vector< double > &t, const double &phi, const std::vector< std::pair< double, double > > &F) const
virtual void setPhasem(double phase) override
virtual double getAutoPhaseEstimate(const double &E0, const double &t0, const double &q, const double &m) override
double startExitField_m
virtual bool isInside(const Vector_t &r) const override
virtual void goOffline() override
double getdE(const int &i, const int &I, const std::vector< double > &t, const double &phi, const std::vector< std::pair< double, double > > &F) const
double scaleCore_m
Definition: TravelingWave.h:98
virtual CoordinateSystemTrafo getEdgeToEnd() const override
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
virtual void finalise() override
double scaleCoreError_m
Definition: TravelingWave.h:99
virtual ~TravelingWave()
virtual CoordinateSystemTrafo getEdgeToBegin() const override
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
virtual void getElementDimensions(double &begin, double &end) const override
double PeriodLength_m
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
double getdT(const int &i, const int &I, const std::vector< double > &E, const std::vector< std::pair< double, double > > &F, const double mass) const
double phaseCore1_m
double startCoreField_m
virtual void goOnline(const double &kineticEnergy) override
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6