OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
TravelingWave.h
Go to the documentation of this file.
1//
2// Class TravelingWave
3// Defines the abstract interface for Traveling Wave.
4//
5// Copyright (c) 200x - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef CLASSIC_TravelingWave_HH
19#define CLASSIC_TravelingWave_HH
20
22#include "Physics/Physics.h"
23
24#include <cmath>
25
26class Fieldmap;
27
28class TravelingWave: public RFCavity {
29
30public:
31
33 explicit TravelingWave(const std::string& name);
34
37 virtual ~TravelingWave();
38
40 virtual void accept(BeamlineVisitor&) const override;
41
43 virtual double getAmplitude() const override = 0;
44
46 virtual double getFrequency() const override = 0;
47
49 virtual double getPhase() const override = 0;
50
51 virtual void setPhasem(double phase) override;
52
53 void setNumCells(int NumCells);
54
55 void setMode(double mode);
56
57 virtual double getAutoPhaseEstimate(const double& E0, const double& t0, const double& q, const double& m) override;
58
59 virtual bool apply(const size_t& i, const double& t, Vector_t& E, Vector_t& B) override;
60
61 virtual bool apply(const Vector_t& R, const Vector_t& P, const double& t, Vector_t& E, Vector_t& B) override;
62
63 virtual bool applyToReferenceParticle(const Vector_t& R, const Vector_t& P, const double& t, Vector_t& E, Vector_t& B) override;
64
65 virtual void initialise(PartBunchBase<double, 3>* bunch, double& startField, double& endField) override;
66
67 virtual void finalise() override;
68
69 virtual bool bends() const override;
70
71 virtual void goOnline(const double& kineticEnergy) override;
72
73 virtual void goOffline() override;
74
75 virtual ElementType getType() const override;
76
77 virtual void getDimensions(double& zBegin, double& zEnd) const override;
78
79 virtual bool isInside(const Vector_t& r) const override;
80
81 virtual void getElementDimensions(double& begin,
82 double& end) const override;
83
84 virtual CoordinateSystemTrafo getEdgeToBegin() const override;
85 virtual CoordinateSystemTrafo getEdgeToEnd() const override;
86
87private:
90
94
98
102 double mode_m;
103
104 inline double getdE(const int& i,
105 const int& I,
106 const std::vector<double>& t,
107 const double& phi,
108 const std::vector<std::pair<double, double> >& F) const;
109
110 inline double getdT(const int& i,
111 const int& I,
112 const std::vector<double>& E,
113 const std::vector<std::pair<double, double> >& F,
114 const double mass) const;
115
116 inline double getdA(const int& i,
117 const int& I,
118 const std::vector<double>& t,
119 const double& phi,
120 const std::vector<std::pair<double, double> >& F) const;
121
122 inline double getdB(const int& i,
123 const int& I,
124 const std::vector<double>& t,
125 const double& phi,
126 const std::vector<std::pair<double, double> >& F) const;
127 // Not implemented.
129};
130
131double TravelingWave::getdE(const int& i,
132 const int& I,
133 const std::vector<double>& t,
134 const double& phi,
135 const std::vector<std::pair<double, double> >& F) const {
136 return (F[I].first - F[I-1].first) / (frequency_m * frequency_m * (t[i] - t[i-1]) * (t[i] - t[i-1])) *
137 (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)) +
138 (F[I].second - F[I-1].second) * (std::cos(frequency_m * t[i] + phi) - std::cos(frequency_m * t[i-1] + phi)));
139}
140
141double TravelingWave::getdT(const int& i,
142 const int& I,
143 const std::vector<double>& E,
144 const std::vector<std::pair<double, double> >& F,
145 const double mass) const {
146 double gamma1 = 1. + (19. * E[i-1] + 1. * E[i]) / (20. * mass);
147 double gamma2 = 1. + (17. * E[i-1] + 3. * E[i]) / (20. * mass);
148 double gamma3 = 1. + (15. * E[i-1] + 5. * E[i]) / (20. * mass);
149 double gamma4 = 1. + (13. * E[i-1] + 7. * E[i]) / (20. * mass);
150 double gamma5 = 1. + (11. * E[i-1] + 9. * E[i]) / (20. * mass);
151 double gamma6 = 1. + (9. * E[i-1] + 11. * E[i]) / (20. * mass);
152 double gamma7 = 1. + (7. * E[i-1] + 13. * E[i]) / (20. * mass);
153 double gamma8 = 1. + (5. * E[i-1] + 15. * E[i]) / (20. * mass);
154 double gamma9 = 1. + (3. * E[i-1] + 17. * E[i]) / (20. * mass);
155 double gamma10 = 1. + (1. * E[i-1] + 19. * E[i]) / (20. * mass);
156 return (F[I].first - F[I-1].first) *
157 (1. / std::sqrt(1. - 1. / (gamma1 * gamma1)) +
158 1. / std::sqrt(1. - 1. / (gamma2 * gamma2)) +
159 1. / std::sqrt(1. - 1. / (gamma3 * gamma3)) +
160 1. / std::sqrt(1. - 1. / (gamma4 * gamma4)) +
161 1. / std::sqrt(1. - 1. / (gamma5 * gamma5)) +
162 1. / std::sqrt(1. - 1. / (gamma6 * gamma6)) +
163 1. / std::sqrt(1. - 1. / (gamma7 * gamma7)) +
164 1. / std::sqrt(1. - 1. / (gamma8 * gamma8)) +
165 1. / std::sqrt(1. - 1. / (gamma9 * gamma9)) +
166 1. / std::sqrt(1. - 1. / (gamma10 * gamma10))) / (10. * Physics::c);
167}
168
169double TravelingWave::getdA(const int& i,
170 const int& I,
171 const std::vector<double>& t,
172 const double& phi,
173 const std::vector<std::pair<double, double> >& F) const {
174 double dt = t[i] - t[i-1];
175 return (F[I].first - F[I-1].first) / (frequency_m * frequency_m * dt * dt) *
176 (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)) -
177 (F[I].second - F[I-1].second) * (std::sin(frequency_m * t[i] + phi) - std::sin(frequency_m * t[i-1] + phi)));
178}
179
180double TravelingWave::getdB(const int& i,
181 const int& I,
182 const std::vector<double>& t,
183 const double& phi,
184 const std::vector<std::pair<double, double> >& F) const {
185 double dt = t[i] - t[i-1];
186 return (F[I].first - F[I-1].first) / (frequency_m * frequency_m * dt * dt) *
187 (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)) +
188 (F[I].second - F[I-1].second) * (std::cos(frequency_m * t[i] + phi) - std::cos(frequency_m * t[i-1] + phi)));
189}
190
191inline
192void TravelingWave::setPhasem(double phase) {
193 phase_m = phase;
197}
198
199inline
200void TravelingWave::setNumCells(int NumCells) {
201 numCells_m = NumCells;
202}
203
204inline
205void TravelingWave::setMode(double mode) {
206 mode_m = mode;
207}
208
209inline
212 Quaternion(1, 0, 0, 0));
213 return ret;
214}
215
216inline
219 Quaternion(1, 0, 0, 0));
220 return ret;
221}
222
223#endif // CLASSIC_TravelingWave_HH
ElementType
Definition: ElementBase.h:88
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
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
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:45
constexpr double pi
The value of.
Definition: Physics.h:30
double frequency_m
Definition: RFCavity.h:211
virtual double getElementLength() const override
Get design length.
Definition: RFCavity.cpp:723
double phase_m
Definition: RFCavity.h:209
double periodLength_m
Definition: TravelingWave.h:99
double mappedStartExitField_m
Definition: TravelingWave.h:97
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 ElementType getType() const override
Get element type std::string.
virtual double getPhase() const override=0
Get RF phase.
double phaseCore2_m
Definition: TravelingWave.h:92
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 frequency.
void setNumCells(int NumCells)
void setMode(double mode)
double phaseExit_m
Definition: TravelingWave.h:93
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
Definition: TravelingWave.h:96
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 cellLength_m
double scaleCore_m
Definition: TravelingWave.h:88
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:89
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
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
Definition: TravelingWave.h:91
double startCoreField_m
Definition: TravelingWave.h:95
virtual void goOnline(const double &kineticEnergy) override
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6