OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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;
41class FieldMap;
42
62class Ring : public Component {
63public:
68 Ring(std::string ring);
69
74 Ring(const Ring& ring);
75
77 virtual ~Ring();
78
92 virtual bool apply(const std::shared_ptr<ParticleContainer_t>& pc) override;
93
94 virtual bool apply(
95 const size_t& id, const double& t, Vector_t<double, 3>& E,
96 Vector_t<double, 3>& B) override;
97
114 virtual bool apply(
115 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& t,
117
126 virtual void initialise(PartBunch_t* bunch, double& startField, double& endField) override;
127
133 virtual void initialise(PartBunch_t* bunch);
134
139 virtual void finalise() override;
140
142 virtual bool bends() const override { return true; }
143
150 virtual void accept(BeamlineVisitor& visitor) const override;
151
153 virtual void getFieldExtend(double& zBegin, double& zEnd) const override;
154
156 virtual ElementBase* clone() const override { return new Ring(*this); }
157
177 void appendElement(const Component& element);
178
180 virtual EMField& getField() override {
181 throw GeneralOpalException("Ring::getField", "Not implemented");
182 }
183
185 virtual const EMField& getField() const override {
186 throw GeneralOpalException("Ring::getField", "Not implemented");
187 }
188
190 virtual PlanarArcGeometry& getGeometry() override { return planarArcGeometry_m; }
191
193 virtual const PlanarArcGeometry& getGeometry() const override { return planarArcGeometry_m; }
194
200 void setLossDataSink(LossDataSink* sink);
201
207
215 void setRefPartBunch(PartBunch_t* bunch);
216
222
224 void setHarmonicNumber(double cyclHarm) { cyclHarm_m = cyclHarm; }
225
227 double getHarmonicNumber() { return cyclHarm_m; }
228 // note this is not a const method to follow parent
229
231 void setRFFreq(double rfFreq) { rfFreq_m = rfFreq; }
232
234 double getRFFreq() const { return rfFreq_m; }
235
237 void setBeamRInit(double rInit) { beamRInit_m = rInit; }
238
240 double getBeamRInit() const { return beamRInit_m; }
241
243 void setBeamPhiInit(double phiInit) { beamPhiInit_m = phiInit; }
244
246 double getBeamPhiInit() const { return beamPhiInit_m; }
247
249 void setBeamPRInit(double pRInit) { beamPRInit_m = pRInit; }
250
252 double getBeamPRInit() const { return beamPRInit_m; }
253
255 void setLatticeRInit(double rInit) { latticeRInit_m = rInit; }
256
258 double getLatticeRInit() const { return latticeRInit_m; }
259
261 void setLatticePhiInit(double phiInit) { latticePhiInit_m = phiInit; }
262
264 double getLatticePhiInit() const { return latticePhiInit_m; }
265
268
271
276 void setLatticeThetaInit(double thetaInit) { latticeThetaInit_m = thetaInit; }
277
282 double getLatticeThetaInit() const { return latticeThetaInit_m; }
283
285 void setSymmetry(double symmetry) { symmetry_m = symmetry; }
286
288 void setScale(double scale) { scale_m = scale; }
289
291 double getSymmetry() const { return symmetry_m; }
292
294 void setIsClosed(bool isClosed) { isClosed_m = isClosed; }
295
297 double getIsClosed() const { return isClosed_m; }
298
303 void setRingAperture(double minR, double maxR);
304
306 double getRingMinR() const { return std::sqrt(minR2_m); }
307
309 double getRingMaxR() const { return std::sqrt(maxR2_m); }
310
320 void lockRing();
321
324
326 std::vector<RingSection*> getSectionsAt(const Vector_t<double, 3>& pos);
327
329 static inline Vector_t<double, 3> convert(const Vector3D& vec);
330
332 static inline Vector3D convert(const Vector_t<double, 3>& vec);
333
334private:
335 // Force end to have azimuthal angle > start unless crossing phi = pi/-pi
336 void resetAzimuths();
337
338 // check for closure; throw an exception is ring is not closed within
339 // tolerance; enforce closure to floating point precision
340 void checkAndClose();
341
342 // build a map that maps section to sections that overlap it
343 void buildRingSections();
344
345 void rotateToCyclCoordinates(Euclid3D& euclid3d) const;
346
347 // predicate for sorting
348 static bool sectionCompare(RingSection const* const sec1, RingSection const* const sec2);
349
352
354 Ring& operator=(const Ring& ring);
355
356 void checkMidplane(Euclid3D delta) const;
358
360
361 // points to same location as RefPartBunch_m on the child bunch, but we
362 // rename to keep in line with style guide
363 //
364 // Ring borrows this memory
366
367 // store for particles out of the aperture
368 //
369 // Ring owns this memory
371
372 // initial position of the beam
376
377 // position, orientation of the first lattice element
381
382 // aperture cut on the ring (before any field maps tracking)
383 // note we store r^2
384 bool willDoAperture_m = false;
385 double minR2_m;
386 double maxR2_m;
387
388 // Ring is locked - new elements cannot be added
390
391 // Set to false to enable a non-circular ring (e.g. some weird spiral
392 // geometry)
394
395 // number of cells/rotational symmetry of the ring
397
398 double scale_m = 1.;
399
400 // rf harmonic number
402
403 // nominal rf frequency
404 double rfFreq_m;
405
406 // vector of RingSection sorted by phi (Component placement)
407 double phiStep_m;
408 std::vector<RingSectionList> ringSections_m;
410
411 // tolerance on checking for geometry consistency
412 static const double lengthTolerance_m;
413 static const double angleTolerance_m;
414};
415
417 return Vector_t<double, 3>({vec_3d(0), vec_3d(1), vec_3d(2)});
418}
419
421 return Vector3D({vec_t[0], vec_t[1], vec_t[2]});
422}
423
424#endif // #ifndef RING_H
Defines the abstract interface for a single beamline component in the accelerator model.
ippl::Vector< T, Dim > Vector_t
std::vector< RingSection * > RingSectionList
Abstract base class for electromagnetic fields.
Definition EMField.h:171
Displacement and rotation in space.
Definition Euclid3D.h:67
A simple arc in the XZ plane.
Component placement handler in ring geometry.
Definition RingSection.h:67
Ring describes a ring type geometry for tracking.
Definition Ring.h:62
virtual const EMField & getField() const override
Definition Ring.h:185
double rfFreq_m
Definition Ring.h:404
double getBeamRInit() const
Definition Ring.h:240
bool isClosed_m
Definition Ring.h:393
LossDataSink * lossDS_m
Definition Ring.h:370
void buildRingSections()
Definition Ring.cpp:367
void setSymmetry(double symmetry)
Definition Ring.h:285
PartBunch_t * getRefPartBunch() const
double maxR2_m
Definition Ring.h:386
double getLatticePhiInit() const
Definition Ring.h:264
virtual void initialise(PartBunch_t *bunch, double &startField, double &endField) override
Definition Ring.cpp:187
double getRingMinR() const
Definition Ring.h:306
static Vector_t< double, 3 > convert(const Vector3D &vec)
Definition Ring.h:416
Rotation3D getRotationStartToEnd(Euclid3D delta) const
Definition Ring.cpp:206
double beamPhiInit_m
Definition Ring.h:375
virtual EMField & getField() override
Definition Ring.h:180
double minR2_m
Definition Ring.h:385
bool willDoAperture_m
Definition Ring.h:384
static bool sectionCompare(RingSection const *const sec1, RingSection const *const sec2)
Definition Ring.cpp:388
double getBeamPRInit() const
Definition Ring.h:252
virtual void finalise() override
Definition Ring.cpp:191
void checkAndClose()
Definition Ring.cpp:353
Vector_t< double, 3 > getNextPosition() const
Definition Ring.cpp:235
void resetAzimuths()
Definition Ring.cpp:338
double getSymmetry() const
Definition Ring.h:291
virtual ~Ring()
Definition Ring.cpp:102
Vector_t< double, 3 > getNextNormal() const
Definition Ring.cpp:244
Ring & operator=(const Ring &ring)
RingSection * getLastSectionPlaced() const
Definition Ring.cpp:381
void setBeamRInit(double rInit)
Definition Ring.h:237
virtual const PlanarArcGeometry & getGeometry() const override
Definition Ring.h:193
void setIsClosed(bool isClosed)
Definition Ring.h:294
void setLatticeThetaInit(double thetaInit)
Definition Ring.h:276
virtual ElementBase * clone() const override
Definition Ring.h:156
void setHarmonicNumber(double cyclHarm)
Definition Ring.h:224
void setLatticePhiInit(double phiInit)
Definition Ring.h:261
virtual bool bends() const override
Definition Ring.h:142
double getLatticeThetaInit() const
Definition Ring.h:282
double latticeThetaInit_m
Definition Ring.h:380
std::vector< RingSectionList > ringSections_m
Definition Ring.h:408
virtual void accept(BeamlineVisitor &visitor) const override
Definition Ring.cpp:69
void setRingAperture(double minR, double maxR)
Definition Ring.cpp:392
double beamRInit_m
Definition Ring.h:373
void setScale(double scale)
Definition Ring.h:288
double latticePhiInit_m
Definition Ring.h:379
RingSectionList section_list_m
Definition Ring.h:409
double getBeamPhiInit() const
Definition Ring.h:246
void setBeamPRInit(double pRInit)
Definition Ring.h:249
double getIsClosed() const
Definition Ring.h:297
double scale_m
Definition Ring.h:398
std::vector< RingSection * > getSectionsAt(const Vector_t< double, 3 > &pos)
Definition Ring.cpp:202
double getRingMaxR() const
Definition Ring.h:309
void checkMidplane(Euclid3D delta) const
Definition Ring.cpp:217
double beamPRInit_m
Definition Ring.h:374
void setLossDataSink(LossDataSink *sink)
Definition Ring.cpp:172
PartBunch_t * refPartBunch_m
Definition Ring.h:365
int symmetry_m
Definition Ring.h:396
void setBeamPhiInit(double phiInit)
Definition Ring.h:243
double latticeRInit_m
Definition Ring.h:378
void setRefPartBunch(PartBunch_t *bunch)
Definition Ring.cpp:197
PlanarArcGeometry planarArcGeometry_m
Definition Ring.h:359
double getHarmonicNumber()
Definition Ring.h:227
void setRFFreq(double rfFreq)
Definition Ring.h:231
double phiStep_m
Definition Ring.h:407
void lockRing()
Definition Ring.cpp:309
double getRFFreq() const
Definition Ring.h:234
void setLatticeRInit(double rInit)
Definition Ring.h:255
virtual PlanarArcGeometry & getGeometry() override
Definition Ring.h:190
bool isLocked_m
Definition Ring.h:389
void appendElement(const Component &element)
Definition Ring.cpp:253
virtual bool apply(const std::shared_ptr< ParticleContainer_t > &pc) override
Definition Ring.cpp:107
void rotateToCyclCoordinates(Euclid3D &euclid3d) const
Definition Ring.cpp:227
double cyclHarm_m
Definition Ring.h:401
double getLatticeRInit() const
Definition Ring.h:258
static const double lengthTolerance_m
Definition Ring.h:412
static const double angleTolerance_m
Definition Ring.h:413
virtual void getFieldExtend(double &zBegin, double &zEnd) const override
Definition Ring.cpp:177
PartBunch_t * getLossDataSink() const
Rotation in 3-dimensional space.
Definition Rotation3D.h:45
A 3-dimension vector.
Definition Vector3D.h:30