OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Ring.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2014, Chris Rogers
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef RING_H
29#define RING_H
30
31#include <string>
32
34
36
39
40class LossDataSink;
41template <class T, unsigned Dim>
42class PartBunchBase;
43class FieldMap;
44
64class Ring : public Component {
65 public:
70 Ring(std::string ring);
71
76 Ring(const Ring& ring);
77
79 virtual ~Ring();
80
94 virtual bool apply(const size_t &id, const double &t, Vector_t &E,
95 Vector_t &B) override;
96
113 virtual bool apply(const Vector_t &R, const Vector_t &P,
114 const double &t, Vector_t &E, Vector_t &B) override;
115
124 virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField,
125 double &endField) override;
126
132 virtual void initialise(PartBunchBase<double, 3> *bunch);
133
138 virtual void finalise() override;
139
141 virtual bool bends() const override {return true;}
142
149 virtual void accept(BeamlineVisitor& visitor) const override;
150
152 virtual void getDimensions(double &zBegin, double &zEnd) const override;
153
155 virtual ElementBase* clone() const override {return new Ring(*this);}
156
176 void appendElement(const Component &element);
177
179 virtual EMField &getField() override {throw GeneralClassicException("Ring::getField", "Not implemented");}
180
182 virtual const EMField &getField() const override {throw GeneralClassicException("Ring::getField", "Not implemented");}
183
186
188 virtual const PlanarArcGeometry &getGeometry() const override {return planarArcGeometry_m;}
189
195 void setLossDataSink(LossDataSink* sink);
196
202
211
217
219 void setHarmonicNumber(double cyclHarm) {cyclHarm_m = cyclHarm;}
220
222 double getHarmonicNumber() {return cyclHarm_m;}
223 // note this is not a const method to follow parent
224
226 void setRFFreq(double rfFreq) {rfFreq_m = rfFreq;}
227
229 double getRFFreq() const {return rfFreq_m;}
230
232 void setBeamRInit(double rInit) {beamRInit_m = rInit;}
233
235 double getBeamRInit() const {return beamRInit_m;}
236
238 void setBeamPhiInit(double phiInit) {beamPhiInit_m = phiInit;}
239
241 double getBeamPhiInit() const {return beamPhiInit_m;}
242
244 void setBeamPRInit(double pRInit) {beamPRInit_m = pRInit;}
245
247 double getBeamPRInit() const {return beamPRInit_m;}
248
250 void setLatticeRInit(double rInit) {latticeRInit_m = rInit;}
251
253 double getLatticeRInit() const {return latticeRInit_m;}
254
256 void setLatticePhiInit(double phiInit) {latticePhiInit_m = phiInit;}
257
259 double getLatticePhiInit() const {return latticePhiInit_m;}
260
263
265 Vector_t getNextNormal() const;
266
271 void setLatticeThetaInit(double thetaInit) {latticeThetaInit_m = thetaInit;}
272
278
280 void setSymmetry(double symmetry) {symmetry_m = symmetry;}
281
283 void setScale(double scale) {scale_m = scale;}
284
286 double getSymmetry() const {return symmetry_m;}
287
289 void setIsClosed(bool isClosed) {isClosed_m = isClosed;}
290
292 double getIsClosed() const {return isClosed_m;}
293
298 void setRingAperture(double minR, double maxR);
299
301 double getRingMinR() const {return std::sqrt(minR2_m);}
302
304 double getRingMaxR() const {return std::sqrt(maxR2_m);}
305
315 void lockRing();
316
319
321 std::vector<RingSection*> getSectionsAt(const Vector_t& pos);
322
324 static inline Vector_t convert(const Vector3D& vec);
325
327 static inline Vector3D convert(const Vector_t& vec);
328
329 private:
330 // Force end to have azimuthal angle > start unless crossing phi = pi/-pi
331 void resetAzimuths();
332
333 // check for closure; throw an exception is ring is not closed within
334 // tolerance; enforce closure to floating point precision
335 void checkAndClose();
336
337 // build a map that maps section to sections that overlap it
338 void buildRingSections();
339
340 void rotateToCyclCoordinates(Euclid3D& euclid3d) const;
341
342 // predicate for sorting
343 static bool sectionCompare(RingSection const* const sec1,
344 RingSection const* const sec2);
345
348
350 Ring& operator=(const Ring& ring);
351
352 void checkMidplane(Euclid3D delta) const;
354
356
357 // points to same location as RefPartBunch_m on the child bunch, but we
358 // rename to keep in line with style guide
359 //
360 // Ring borrows this memory
362
363 // store for particles out of the aperture
364 //
365 // Ring owns this memory
367
368 // initial position of the beam
372
373 // position, orientation of the first lattice element
377
378 // aperture cut on the ring (before any field maps tracking)
379 // note we store r^2
380 bool willDoAperture_m = false;
381 double minR2_m;
382 double maxR2_m;
383
384 // Ring is locked - new elements cannot be added
386
387 // Set to false to enable a non-circular ring (e.g. some weird spiral
388 // geometry)
390
391 // number of cells/rotational symmetry of the ring
393
394 double scale_m = 1.;
395
396 // rf harmonic number
398
399 // nominal rf frequency
400 double rfFreq_m;
401
402 // vector of RingSection sorted by phi (Component placement)
403 double phiStep_m;
404 std::vector<RingSectionList> ringSections_m;
406
407 // tolerance on checking for geometry consistency
408 static const double lengthTolerance_m;
409 static const double angleTolerance_m;
410};
411
413 return Vector_t(vec_3d(0), vec_3d(1), vec_3d(2));
414}
415
417 return Vector3D(vec_t[0], vec_t[1], vec_t[2]);
418}
419
420#endif //#ifndef RING_H
std::vector< RingSection * > RingSectionList
Definition: RingSection.h:199
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
Interface for a single beam element.
Definition: Component.h:50
Ring describes a ring type geometry for tracking.
Definition: Ring.h:64
virtual const EMField & getField() const override
Definition: Ring.h:182
double rfFreq_m
Definition: Ring.h:400
double getBeamRInit() const
Definition: Ring.h:235
bool isClosed_m
Definition: Ring.h:389
LossDataSink * lossDS_m
Definition: Ring.h:366
Vector_t getNextPosition() const
Definition: Ring.cpp:211
void buildRingSections()
Definition: Ring.cpp:350
std::vector< RingSection * > getSectionsAt(const Vector_t &pos)
Definition: Ring.cpp:177
void setSymmetry(double symmetry)
Definition: Ring.h:280
double maxR2_m
Definition: Ring.h:382
PartBunchBase< double, 3 > * getRefPartBunch() const
double getLatticePhiInit() const
Definition: Ring.h:259
double getRingMinR() const
Definition: Ring.h:301
Rotation3D getRotationStartToEnd(Euclid3D delta) const
Definition: Ring.cpp:181
double beamPhiInit_m
Definition: Ring.h:371
virtual EMField & getField() override
Definition: Ring.h:179
double minR2_m
Definition: Ring.h:381
bool willDoAperture_m
Definition: Ring.h:380
static bool sectionCompare(RingSection const *const sec1, RingSection const *const sec2)
Definition: Ring.cpp:371
Vector_t getNextNormal() const
Definition: Ring.cpp:220
double getBeamPRInit() const
Definition: Ring.h:247
virtual void finalise() override
Definition: Ring.cpp:167
void checkAndClose()
Definition: Ring.cpp:335
void resetAzimuths()
Definition: Ring.cpp:320
double getSymmetry() const
Definition: Ring.h:286
virtual ~Ring()
Definition: Ring.cpp:94
virtual bool apply(const size_t &id, const double &t, Vector_t &E, Vector_t &B) override
Definition: Ring.cpp:99
Ring & operator=(const Ring &ring)
RingSection * getLastSectionPlaced() const
Definition: Ring.cpp:364
void setBeamRInit(double rInit)
Definition: Ring.h:232
virtual const PlanarArcGeometry & getGeometry() const override
Definition: Ring.h:188
void setIsClosed(bool isClosed)
Definition: Ring.h:289
void setLatticeThetaInit(double thetaInit)
Definition: Ring.h:271
void setRefPartBunch(PartBunchBase< double, 3 > *bunch)
Definition: Ring.cpp:172
virtual ElementBase * clone() const override
Definition: Ring.h:155
void setHarmonicNumber(double cyclHarm)
Definition: Ring.h:219
void setLatticePhiInit(double phiInit)
Definition: Ring.h:256
virtual bool bends() const override
Definition: Ring.h:141
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: Ring.cpp:162
double getLatticeThetaInit() const
Definition: Ring.h:277
double latticeThetaInit_m
Definition: Ring.h:376
std::vector< RingSectionList > ringSections_m
Definition: Ring.h:404
virtual void accept(BeamlineVisitor &visitor) const override
Definition: Ring.cpp:60
void setRingAperture(double minR, double maxR)
Definition: Ring.cpp:376
double beamRInit_m
Definition: Ring.h:369
void setScale(double scale)
Definition: Ring.h:283
double latticePhiInit_m
Definition: Ring.h:375
RingSectionList section_list_m
Definition: Ring.h:405
double getBeamPhiInit() const
Definition: Ring.h:241
void setBeamPRInit(double pRInit)
Definition: Ring.h:244
double getIsClosed() const
Definition: Ring.h:292
double scale_m
Definition: Ring.h:394
double getRingMaxR() const
Definition: Ring.h:304
void checkMidplane(Euclid3D delta) const
Definition: Ring.cpp:192
double beamPRInit_m
Definition: Ring.h:370
void setLossDataSink(LossDataSink *sink)
Definition: Ring.cpp:146
int symmetry_m
Definition: Ring.h:392
void setBeamPhiInit(double phiInit)
Definition: Ring.h:238
double latticeRInit_m
Definition: Ring.h:374
PlanarArcGeometry planarArcGeometry_m
Definition: Ring.h:355
double getHarmonicNumber()
Definition: Ring.h:222
virtual void getDimensions(double &zBegin, double &zEnd) const override
Definition: Ring.cpp:151
void setRFFreq(double rfFreq)
Definition: Ring.h:226
double phiStep_m
Definition: Ring.h:403
void lockRing()
Definition: Ring.cpp:289
PartBunchBase< double, 3 > * getLossDataSink() const
double getRFFreq() const
Definition: Ring.h:229
void setLatticeRInit(double rInit)
Definition: Ring.h:250
virtual PlanarArcGeometry & getGeometry() override
Definition: Ring.h:185
bool isLocked_m
Definition: Ring.h:385
void appendElement(const Component &element)
Definition: Ring.cpp:229
void rotateToCyclCoordinates(Euclid3D &euclid3d) const
Definition: Ring.cpp:202
static Vector_t convert(const Vector3D &vec)
Definition: Ring.h:412
double cyclHarm_m
Definition: Ring.h:397
double getLatticeRInit() const
Definition: Ring.h:253
static const double lengthTolerance_m
Definition: Ring.h:408
PartBunchBase< double, 3 > * refPartBunch_m
Definition: Ring.h:361
static const double angleTolerance_m
Definition: Ring.h:409
Displacement and rotation in space.
Definition: Euclid3D.h:68
A simple arc in the XZ plane.
Rotation in 3-dimensional space.
Definition: Rotation3D.h:46
A 3-dimension vector.
Definition: Vector3D.h:31
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
Component placement handler in ring geometry.
Definition: RingSection.h:67
Definition: Vec.h:22
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6