OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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"
27#include "AbsBeamline/Marker.h"
28#include "AbsBeamline/Septum.h"
29#include "AbsBeamline/Source.h"
30
32
34
35template <class T, unsigned Dim>
36class PartBunchBase;
39
41
42public:
44 OpalBeamline(const Vector_t& origin,
45 const Quaternion& rotation);
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>
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();
96private:
100
102};
103
104template<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
120template<> inline
121void 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
136template<> inline
137void OpalBeamline::visit<Marker>(const Marker &/*element*/, BeamlineVisitor &, PartBunchBase<double, 3> *) {
138}
139
140template<> inline
141void OpalBeamline::visit<Septum>(const Septum &element, BeamlineVisitor &, PartBunchBase<double, 3> *) {
142 WARNMSG(element.getTypeString() << " not implemented yet!" << endl);
143}
144
145inline
148}
149
150inline
153}
154
155inline
158}
159
160inline
163}
164
165inline
166Vector_t OpalBeamline::transformToLocalCS(const std::shared_ptr<Component> &comp,
167 const Vector_t &r) const {
168 return comp->getCSTrafoGlobal2Local().transformTo(r);
169}
170
171inline
172Vector_t OpalBeamline::transformFromLocalCS(const std::shared_ptr<Component> &comp,
173 const Vector_t &r) const {
174 return comp->getCSTrafoGlobal2Local().transformFrom(r);
175}
176
177inline
178Vector_t OpalBeamline::rotateToLocalCS(const std::shared_ptr<Component> &comp,
179 const Vector_t &r) const {
180 return comp->getCSTrafoGlobal2Local().rotateTo(r);
181}
182
183inline
184Vector_t OpalBeamline::rotateFromLocalCS(const std::shared_ptr<Component> &comp,
185 const Vector_t &r) const {
186 return comp->getCSTrafoGlobal2Local().rotateFrom(r);
187}
188
189inline
190CoordinateSystemTrafo OpalBeamline::getCSTrafoLab2Local(const std::shared_ptr<Component> &comp) const {
191 return comp->getCSTrafoGlobal2Local();
192}
193
194inline
197}
198
199inline
200CoordinateSystemTrafo OpalBeamline::getMisalignment(const std::shared_ptr<Component> &comp) const {
201 return comp->getMisalignment();
202}
203
204inline
206 return containsSource_m;
207}
208#endif // OPAL_BEAMLINE_H
ElementType
Definition: ElementBase.h:88
std::list< ClassicField > FieldList
Definition: ClassicField.h:43
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define WARNMSG(msg)
Definition: IpplInfo.h:349
virtual ElementBase * clone() const =0
Return clone.
std::string getTypeString() const
Definition: ElementBase.h:578
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(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
ParticleMatterInteractionHandler * getParticleMatterInteractionHandler(const unsigned int &)
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()
void print(Inform &) const
void compute3DLattice()
void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors=false)
void switchElementsOff()
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
BoundaryGeometry * getBoundaryGeometry(const unsigned int &)
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