OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Component.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Component.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Component
10 // An abstract base class which defines the common interface for all
11 // CLASSIC components, i.e. beamline members which are not themselves
12 // beamlines.
13 //
14 // ------------------------------------------------------------------------
15 // Class category: AbsBeamline
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2000/03/27 09:32:31 $
19 // $Author: fci $
20 //c
21 // ------------------------------------------------------------------------
22 
23 #include "AbsBeamline/Component.h"
24 #include "Utilities/LogicalError.h"
26 
27 // Class Component
28 // ------------------------------------------------------------------------
29 // Represents an arbitrary component in an accelerator. A component is
30 // the basic element in the accelerator model, and can be thought of as
31 // acting as a leaf in the Composite pattern. A Component is associated
32 // with an electromagnetic field.
33 // 2017-03-20 (Rogers) set default aperture to something huge; else we get a
34 // segmentation fault by default from NULL dereference during tracking
35 
36 const std::vector<double> Component::defaultAperture_m =
37  std::vector<double>({1e6, 1e6, 1.0});
38 
39 
41  Component("")
42 {}
43 
44 
46  ElementBase(right),
47  exit_face_slope_m(right.exit_face_slope_m),
48  RefPartBunch_m(right.RefPartBunch_m),
49  online_m(right.online_m) {
50 }
51 
52 
53 Component::Component(const std::string &name):
55  exit_face_slope_m(0.0),
56  RefPartBunch_m(NULL),
57  online_m(false) {
59 
60 }
61 
62 
64 {}
65 
66 
68  return *this;
69 }
70 
71 void Component::trackBunch(PartBunchBase<double, 3> *, const PartData &, bool, bool) const {
72  throw LogicalError("Component::trackBunch()",
73  "Called for component \"" + getName() + "\".");
74 }
75 
76 
78 trackMap(FVps<double, 6> &, const PartData &, bool, bool) const {
79  throw LogicalError("Component::trackMap()",
80  "Called for component \"" + getName() + "\".");
81 }
82 
83 void Component::goOnline(const double &) {
84  online_m = true;
85 }
86 
88  online_m = false;
89 }
90 
92  return online_m;
93 }
94 
96  return ElementBase::ANY;
97 }
98 
99 bool Component::apply(const size_t &i,
100  const double &/*t*/,
101  Vector_t &/*E*/,
102  Vector_t &/*B*/) {
103  const Vector_t &R = RefPartBunch_m->R[i];
104  if (R(2) >= 0.0 && R(2) < getElementLength()) {
105  if (!isInsideTransverse(R)) return true;
106  }
107  return false;
108 }
109 
111  const Vector_t &/*P*/,
112  const double &/*t*/,
113  Vector_t &/*E*/,
114  Vector_t &/*B*/) {
115  if (R(2) >= 0.0 && R(2) < getElementLength()) {
116  if (!isInsideTransverse(R)) return true;
117  }
118  return false;
119 }
120 
122  const Vector_t &/*P*/,
123  const double &/*t*/,
124  Vector_t &/*E*/,
125  Vector_t &/*B*/) {
126  if (R(2) >= 0.0 && R(2) < getElementLength()) {
127  if (!isInsideTransverse(R)) return true;
128  }
129  return false;
130 }
const std::string name
ParticlePos_t & R
Vector truncated power series in n variables.
Definition: FVps.h:39
Interface for a single beam element.
Definition: Component.h:50
bool online_m
Definition: Component.h:195
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B)
Definition: Component.cpp:121
virtual void goOnline(const double &kineticEnergy)
Definition: Component.cpp:83
virtual void goOffline()
Definition: Component.cpp:87
virtual ElementBase::ElementType getType() const
Get element type std::string.
Definition: Component.cpp:95
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
Definition: Component.cpp:99
virtual void trackBunch(PartBunchBase< double, 3 > *bunch, const PartData &, bool revBeam, bool revTrack) const
Track particle bunch.
Definition: Component.cpp:71
virtual void trackMap(FVps< double, 6 > &map, const PartData &, bool revBeam, bool revTrack) const
Track a map.
Definition: Component.cpp:78
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:194
virtual ~Component()
Definition: Component.cpp:63
static const std::vector< double > defaultAperture_m
Definition: Component.h:190
virtual bool Online()
Definition: Component.cpp:91
virtual const ElementBase & getDesign() const
Return design element.
Definition: Component.cpp:67
virtual const std::string & getName() const
Get element name.
void setAperture(const ApertureType &type, const std::vector< double > &args)
Definition: ElementBase.h:536
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:432
bool isInsideTransverse(const Vector_t &r) const
Particle reference data.
Definition: PartData.h:35
Logical error exception.
Definition: LogicalError.h:33