OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
23#include "PartBunch/PartBunch.h"
24#include "Physics/Physics.h"
26#include "Utilities/Util.h"
27
28// Class Corrector
29// ------------------------------------------------------------------------
30
33
43
44Corrector::Corrector(const std::string& name)
45 : Component(name),
46 kickX_m(0.0),
47 kickY_m(0.0),
48 designEnergy_m(0.0),
50 kickFieldSet_m(false),
51 kickField_m(0.0) {
52}
53
56
57void Corrector::accept(BeamlineVisitor& visitor) const {
58 visitor.visitCorrector(*this);
59}
60
62 const size_t& i, const double& t, Vector_t<double, 3>& E, Vector_t<double, 3>& B) {
65
66 return apply(R, P, t, E, B);
67}
68
70 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& /*t*/,
72 if (R(2) >= 0.0 && R(2) < getElementLength()) {
73 if (!isInsideTransverse(R))
75
76 double tau = 1.0;
77 const double& dt = RefPartBunch_m->getdT();
78 const double stepSize = dt * Physics::c * P(2) / Util::getGamma(P);
79
80 if (R(2) < stepSize) {
81 tau = R(2) / stepSize + 0.5;
82 }
83 if (getElementLength() - R(2) < stepSize) {
84 tau += (getElementLength() - R(2)) / stepSize - 0.5;
85 }
86
87 B += kickField_m * tau;
88 }
89
90 return false;
91}
92
93void Corrector::initialise(PartBunch_t* bunch, double& startField, double& endField) {
94 endField = startField + getElementLength();
95 RefPartBunch_m = bunch;
96}
97
100
101void Corrector::goOnline(const double&) {
102 const double pathLength = getGeometry().getElementLength();
103 const double minLength = Physics::c * RefPartBunch_m->getdT();
104 if (pathLength < minLength) {
106 "Corrector::goOnline",
107 "length of corrector, L= " + std::to_string(pathLength)
108 + ", shorter than distance covered during one time step, dS= "
109 + std::to_string(minLength));
110 }
111
112 if (!kickFieldSet_m) {
113 const double momentum = std::sqrt(
114 std::pow(designEnergy_m, 2.0) + 2.0 * designEnergy_m * RefPartBunch_m->getM());
115 const double magnitude = momentum / (Physics::c * pathLength);
117 magnitude * RefPartBunch_m->getQ() * Vector_t<double, 3>(kickY_m, -kickX_m, 0.0);
118 }
119
120 online_m = true;
121}
122
123void Corrector::setDesignEnergy(const double& ekin, bool changeable) {
125 designEnergy_m = ekin;
126 designEnergyChangeable_m = changeable;
127 }
128 if (RefPartBunch_m) {
129 if (!kickFieldSet_m) {
130 const double pathLength = getGeometry().getElementLength();
131 const double momentum = std::sqrt(
132 std::pow(designEnergy_m, 2.0) + 2.0 * designEnergy_m * RefPartBunch_m->getM());
133 const double magnitude = momentum / (Physics::c * pathLength);
135 magnitude * RefPartBunch_m->getQ() * Vector_t<double, 3>(kickY_m, -kickX_m, 0.0);
136 }
137 }
138}
139
140bool Corrector::bends() const {
141 return false;
142}
143
144void Corrector::getDimensions(double& zBegin, double& zEnd) const {
145 zBegin = 0.0;
146 zEnd = getElementLength();
147}
148
150 return ElementType::CORRECTOR;
151}
ElementType
Definition ElementBase.h:88
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
ippl::Vector< T, Dim > Vector_t
constexpr double c
The velocity of light in m/s.
Definition Physics.h:45
double getGamma(ippl::Vector< double, 3 > p)
Definition Util.h:44
bool online_m
Definition Component.h:186
Component(const std::string &name)
Constructor with given name.
Definition Component.cpp:44
PartBunch_t * RefPartBunch_m
Definition Component.h:185
virtual StraightGeometry & getGeometry()=0
Return the corrector geometry.
virtual ~Corrector()
Definition Corrector.cpp:54
virtual void getDimensions(double &zBegin, double &zEnd) const
virtual void goOnline(const double &kineticEnergy)
virtual bool bends() const
virtual bool apply(const size_t &i, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B)
Definition Corrector.cpp:61
virtual ElementType getType() const
Get element type std::string.
double designEnergy_m
Definition Corrector.h:117
double kickX_m
Definition Corrector.h:115
bool designEnergyChangeable_m
Definition Corrector.h:118
virtual void accept(BeamlineVisitor &) const
Apply a visitor to Corrector.
Definition Corrector.cpp:57
Corrector(const std::string &name)
Constructor with given name.
Definition Corrector.cpp:44
Vector_t< double, 3 > kickField_m
Definition Corrector.h:121
double kickY_m
Definition Corrector.h:116
virtual void setDesignEnergy(const double &ekin, bool changeable=true)
virtual void initialise(PartBunch_t *bunch, double &startField, double &endField)
Definition Corrector.cpp:93
bool kickFieldSet_m
Definition Corrector.h:119
virtual void finalise()
Definition Corrector.cpp:98
bool getFlagDeleteOnTransverseExit() const
virtual double getElementLength() const
Get design length.
bool isInsideTransverse(const Vector_t< double, 3 > &r) const
virtual double getElementLength() const
Get design length.