OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 
31 #include <string>
32 #include <map>
33 
35 {
36 public:
37 
38  OrbitThreader(const PartData &ref,
39  const Vector_t &r,
40  const Vector_t &p,
41  double s,
42  double maxDiffZBunch,
43  double t,
44  double dT,
45  StepSizeConfig stepSizes,
46  OpalBeamline &bl);
47 
48  void execute();
49 
52 
54  double position) const;
56 
57 private:
63  double pathLength_m;
68  double time_m;
70  double dt_m;
71 
74  const double zstop_m;
75 
78 
79  unsigned int errorFlag_m;
80 
83 
84  std::ofstream logger_m;
86 
88 
89  struct elementPosition {
90  double startField_m;
91  double endField_m;
92  double elementEdge_m;
93  };
94 
96  bool operator() (const elementPosition &a, const elementPosition &b) const {
97  return a.elementEdge_m < b.elementEdge_m;
98  }
99  };
100 
101  std::multimap<std::string, elementPosition> elementRegistry_m;
102 
103  void trackBack();
104  void integrate(const IndexMap::value_t &activeSet, double maxDrift = 10.0);
105  bool containsCavity(const IndexMap::value_t &activeSet);
106  void autophaseCavities(const IndexMap::value_t &activeSet, const std::set<std::string> &visitedElements);
107  double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const;
108 
109  void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p);
110  void processElementRegister();
111  void setDesignEnergy(FieldList &allElements, const std::set<std::string> &visitedElements);
112  void computeBoundingBox();
114  double computeDriftLengthToBoundingBox(const std::set<std::shared_ptr<Component>> & elements,
115  const Vector_t & position,
116  const Vector_t & direction) const;
117 
118  void checkElementLengths(const std::set<std::shared_ptr<Component>>& elements);
119 };
120 
121 inline
124  return imap_m.query(pathLength, length);
125 }
126 
127 inline
129  double position) const {
130  return imap_m.getRange(element, position);
131 }
132 
133 inline
135  return imap_m.getTouchingElements(range);
136 }
137 
138 #endif
elements
Definition: IndexMap.cpp:163
T * value_type(const SliceIterator< T > &)
std::list< ClassicField > FieldList
Definition: ClassicField.h:42
std::complex< double > a
std::set< std::shared_ptr< Component > > value_t
Definition: IndexMap.h:47
value_t getTouchingElements(const key_t &range) const
Definition: IndexMap.cpp:396
key_t getRange(const IndexMap::value_t::value_type &element, double position) const
Definition: IndexMap.cpp:375
value_t query(key_t::first_type s, key_t::second_type ds)
Definition: IndexMap.cpp:76
double first_type
Definition: IndexMap.h:41
double second_type
Definition: IndexMap.h:42
void processElementRegister()
void updateBoundingBoxWithCurrentPosition()
double distTrackBack_m
Definition: OrbitThreader.h:66
void setDesignEnergy(FieldList &allElements, const std::set< std::string > &visitedElements)
IndexMap::value_t query(IndexMap::key_t::first_type step, IndexMap::key_t::second_type length)
BorisPusher integrator_m
Definition: OrbitThreader.h:81
IndexMap imap_m
Definition: OrbitThreader.h:77
unsigned int errorFlag_m
Definition: OrbitThreader.h:79
double dt_m
the time step
Definition: OrbitThreader.h:70
double time_m
the simulated time
Definition: OrbitThreader.h:68
OpalBeamline & itsOpalBeamline_m
Definition: OrbitThreader.h:76
std::multimap< std::string, elementPosition > elementRegistry_m
Vector_t r_m
position of reference particle in lab coordinates
Definition: OrbitThreader.h:59
const PartData & reference_m
Definition: OrbitThreader.h:82
std::ofstream logger_m
Definition: OrbitThreader.h:84
Vector_t p_m
momentum of reference particle
Definition: OrbitThreader.h:61
bool containsCavity(const IndexMap::value_t &activeSet)
void integrate(const IndexMap::value_t &activeSet, double maxDrift=10.0)
OrbitThreader(const PartData &ref, const Vector_t &r, const Vector_t &p, double s, double maxDiffZBunch, double t, double dT, StepSizeConfig stepSizes, OpalBeamline &bl)
StepSizeConfig stepSizes_m
final position in path length
Definition: OrbitThreader.h:73
ElementBase::BoundingBox globalBoundingBox_m
Definition: OrbitThreader.h:87
double computeDriftLengthToBoundingBox(const std::set< std::shared_ptr< Component >> &elements, const Vector_t &position, const Vector_t &direction) const
void checkElementLengths(const std::set< std::shared_ptr< Component >> &elements)
double getMaxDesignEnergy(const IndexMap::value_t &elementSet) const
IndexMap::value_t getTouchingElements(const IndexMap::key_t &range) const
IndexMap::key_t getRange(const IndexMap::value_t::value_type &element, double position) const
void registerElement(const IndexMap::value_t &elementSet, double, const Vector_t &r, const Vector_t &p)
double pathLength_m
position of reference particle in path length
Definition: OrbitThreader.h:63
void autophaseCavities(const IndexMap::value_t &activeSet, const std::set< std::string > &visitedElements)
void computeBoundingBox()
size_t loggingFrequency_m
Definition: OrbitThreader.h:85
const double zstop_m
Definition: OrbitThreader.h:74
bool operator()(const elementPosition &a, const elementPosition &b) const
Definition: OrbitThreader.h:96
Particle reference data.
Definition: PartData.h:35