OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
23#include "AbsBeamline/Marker.h"
24#include "AbsBeamline/Septum.h"
25#include "AbsBeamline/Source.h"
27#include "Beamlines/Beamline.h"
30
31#include <filesystem>
32#include <fstream>
33#include <memory>
34#include <set>
35#include <string>
36
37template <class T, unsigned Dim>
38class PartBunchBase;
41
43
44public:
46 OpalBeamline(const Vector_t& origin,
47 const Quaternion& rotation);
49
50 void activateElements();
51 std::set<std::shared_ptr<Component>> getElements(const Vector_t &x);
52 Vector_t transformTo(const Vector_t &r) const;
53 Vector_t transformFrom(const Vector_t &r) const;
54 Vector_t rotateTo(const Vector_t &r) const;
55 Vector_t rotateFrom(const Vector_t &r) const;
56
57 Vector_t transformToLocalCS(const std::shared_ptr<Component> &comp,
58 const Vector_t &r) const;
59 Vector_t transformFromLocalCS(const std::shared_ptr<Component> &comp,
60 const Vector_t &r) const;
61 Vector_t rotateToLocalCS(const std::shared_ptr<Component> &comp,
62 const Vector_t &r) const;
63 Vector_t rotateFromLocalCS(const std::shared_ptr<Component> &comp,
64 const Vector_t &r) const;
65 CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr<Component> &comp) const;
67 CoordinateSystemTrafo getMisalignment(const std::shared_ptr<Component> &comp) const;
68
69 double getStart(const Vector_t &) const;
70 double getEnd(const Vector_t &) const;
71
72 void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors = false);
73 void switchElementsOff();
74
76
77 BoundaryGeometry *getBoundaryGeometry(const unsigned int &);
78
79 unsigned long getFieldAt(const unsigned int &, const Vector_t &, const long &, const double &, Vector_t &, Vector_t &);
80 unsigned long getFieldAt(const Vector_t &, const Vector_t &, const double &, Vector_t &, Vector_t &);
81
82 template<class T>
84
85 void prepareSections();
86 void positionElementRelative(std::shared_ptr<ElementBase>);
87 void compute3DLattice();
88 void save3DLattice();
89 void save3DInput();
90 void print(Inform &) const;
91
93
94 void swap(OpalBeamline & rhs);
95 void merge(OpalBeamline &rhs);
96
97 bool containsSource();
98private:
102
104};
105
106template<class T> inline
108 Inform msg("OPAL ");
109 double startField = 0.0;
110 double endField = 0.0;
111 std::shared_ptr<T> elptr(dynamic_cast<T *>(element.clone()));
112
114
115 if (elptr->isElementPositionSet())
116 startField = elptr->getElementPosition();
117
118 elptr->initialise(bunch, startField, endField);
119 elements_m.push_back(ClassicField(elptr, startField, endField));
120}
121
122template<> inline
123void OpalBeamline::visit<Source>(const Source &element, BeamlineVisitor &, PartBunchBase<double, 3> *bunch) {
124 containsSource_m = true;
125 double startField = 0.0;
126 double endField = 0.0;
127 std::shared_ptr<Source> elptr(dynamic_cast<Source *>(element.clone()));
128
130
131 if (elptr->isElementPositionSet())
132 startField = elptr->getElementPosition();
133
134 elptr->initialise(bunch, startField, endField);
135 elements_m.push_back(ClassicField(elptr, startField, endField));
136}
137
138template<> inline
139void OpalBeamline::visit<Marker>(const Marker &/*element*/, BeamlineVisitor &, PartBunchBase<double, 3> *) {
140}
141
142template<> inline
143void OpalBeamline::visit<Septum>(const Septum &element, BeamlineVisitor &, PartBunchBase<double, 3> *) {
144 WARNMSG(element.getTypeString() << " not implemented yet!" << endl);
145}
146
147inline
151
152inline
156
157inline
161
162inline
166
167inline
168Vector_t OpalBeamline::transformToLocalCS(const std::shared_ptr<Component> &comp,
169 const Vector_t &r) const {
170 return comp->getCSTrafoGlobal2Local().transformTo(r);
171}
172
173inline
174Vector_t OpalBeamline::transformFromLocalCS(const std::shared_ptr<Component> &comp,
175 const Vector_t &r) const {
176 return comp->getCSTrafoGlobal2Local().transformFrom(r);
177}
178
179inline
180Vector_t OpalBeamline::rotateToLocalCS(const std::shared_ptr<Component> &comp,
181 const Vector_t &r) const {
182 return comp->getCSTrafoGlobal2Local().rotateTo(r);
183}
184
185inline
186Vector_t OpalBeamline::rotateFromLocalCS(const std::shared_ptr<Component> &comp,
187 const Vector_t &r) const {
188 return comp->getCSTrafoGlobal2Local().rotateFrom(r);
189}
190
191inline
192CoordinateSystemTrafo OpalBeamline::getCSTrafoLab2Local(const std::shared_ptr<Component> &comp) const {
193 return comp->getCSTrafoGlobal2Local();
194}
195
196inline
200
201inline
202CoordinateSystemTrafo OpalBeamline::getMisalignment(const std::shared_ptr<Component> &comp) const {
203 return comp->getMisalignment();
204}
205
206inline
210#endif // OPAL_BEAMLINE_H
ElementType
Definition ElementBase.h:89
std::list< ClassicField > FieldList
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
Interface for a marker.
Definition Marker.h:32
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
Vector_t transformFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
double getEnd(const Vector_t &) const
void positionElementRelative(std::shared_ptr< ElementBase >)
void visit(const T &, BeamlineVisitor &, PartBunchBase< double, 3 > *)
CoordinateSystemTrafo getMisalignment(const std::shared_ptr< Component > &comp) const
bool containsSource_m
void merge(OpalBeamline &rhs)
Vector_t transformTo(const Vector_t &r) const
double getStart(const Vector_t &) const
Vector_t transformFrom(const Vector_t &r) const
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
ParticleMatterInteractionHandler * getParticleMatterInteractionHandler(const unsigned int &)
Vector_t rotateFromLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
CoordinateSystemTrafo coordTransformationTo_m
bool containsSource()
void prepareSections()
void print(Inform &) const
void compute3DLattice()
void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors=false)
void switchElementsOff()
unsigned long getFieldAt(const unsigned int &, const Vector_t &, const long &, const double &, Vector_t &, Vector_t &)
FieldList elements_m
CoordinateSystemTrafo getCSTrafoLab2Local() const
BoundaryGeometry * getBoundaryGeometry(const unsigned int &)
Vector_t rotateTo(const Vector_t &r) const
void activateElements()
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
void swap(OpalBeamline &rhs)