42 :
Component(ring), planarArcGeometry_m(1, 1),
43 refPartBunch_m(nullptr),
45 beamRInit_m(0.), beamPRInit_m(0.), beamPhiInit_m(0.),
46 latticeRInit_m(0.), latticePhiInit_m(0.), latticeThetaInit_m(0.),
47 isLocked_m(false), isClosed_m(true),
48 symmetry_m(0), cyclHarm_m(0), rfFreq_m(0),
61 planarArcGeometry_m(ring.planarArcGeometry_m),
63 beamRInit_m(ring.beamRInit_m),
64 beamPRInit_m(ring.beamPRInit_m),
65 beamPhiInit_m(ring.beamPhiInit_m),
66 beamThetaInit_m(ring.beamThetaInit_m),
67 latticeRInit_m(ring.latticeRInit_m),
68 latticePhiInit_m(ring.latticePhiInit_m),
69 latticeThetaInit_m(ring.latticeThetaInit_m),
70 willDoAperture_m(ring.willDoAperture_m),
71 minR2_m(ring.minR2_m),
72 maxR2_m(ring.maxR2_m),
73 isLocked_m(ring.isLocked_m),
74 isClosed_m(ring.isClosed_m),
75 symmetry_m(ring.symmetry_m),
76 cyclHarm_m(ring.cyclHarm_m),
77 phiStep_m(ring.phiStep_m),
79 section_list_m(ring.section_list_m.size()) {
83 "Can't copy construct LossDataSink so copy constructor fails");
100 if (flagNeedUpdate) {
103 <<
" m out of the field map boundary" <<
endl;
113 return flagNeedUpdate;
122 bool outOfBounds =
true;
125 double rSquared =
R[0] *
R[0] +
R[1] *
R[1];
126 if (rSquared < minR2_m || rSquared >
maxR2_m) {
130 for (
size_t i = 0; i < sections.size(); ++i) {
147 "Cannot get s-dimension of a ring");
157 double& ,
double& ) {
182 double deltaAngle =
std::atan2(rotationTest(2), rotationTest(0));
184 return elementRotation;
192 std::string(
"Placement of elements out of the ")+
193 "midplane is not supported by Ring");
201 Euclid3D euclid(v(2), v(0), -v(1), r(2), r(0), -r(1));
237 "Attempt to append element " + element.
getName() +
238 " when ring is locked");
256 double placeF =
std::atan2(startNorm(0), startNorm(1));
270 double orientation =
std::atan2(startNorm(1), startNorm(0));
275 *
gmsg <<
"* Start position ("
282 *
gmsg <<
"* End position ("
294 "Attempt to lock ring when it is already locked");
298 if (sectionListSize == 0) {
300 "Failed to find any elements in Ring");
305 *
gmsg <<
"Applying symmetry to Ring" <<
endl;
307 for (
size_t j = 0; j < sectionListSize; ++j) {
341 for (
int i = 0; i < 3; ++i) {
345 "Ring is not closed");
353 ringSections_m = std::vector< std::vector<RingSection*> >(nSections);
377 if (minR < 0 || maxR < 0) {
379 "Could not parse negative or undefined aperture limit");
389 std::stringstream err;
390 err <<
"Attempt to get RingSection for element " << i
395 if (
sec ==
nullptr) {
397 "Opal internal error - RingSection was null");
Tps< T > sec(const Tps< T > &x)
Secant.
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > sin(const Tps< T > &x)
Sine.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Inform & level4(Inform &inf)
Inform & endl(Inform &inf)
constexpr double two_pi
The value of.
constexpr double e
The value of.
ParticleAttrib< int > Bin
ParticleAttrib< double > M
ParticleAttrib< Vector_t > P
ParticleAttrib< double > Q
Vector_t get_centroid() const
virtual void visitRing(const Ring &)=0
Apply the algorithm to a ring.
Interface for a single beam element.
PartBunchBase< double, 3 > * RefPartBunch_m
virtual const std::string & getName() const
Get element name.
virtual ElementBase * clone() const =0
Return clone.
virtual BGeometryBase & getGeometry()=0
Get geometry.
Ring describes a ring type geometry for tracking.
Vector_t getNextPosition() const
Get the initial element's start position in cartesian coordinates.
std::vector< RingSection * > getSectionsAt(const Vector_t &pos)
Get the list of sections at position pos.
Rotation3D getRotationStartToEnd(Euclid3D delta) const
size_t getNumberOfRingSections() const
Get number of RingSections.
static bool sectionCompare(RingSection const *const sec1, RingSection const *const sec2)
Vector_t getNextNormal() const
Get the initial element's start normal in cartesian coordinates.
virtual void finalise() override
Clean up the Ring.
virtual ~Ring()
Destructor - deletes lossDS_m if not nullptr.
virtual bool apply(const size_t &id, const double &t, Vector_t &E, Vector_t &B) override
Overwrite data in vector E and B with electric and magnetic field.
RingSection * getLastSectionPlaced() const
Get the last section placed or nullptr if no sections were placed yet.
void setRefPartBunch(PartBunchBase< double, 3 > *bunch)
Set RefPartBunchBase<double, 3> to bunch.
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Initialise the Ring.
double latticeThetaInit_m
std::vector< RingSectionList > ringSections_m
virtual void accept(BeamlineVisitor &visitor) const override
Accept the BeamlineVisitor.
void setRingAperture(double minR, double maxR)
Set the ring aperture limits.
RingSectionList section_list_m
void checkMidplane(Euclid3D delta) const
void setLossDataSink(LossDataSink *sink)
Set LossDataSink to sink.
virtual void getDimensions(double &zBegin, double &zEnd) const override
Not implemented - always throws an exception.
void lockRing()
Lock the ring.
void appendElement(const Component &element)
Add element to the ring.
Vector_t getStartNormal() const
void rotateToCyclCoordinates(Euclid3D &euclid3d) const
static const double lengthTolerance_m
RingSection * getSection(int i) const
Return ith section.
Vector_t getStartPosition() const
PartBunchBase< double, 3 > * refPartBunch_m
static const double angleTolerance_m
Displacement and rotation in space.
const Vector3D & getVector() const
Get displacement.
const Rotation3D & getRotation() const
Get rotation.
virtual Euclid3D getTotalTransform() const
Get transform.
Rotation in 3-dimensional space.
static Rotation3D ZRotation(double angle)
Make rotation.
Vector3D getAxis() const
Get axis vector.
void save(unsigned int numSets=1, OpalData::OpenMode openMode=OpalData::OpenMode::UNDEFINED)
void addParticle(const OpalParticle &, const boost::optional< std::pair< int, short int > > &turnBunchNumPair=boost::none)
Component placement handler in ring geometry.
void setStartNormal(Vector_t orientation)
Set the normal vector to the section start plane.
void setComponentPosition(Vector_t position)
Set the displacement for the component relative to the section start.
void setComponent(Component *component)
Set the component wrapped by RingSection.
void handleOffset()
Check whether component_m is a global offset and handle.
void setStartPosition(Vector_t pos)
Set a position on the plane of the section start.
Vector_t getStartNormal() const
Get the normal vector to the section start plane.
void setComponentOrientation(Vector_t orientation)
Set the rotation for the component relative to the section start.
Component * getComponent() const
Get the component wrapped by RingSection.
Vector_t getEndPosition() const
Get a position on the section end plane.
Vector_t getStartPosition() const
Get a position on the plane of the section start.
void setEndPosition(Vector_t pos)
Set a position on the section end plane.
Vector_t getEndNormal() const
Get the normal vector to the section end plane.
void setEndNormal(Vector_t orientation)
Set the normal vector to the section end plane
Vektor< double, 3 > Vector_t