OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Source.cpp
Go to the documentation of this file.
1 
2 #include "AbsBeamline/Source.h"
5 #include "Fields/Fieldmap.h"
6 #include "Physics/Physics.h"
8 
9 #include <iostream>
10 #include <fstream>
11 
12 extern Inform *gmsg;
13 
14 // Class Source
15 // ------------------------------------------------------------------------
16 
18  Source("")
19 {}
20 
21 
22 Source::Source(const Source &right):
23  Component(right),
24  ElementEdge_m(right.ElementEdge_m),
25  startField_m(right.startField_m),
26  endField_m(right.endField_m)
27 {
29 }
30 
31 
32 Source::Source(const std::string &name):
33  Component(name),
34  ElementEdge_m(0.0),
35  startField_m(0.0),
36  endField_m(0.0)
37 {
39 }
40 
42 
43 }
44 
45 
46 void Source::accept(BeamlineVisitor &visitor) const {
47  visitor.visitSource(*this);
48 }
49 
55 void Source::addKR(int i, double t, Vector_t &K) {
56 }
57 
63 void Source::addKT(int i, double t, Vector_t &K) {
64 }
65 
66 bool Source::apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) {
67  const Vector_t &R = RefPartBunch_m->R[i];
68  const Vector_t &P = RefPartBunch_m->P[i];
69  const double &dt = RefPartBunch_m->dt[i];
70  const double recpgamma = Physics::c * dt / Util::getGamma(P);
71  const double end = getElementLength();
72  if (online_m && dt < 0.0) {
73  if (R(2) > end &&
74  (R(2) + P(2) * recpgamma) < end) {
75  double frac = (end - R(2)) / (P(2) * recpgamma);
76 
77  lossDs_m->addParticle(R + frac * recpgamma * P,
78  P, RefPartBunch_m->ID[i], t + frac * dt, 0);
79 
80  return true;
81  }
82  }
83 
84  return false;
85 }
86 
87 void Source::initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) {
88  RefPartBunch_m = bunch;
89  endField = startField;
90  startField -= getElementLength();
91 
92  std::string filename = getName();
93  lossDs_m = std::unique_ptr<LossDataSink>(new LossDataSink(filename,
95  getType()));
96 
97 }
98 
100 {}
101 
102 bool Source::bends() const {
103  return false;
104 }
105 
106 
107 void Source::goOnline(const double &) {
108  online_m = true;
109 }
110 
112  online_m = false;
113  lossDs_m->save();
114 }
115 
116 void Source::getDimensions(double &zBegin, double &zEnd) const {
117  zBegin = startField_m;
118  zEnd = endField_m;
119 }
120 
121 
123  return SOURCE;
124 }
ParticleAttrib< Vector_t > P
Definition: Source.h:12
virtual void visitSource(const Source &)=0
Apply the algorithm to a source.
virtual void getDimensions(double &zBegin, double &zEnd) const override
Definition: Source.cpp:116
virtual void goOnline(const double &kineticEnergy) override
Definition: Source.cpp:107
Inform * gmsg
Definition: Main.cpp:21
bool online_m
Definition: Component.h:201
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
virtual ~Source()
Definition: Source.cpp:41
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Definition: Source.cpp:66
double getGamma(Vector_t p)
Definition: Util.h:24
Source()
Definition: Source.cpp:17
ParticleIndex_t & ID
virtual bool bends() const override
Definition: Source.cpp:102
void setElType(ElemType elt)
set the element type as enumeration needed in the envelope tracker
Definition: ElementBase.h:591
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
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: Source.cpp:87
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:200
virtual void addKR(int i, double t, Vector_t &K) override
ENVELOPE COMPONENT for radial focussing of the beam Calculates the transverse envelope component for ...
Definition: Source.cpp:55
virtual ElementBase::ElementType getType() const override
Get element type std::string.
Definition: Source.cpp:122
ParticleAttrib< double > dt
bool asciidump
Definition: Options.cpp:18
virtual void addKT(int i, double t, Vector_t &K) override
Definition: Source.cpp:63
double startField_m
Definition: Source.h:49
std::unique_ptr< LossDataSink > lossDs_m
Definition: Source.h:52
const std::string name
virtual void finalise() override
Definition: Source.cpp:99
ParticlePos_t & R
Interface for a single beam element.
Definition: Component.h:51
#define K
Definition: integrate.cpp:118
Abstract algorithm.
Definition: Inform.h:41
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Source.
Definition: Source.cpp:46
double endField_m
Definition: Source.h:50
virtual void goOffline() override
Definition: Source.cpp:111