OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
32
34 : Component(right),
35 kickX_m(right.kickX_m),
36 kickY_m(right.kickY_m),
37 designEnergy_m(right.designEnergy_m),
38 designEnergyChangeable_m(right.designEnergyChangeable_m),
39 kickFieldSet_m(right.kickFieldSet_m),
40 kickField_m(right.kickField_m) {}
41
42Corrector::Corrector(const std::string& name)
43 : Component(name),
44 kickX_m(0.0),
45 kickY_m(0.0),
46 designEnergy_m(0.0),
47 designEnergyChangeable_m(true),
48 kickFieldSet_m(false),
49 kickField_m(0.0) {}
50
52
53void Corrector::accept(BeamlineVisitor& visitor) const { visitor.visitCorrector(*this); }
54
56 const size_t& i, const double& t, Vector_t<double, 3>& E, Vector_t<double, 3>& B) {
59
60 return apply(R, P, t, E, B);
61}
62
64 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& /*t*/,
66 if (R(2) >= 0.0 && R(2) < getElementLength()) {
68
69 double tau = 1.0;
70 const double& dt = RefPartBunch_m->getdT();
71 const double stepSize = dt * Physics::c * P(2) / Util::getGamma(P);
72
73 if (R(2) < stepSize) {
74 tau = R(2) / stepSize + 0.5;
75 }
76 if (getElementLength() - R(2) < stepSize) {
77 tau += (getElementLength() - R(2)) / stepSize - 0.5;
78 }
79
80 B += kickField_m * tau;
81 }
82
83 return false;
84}
85
86void Corrector::initialise(PartBunch_t* bunch, double& startField, double& endField) {
87 endField = startField + getElementLength();
88 RefPartBunch_m = bunch;
89}
90
92
93void Corrector::goOnline(const double&) {
94 const double pathLength = getGeometry().getElementLength();
95 const double minLength = Physics::c * RefPartBunch_m->getdT();
96 if (pathLength < minLength) {
98 "Corrector::goOnline",
99 "length of corrector, L= " + std::to_string(pathLength)
100 + ", shorter than distance covered during one time step, dS= "
101 + std::to_string(minLength));
102 }
103
104 if (!kickFieldSet_m) {
105 const auto pc = RefPartBunch_m->getParticleContainer();
106 const double momentum = std::sqrt(
107 std::pow(designEnergy_m, 2.0) + 2.0 * designEnergy_m * pc->getTotalMass());
108 const double magnitude = momentum / (Physics::c * pathLength);
110 magnitude * pc->getTotalCharge() * Vector_t<double, 3>(kickY_m, -kickX_m, 0.0);
111 }
112
113 online_m = true;
114}
115
116void Corrector::setDesignEnergy(const double& ekin, bool changeable) {
118 designEnergy_m = ekin;
119 designEnergyChangeable_m = changeable;
120 }
121 if (RefPartBunch_m) {
122 if (!kickFieldSet_m) {
123 const auto pc = RefPartBunch_m->getParticleContainer();
124 const double pathLength = getGeometry().getElementLength();
125 const double momentum = std::sqrt(
126 std::pow(designEnergy_m, 2.0) + 2.0 * designEnergy_m * pc->getTotalMass());
127 const double magnitude = momentum / (Physics::c * pathLength);
129 magnitude * pc->getTotalCharge() * Vector_t<double, 3>(kickY_m, -kickX_m, 0.0);
130 }
131 }
132}
133
134bool Corrector::bends() const { return false; }
135
136void Corrector::getFieldExtend(double& zBegin, double& zEnd) const {
137 zBegin = 0.0;
138 zEnd = getElementLength();
139}
140
141ElementType Corrector::getType() const { return ElementType::CORRECTOR; }
ippl::Vector< T, Dim > Vector_t
ElementType
Definition ElementBase.h:94
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
bool online_m
Definition Component.h:226
PartBunch_t * RefPartBunch_m
Definition Component.h:225
Interface for general corrector.
Definition Corrector.h:35
virtual StraightGeometry & getGeometry()=0
Return the corrector geometry.
virtual ~Corrector()
Definition Corrector.cpp:51
virtual void goOnline(const double &kineticEnergy)
Definition Corrector.cpp:93
virtual bool bends() const
virtual bool apply(const size_t &i, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B)
Apply to particle i.
Definition Corrector.cpp:55
virtual ElementType getType() const
Get element type std::string.
double designEnergy_m
Definition Corrector.h:110
double kickX_m
Definition Corrector.h:108
bool designEnergyChangeable_m
Definition Corrector.h:111
virtual void accept(BeamlineVisitor &) const
Apply a visitor to Corrector.
Definition Corrector.cpp:53
Vector_t< double, 3 > kickField_m
Definition Corrector.h:114
virtual void getFieldExtend(double &zBegin, double &zEnd) const
Return the field-support extent of the component.
double kickY_m
Definition Corrector.h:109
virtual void setDesignEnergy(const double &ekin, bool changeable=true)
virtual void initialise(PartBunch_t *bunch, double &startField, double &endField)
Definition Corrector.cpp:86
bool kickFieldSet_m
Definition Corrector.h:112
virtual void finalise()
Definition Corrector.cpp:91
bool getFlagDeleteOnTransverseExit() const
virtual double getElementLength() const
Get design length.
bool isInsideTransverse(const Vector_t< double, 3 > &r) const
Vector_t< double, Dim > R(size_t)
Do not use; throws (access positions via ParticleContainer::R).
Definition PartBunch.h:611
double getdT() const
Get the global time step.
Definition PartBunch.h:642
Vector_t< double, Dim > P(size_t)
Do not use; throws (access momenta via ParticleContainer::P).
Definition PartBunch.h:620
virtual double getElementLength() const
Get design length.
constexpr double c
The velocity of light in m/s.
Definition Physics.h:60
double getGamma(ippl::Vector< double, 3 > p)
Definition Util.h:44