OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalBeamline.h
Go to the documentation of this file.
1 //
2 // Class OpalBeamline
3 // :FIXME: add class description
4 //
5 // Copyright (c) 200x - 2020, 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 OPAL_BEAMLINE_H
19 #define OPAL_BEAMLINE_H
20 
21 #include <set>
22 #include <string>
23 
24 #include "Beamlines/Beamline.h"
25 #include "AbsBeamline/Corrector.h"
26 #include "AbsBeamline/Degrader.h"
27 #include "AbsBeamline/Marker.h"
28 #include "AbsBeamline/Septum.h"
29 #include "AbsBeamline/Source.h"
30 
31 #include "Utilities/ClassicField.h"
32 
34 
35 template <class T, unsigned Dim>
36 class PartBunchBase;
38 class BoundaryGeometry;
39 
40 class OpalBeamline {
41 
42 public:
43  OpalBeamline();
44  OpalBeamline(const Vector_t& origin,
45  const Quaternion& rotation);
46  ~OpalBeamline();
47 
48  void activateElements();
49  std::set<std::shared_ptr<Component>> getElements(const Vector_t &x);
50  Vector_t transformTo(const Vector_t &r) const;
51  Vector_t transformFrom(const Vector_t &r) const;
52  Vector_t rotateTo(const Vector_t &r) const;
53  Vector_t rotateFrom(const Vector_t &r) const;
54 
55  Vector_t transformToLocalCS(const std::shared_ptr<Component> &comp,
56  const Vector_t &r) const;
57  Vector_t transformFromLocalCS(const std::shared_ptr<Component> &comp,
58  const Vector_t &r) const;
59  Vector_t rotateToLocalCS(const std::shared_ptr<Component> &comp,
60  const Vector_t &r) const;
61  Vector_t rotateFromLocalCS(const std::shared_ptr<Component> &comp,
62  const Vector_t &r) const;
63  CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr<Component> &comp) const;
65  CoordinateSystemTrafo getMisalignment(const std::shared_ptr<Component> &comp) const;
66 
67  double getStart(const Vector_t &) const;
68  double getEnd(const Vector_t &) const;
69 
70  void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors = false);
71  void switchElementsOff();
72 
74 
75  BoundaryGeometry *getBoundaryGeometry(const unsigned int &);
76 
77  unsigned long getFieldAt(const unsigned int &, const Vector_t &, const long &, const double &, Vector_t &, Vector_t &);
78  unsigned long getFieldAt(const Vector_t &, const Vector_t &, const double &, Vector_t &, Vector_t &);
79 
80  template<class T>
81  void visit(const T &, BeamlineVisitor &, PartBunchBase<double, 3> *);
82 
83  void prepareSections();
84  void positionElementRelative(std::shared_ptr<ElementBase>);
85  void compute3DLattice();
86  void save3DLattice();
87  void save3DInput();
88  void print(Inform &) const;
89 
91 
92  void swap(OpalBeamline & rhs);
93  void merge(OpalBeamline &rhs);
94 
95  bool containsSource();
96 private:
98  bool prepared_m;
100 
102 };
103 
104 template<class T> inline
106  Inform msg("OPAL ");
107  double startField = 0.0;
108  double endField = 0.0;
109  std::shared_ptr<T> elptr(dynamic_cast<T *>(element.clone()));
110 
112 
113  if (elptr->isElementPositionSet())
114  startField = elptr->getElementPosition();
115 
116  elptr->initialise(bunch, startField, endField);
117  elements_m.push_back(ClassicField(elptr, startField, endField));
118 }
119 
120 template<> inline
121 void OpalBeamline::visit<Source>(const Source &element, BeamlineVisitor &, PartBunchBase<double, 3> *bunch) {
122  containsSource_m = true;
123  double startField = 0.0;
124  double endField = 0.0;
125  std::shared_ptr<Source> elptr(dynamic_cast<Source *>(element.clone()));
126 
128 
129  if (elptr->isElementPositionSet())
130  startField = elptr->getElementPosition();
131 
132  elptr->initialise(bunch, startField, endField);
133  elements_m.push_back(ClassicField(elptr, startField, endField));
134 }
135 
136 template<> inline
137 void OpalBeamline::visit<Marker>(const Marker &/*element*/, BeamlineVisitor &, PartBunchBase<double, 3> *) {
138 }
139 
140 template<> inline
141 void OpalBeamline::visit<Septum>(const Septum &element, BeamlineVisitor &, PartBunchBase<double, 3> *) {
142  WARNMSG(element.getTypeString() << " not implemented yet!" << endl);
143 }
144 
145 inline
148 }
149 
150 inline
153 }
154 
155 inline
158 }
159 
160 inline
163 }
164 
165 inline
166 Vector_t OpalBeamline::transformToLocalCS(const std::shared_ptr<Component> &comp,
167  const Vector_t &r) const {
168  return comp->getCSTrafoGlobal2Local().transformTo(r);
169 }
170 
171 inline
172 Vector_t OpalBeamline::transformFromLocalCS(const std::shared_ptr<Component> &comp,
173  const Vector_t &r) const {
174  return comp->getCSTrafoGlobal2Local().transformFrom(r);
175 }
176 
177 inline
178 Vector_t OpalBeamline::rotateToLocalCS(const std::shared_ptr<Component> &comp,
179  const Vector_t &r) const {
180  return comp->getCSTrafoGlobal2Local().rotateTo(r);
181 }
182 
183 inline
184 Vector_t OpalBeamline::rotateFromLocalCS(const std::shared_ptr<Component> &comp,
185  const Vector_t &r) const {
186  return comp->getCSTrafoGlobal2Local().rotateFrom(r);
187 }
188 
189 inline
190 CoordinateSystemTrafo OpalBeamline::getCSTrafoLab2Local(const std::shared_ptr<Component> &comp) const {
191  return comp->getCSTrafoGlobal2Local();
192 }
193 
194 inline
197 }
198 
199 inline
200 CoordinateSystemTrafo OpalBeamline::getMisalignment(const std::shared_ptr<Component> &comp) const {
201  return comp->getMisalignment();
202 }
203 
204 inline
206  return containsSource_m;
207 }
208 #endif // OPAL_BEAMLINE_H
std::list< ClassicField > FieldList
Definition: ClassicField.h:42
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define WARNMSG(msg)
Definition: IpplInfo.h:349
std::string getTypeString() const
Definition: ElementBase.h:596
virtual ElementBase * clone() const =0
Return clone.
Interface for a marker.
Definition: Marker.h:32
Definition: Septum.h:23
Definition: Source.h:30
Vector_t rotateFrom(const Vector_t &r) const
Vector_t transformFrom(const Vector_t &r) const
Vector_t transformTo(const Vector_t &r) const
Vector_t rotateTo(const Vector_t &r) const
FieldList getElementByType(ElementBase::ElementType)
Vector_t rotateFrom(const Vector_t &r) const
Definition: OpalBeamline.h:161
Vector_t transformFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:172
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:178
double getEnd(const Vector_t &) const
void positionElementRelative(std::shared_ptr< ElementBase >)
void visit(const T &, BeamlineVisitor &, PartBunchBase< double, 3 > *)
Definition: OpalBeamline.h:105
CoordinateSystemTrafo getMisalignment(const std::shared_ptr< Component > &comp) const
Definition: OpalBeamline.h:200
bool containsSource_m
Definition: OpalBeamline.h:99
void merge(OpalBeamline &rhs)
Vector_t transformTo(const Vector_t &r) const
Definition: OpalBeamline.h:146
double getStart(const Vector_t &) const
Vector_t transformFrom(const Vector_t &r) const
Definition: OpalBeamline.h:151
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:166
Vector_t rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:184
CoordinateSystemTrafo coordTransformationTo_m
Definition: OpalBeamline.h:101
bool containsSource()
Definition: OpalBeamline.h:205
void prepareSections()
ParticleMatterInteractionHandler * getParticleMatterInteractionHandler(const unsigned int &)
void print(Inform &) const
void compute3DLattice()
void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors=false)
void switchElementsOff()
BoundaryGeometry * getBoundaryGeometry(const unsigned int &)
void save3DInput()
unsigned long getFieldAt(const unsigned int &, const Vector_t &, const long &, const double &, Vector_t &, Vector_t &)
FieldList elements_m
Definition: OpalBeamline.h:97
void save3DLattice()
CoordinateSystemTrafo getCSTrafoLab2Local() const
Definition: OpalBeamline.h:195
Vector_t rotateTo(const Vector_t &r) const
Definition: OpalBeamline.h:156
void activateElements()
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
void swap(OpalBeamline &rhs)
Definition: Inform.h:42