OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OrbitThreader.h
Go to the documentation of this file.
1 //
2 // Class OrbitThreader
3 //
4 // This class determines the design path by tracking the reference particle through
5 // the 3D lattice.
6 //
7 // Copyright (c) 2016, Christof Metzger-Kraus, Helmholtz-Zentrum Berlin, Germany
8 // 2017 - 2020 Christof Metzger-Kraus
9 //
10 // All rights reserved
11 //
12 // This file is part of OPAL.
13 //
14 // OPAL is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
21 //
22 #ifndef OPAL_ORBITTHREADER_H
23 #define OPAL_ORBITTHREADER_H
24 
25 #include "Algorithms/IndexMap.h"
27 #include "Algorithms/Vektor.h"
28 #include "Elements/OpalBeamline.h"
29 #include "Steppers/BorisPusher.h"
30 #include "Structure/BoundingBox.h"
31 #include "Structure/ValueRange.h"
32 
33 #include <string>
34 #include <map>
35 
37 {
38 public:
39 
40  OrbitThreader(const PartData &ref,
41  const Vector_t &r,
42  const Vector_t &p,
43  double s,
44  double maxDiffZBunch,
45  double t,
46  double dT,
47  StepSizeConfig stepSizes,
48  OpalBeamline &bl);
49 
50  void execute();
51 
54 
56  double position) const;
58 
60 
61 private:
67  double pathLength_m;
72  double time_m;
74  double dt_m;
76  long currentStep_m{0};
77 
80  const double zstop_m;
82 
85 
86  unsigned int errorFlag_m;
87 
90 
91  std::ofstream logger_m;
93 
95 
96  struct elementPosition {
97  double startField_m;
98  double endField_m;
99  double elementEdge_m;
100  };
101 
103  bool operator() (const elementPosition &a, const elementPosition &b) const {
104  return a.elementEdge_m < b.elementEdge_m;
105  }
106  };
107 
108  std::multimap<std::string, elementPosition> elementRegistry_m;
109 
110  void trackBack();
111  void integrate(const IndexMap::value_t &activeSet, double maxDrift = 10.0);
112  bool containsCavity(const IndexMap::value_t &activeSet);
113  void autophaseCavities(const IndexMap::value_t &activeSet, const std::set<std::string> &visitedElements);
114  double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const;
115 
116  void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p);
117  void processElementRegister();
118  void setDesignEnergy(FieldList &allElements, const std::set<std::string> &visitedElements);
119  void computeBoundingBox();
121  double computeDriftLengthToBoundingBox(const std::set<std::shared_ptr<Component>> & elements,
122  const Vector_t & position,
123  const Vector_t & direction) const;
124 
125  void checkElementLengths(const std::set<std::shared_ptr<Component>>& elements);
126 };
127 
128 inline
131  return imap_m.query(pathLength, length);
132 }
133 
134 inline
136  double position) const {
137  return imap_m.getRange(element, position);
138 }
139 
140 inline
142  return imap_m.getTouchingElements(range);
143 }
144 
145 inline
147  return globalBoundingBox_m;
148 }
149 #endif
IndexMap::value_t getTouchingElements(const IndexMap::key_t &range) const
ValueRange< long > stepRange_m
Definition: OrbitThreader.h:75
std::ofstream logger_m
Definition: OrbitThreader.h:91
const double zstop_m
Definition: OrbitThreader.h:80
double pathLength_m
position of reference particle in path length
Definition: OrbitThreader.h:67
void processElementRegister()
value_t getTouchingElements(const key_t &range) const
Definition: IndexMap.cpp:396
double distTrackBack_m
Definition: OrbitThreader.h:70
double dt_m
the time step
Definition: OrbitThreader.h:74
BoundingBox globalBoundingBox_m
Definition: OrbitThreader.h:94
void autophaseCavities(const IndexMap::value_t &activeSet, const std::set< std::string > &visitedElements)
std::set< std::shared_ptr< Component > > value_t
Definition: IndexMap.h:47
void updateBoundingBoxWithCurrentPosition()
void computeBoundingBox()
BoundingBox getBoundingBox() const
double first_type
Definition: IndexMap.h:41
key_t getRange(const IndexMap::value_t::value_type &element, double position) const
Definition: IndexMap.cpp:375
bool operator()(const elementPosition &a, const elementPosition &b) const
std::multimap< std::string, elementPosition > elementRegistry_m
value_t query(key_t::first_type s, key_t::second_type ds)
Definition: IndexMap.cpp:76
void setDesignEnergy(FieldList &allElements, const std::set< std::string > &visitedElements)
OpalBeamline & itsOpalBeamline_m
Definition: OrbitThreader.h:83
void checkElementLengths(const std::set< std::shared_ptr< Component >> &elements)
elements
Definition: IndexMap.cpp:163
set(_SRCS Action.cpp Attribute.cpp AttributeBase.cpp AttributeHandler.cpp BeamSequence.cpp Definition.cpp Directory.cpp Element.cpp Invalidator.cpp OpalData.cpp Object.cpp ObjectFunction.cpp PlaceRep.cpp RangeRep.cpp Table.cpp TableRowRep.cpp ValueDefinition.cpp) include_directories($
Definition: CMakeLists.txt:1
OrbitThreader(const PartData &ref, const Vector_t &r, const Vector_t &p, double s, double maxDiffZBunch, double t, double dT, StepSizeConfig stepSizes, OpalBeamline &bl)
ValueRange< double > pathLengthRange_m
Definition: OrbitThreader.h:81
BorisPusher integrator_m
Definition: OrbitThreader.h:88
double computeDriftLengthToBoundingBox(const std::set< std::shared_ptr< Component >> &elements, const Vector_t &position, const Vector_t &direction) const
StepSizeConfig stepSizes_m
final position in path length
Definition: OrbitThreader.h:79
T * value_type(const SliceIterator< T > &)
double time_m
the simulated time
Definition: OrbitThreader.h:72
size_t loggingFrequency_m
Definition: OrbitThreader.h:92
std::list< ClassicField > FieldList
Definition: ClassicField.h:43
IndexMap::value_t query(IndexMap::key_t::first_type step, IndexMap::key_t::second_type length)
unsigned int errorFlag_m
Definition: OrbitThreader.h:86
Vector_t p_m
momentum of reference particle
Definition: OrbitThreader.h:65
double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const
double second_type
Definition: IndexMap.h:42
IndexMap imap_m
Definition: OrbitThreader.h:84
Vector_t r_m
position of reference particle in lab coordinates
Definition: OrbitThreader.h:63
bool containsCavity(const IndexMap::value_t &activeSet)
IndexMap::key_t getRange(const IndexMap::value_t::value_type &element, double position) const
void integrate(const IndexMap::value_t &activeSet, double maxDrift=10.0)
const PartData & reference_m
Definition: OrbitThreader.h:89
void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p)