OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
ElementBase.h
Go to the documentation of this file.
1//
2// Class ElementBase
3// The very base class for beam line representation objects. A beam line
4// is modelled as a composite structure having a single root object
5// (the top level beam line), which contains both ``single'' leaf-type
6// elements (Components), as well as sub-lines (composites).
7//
8// Interface for basic beam line object.
9// This class defines the abstract interface for all objects which can be
10// contained in a beam line. ElementBase forms the base class for two distinct
11// but related hierarchies of objects:
12// [OL]
13// [LI]
14// A set of concrete accelerator element classes, which compose the standard
15// accelerator component library (SACL).
16// [LI]
17// [/OL]
18// Instances of the concrete classes for single elements are by default
19// sharable. Instances of beam lines and integrators are by
20// default non-sharable, but they may be made sharable by a call to
21// [b]makeSharable()[/b].
22// [p]
23// An ElementBase object can return two lengths, which may be different:
24// [OL]
25// [LI]
26// The arc length along the geometry.
27// [LI]
28// The design length, often measured along a straight line.
29// [/OL]
30// Class ElementBase contains a map of name versus value for user-defined
31// attributes (see file AbsBeamline/AttributeSet.hh). The map is primarily
32// intended for processes that require algorithm-specific data in the
33// accelerator model.
34// [P]
35// The class ElementBase has as base class the abstract class RCObject.
36// Virtual derivation is used to make multiple inheritance possible for
37// derived concrete classes. ElementBase implements three copy modes:
38// [OL]
39// [LI]
40// Copy by reference: Call RCObject::addReference() and use [b]this[/b].
41// [LI]
42// Copy structure: use ElementBase::copyStructure().
43// During copying of the structure, all sharable items are re-used, while
44// all non-sharable ones are cloned.
45// [LI]
46// Copy by cloning: use ElementBase::clone().
47// This returns a full deep copy.
48// [/OL]
49//
50// Copyright (c) 200x - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
51// All rights reserved
52//
53// This file is part of OPAL.
54//
55// OPAL is free software: you can redistribute it and/or modify
56// it under the terms of the GNU General Public License as published by
57// the Free Software Foundation, either version 3 of the License, or
58// (at your option) any later version.
59//
60// You should have received a copy of the GNU General Public License
61// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
62//
63#ifndef CLASSIC_ElementBase_HH
64#define CLASSIC_ElementBase_HH
65
74
75#include <map>
76#include <ostream>
77#include <queue>
78#include <string>
79#include <utility>
80#include <vector>
81
82class BeamlineVisitor;
84class Channel;
85class ConstChannel;
87class WakeFunction;
88
89enum class ElementType: unsigned short {
90 ANY,
96 DRIFT,
98 MARKER,
99 MONITOR,
101 MULTIPOLE,
103 OFFSET,
105 PROBE,
106 RBEND,
107 RBEND3D,
108 RFCAVITY,
109 RING,
110 SBEND,
111 SBEND3D,
112 SEPTUM,
113 SOLENOID,
114 SOURCE,
115 STRIPPER,
117 UNDULATOR,
118 VACUUM,
120};
121
122enum class ApertureType: unsigned short {
127};
128
129class ElementBase: public RCObject {
130
131public:
133 explicit ElementBase(const std::string &name);
134
135 ElementBase();
136 ElementBase(const ElementBase &);
137 virtual ~ElementBase();
138
140 virtual const std::string &getName() const;
141
143 virtual void setName(const std::string &name);
144
146 virtual ElementType getType() const = 0;
147
148 std::string getTypeString() const;
149 static std::string getTypeString(ElementType type);
150
152 // Return the element geometry.
153 // Version for non-constant object.
155
157 // Return the element geometry
158 // Version for constant object.
159 virtual const BGeometryBase &getGeometry() const = 0;
160
162 // Return the entire arc length measured along the design orbit
163 virtual double getArcLength() const;
164
166 // Return the design length defined by the geometry.
167 // This may be the arc length or the straight length.
168 virtual double getElementLength() const;
169
171 // Set the design length defined by the geometry.
172 // This may be the arc length or the straight length.
173 virtual void setElementLength(double length);
174
175 virtual void getElementDimensions(double &begin,
176 double &end) const {
177 begin = 0.0;
179 }
180
182 // Return the arc length from the entrance to the origin of the element
183 // (origin >= 0)
184 virtual double getOrigin() const;
185
187 // Return the arc length from the origin to the entrance of the element
188 // (entrance <= 0)
189 virtual double getEntrance() const;
190
192 // Return the arc length from the origin to the exit of the element
193 // (exit >= 0)
194 virtual double getExit() const;
195
197 // Return the transform of the local coordinate system from the
198 // position [b]fromS[/b] to the position [b]toS[/b].
199 virtual Euclid3D getTransform(double fromS, double toS) const;
200
202 // Equivalent to getTransform(0.0, s).
203 // Return the transform of the local coordinate system from the
204 // origin and [b]s[/b].
205 virtual Euclid3D getTransform(double s) const;
206
208 // Equivalent to getTransform(getEntrance(), getExit()).
209 // Return the transform of the local coordinate system from the
210 // entrance to the exit of the element.
211 virtual Euclid3D getTotalTransform() const;
212
214 // Equivalent to getTransform(0.0, getEntrance()).
215 // Return the transform of the local coordinate system from the
216 // origin to the entrance of the element.
217 virtual Euclid3D getEntranceFrame() const;
218
220 // Equivalent to getTransform(0.0, getExit()).
221 // Return the transform of the local coordinate system from the
222 // origin to the exit of the element.
223 virtual Euclid3D getExitFrame() const;
224
226 // Returns the entrance patch (transformation) which is used to transform
227 // the global geometry to the local geometry for a misaligned element
228 // at its entrance. The default behaviour returns identity transformation.
229 // This function should be overridden by derived concrete classes which
230 // model complex geometries.
231 virtual Euclid3D getEntrancePatch() const;
232
234 // Returns the entrance patch (transformation) which is used to transform
235 // the local geometry to the global geometry for a misaligned element
236 // at its exit. The default behaviour returns identity transformation.
237 // This function should be overridden by derived concrete classes which
238 // model complex geometries.
239 virtual Euclid3D getExitPatch() const;
240
242 // If the attribute does not exist, return zero.
243 virtual double getAttribute(const std::string &aKey) const;
244
246 // If the attribute exists, return true, otherwise false.
247 virtual bool hasAttribute(const std::string &aKey) const;
248
250 virtual void removeAttribute(const std::string &aKey);
251
253 virtual void setAttribute(const std::string &aKey, double val);
254
256 // This method constructs a Channel permitting read/write access to
257 // the attribute [b]aKey[/b] and returns it.
258 // If the attribute does not exist, it returns nullptr.
259 virtual Channel *getChannel(const std::string &aKey, bool create = false);
260
262 // This method constructs a Channel permitting read-only access to
263 // the attribute [b]aKey[/b] and returns it.
264 // If the attribute does not exist, it returns nullptr.
265 virtual const ConstChannel *getConstChannel(const std::string &aKey) const;
266
268 // This method must be overridden by derived classes. It should call the
269 // method of the visitor corresponding to the element class.
270 // If any error occurs, this method throws an exception.
271 virtual void accept(BeamlineVisitor &visitor) const = 0;
272
274 // Return an identical deep copy of the element.
275 virtual ElementBase *clone() const = 0;
276
278 // Return a fresh copy of any beam line structure is made,
279 // but sharable elements remain shared.
280 virtual ElementBase *copyStructure();
281
283 bool isSharable() const;
284
286 // The whole structure depending on [b]this[/b] is marked as sharable.
287 // After this call a [b]copyStructure()[/b] call reuses the element.
288 virtual void makeSharable();
289
291 // This method stores all attributes contained in the AttributeSet to
292 // "*this". The return value [b]true[/b] indicates success.
293 bool update(const AttributeSet &);
294
296 void setElementPosition(double elemedge);
297 double getElementPosition() const;
298 bool isElementPositionSet() const;
301 virtual void setBoundaryGeometry(BoundaryGeometry *geo);
302
304 virtual BoundaryGeometry *getBoundaryGeometry() const;
305
306 virtual bool hasBoundaryGeometry() const;
307
309 virtual void setWake(WakeFunction *wf);
310
312 virtual WakeFunction *getWake() const;
313
314 virtual bool hasWake() const;
315
317
319
320 virtual bool hasParticleMatterInteraction() const;
321
324 void releasePosition();
325 void fixPosition();
326 bool isPositioned() const;
327
329 virtual CoordinateSystemTrafo getEdgeToEnd() const;
330
331 void setAperture(const ApertureType& type, const std::vector<double> &args);
332 std::pair<ApertureType, std::vector<double> > getAperture() const;
333
334 virtual bool isInside(const Vector_t &r) const;
335
336 void setMisalignment(const CoordinateSystemTrafo &cst);
337
338 void getMisalignment(double &x, double &y, double &s) const;
340
341 void setActionRange(const std::queue<std::pair<double, double> > &range);
342 void setCurrentSCoordinate(double s);
343
345 void setRotationAboutZ(double rotation);
346 double getRotationAboutZ() const;
347
349
350 virtual int getRequiredNumberOfTimeSteps() const;
351
353 void setOutputFN(std::string fn);
355 std::string getOutputFN() const;
356
357 void setFlagDeleteOnTransverseExit(bool = true);
359
360protected:
361 bool isInsideTransverse(const Vector_t &r) const;
362
363 // Sharable flag.
364 // If this flag is true, the element is always shared.
365 mutable bool shareFlag;
366
369
370 std::pair<ApertureType, std::vector<double> > aperture_m;
371
373
375
376
377private:
378 // Not implemented.
379 void operator=(const ElementBase &);
380
381 // The element's name
382 std::string elementID;
383
384 static const std::map<ElementType, std::string> elementTypeToString_s;
385
386 // The user-defined set of attributes.
388
390
392
394
400 std::queue<std::pair<double, double> > actionRange_m;
401
402 std::string outputfn_m;
405};
406
407
408// Inline functions.
409// ------------------------------------------------------------------------
410
411inline
413{ return getGeometry().getArcLength(); }
414
415inline
418
419inline
421{ getGeometry().setElementLength(length); }
422
423inline
425{ return getGeometry().getOrigin(); }
426
427inline
429{ return getGeometry().getEntrance(); }
430
431inline
433{ return getGeometry().getExit(); }
434
435inline
436Euclid3D ElementBase::getTransform(double fromS, double toS) const
437{ return getGeometry().getTransform(fromS, toS); }
438
439inline
442
443inline
445{ return getGeometry().getTransform(s); }
446
447inline
450
451inline
454
455inline
458
459inline
462
463inline
465{ return shareFlag; }
466
467inline
470
471inline
473{ return wake_m != nullptr; }
474
475inline
478
479inline
481{ return bgeometry_m != nullptr; }
482
483inline
486
487inline
489{ return parmatint_m != nullptr; }
490
491inline
493 if (positionIsFixed) return;
494
495 csTrafoGlobal2Local_m = trafo;
496}
497
498inline
502
503inline
505 CoordinateSystemTrafo ret(Vector_t({0, 0, 0}),
506 Quaternion(1, 0, 0, 0));
507
508 return ret;
509}
510
511inline
514 Quaternion(1, 0, 0, 0));
515
516 return ret;
517}
518
519inline
520void ElementBase::setAperture(const ApertureType& type, const std::vector<double> &args) {
521 aperture_m.first = type;
522 aperture_m.second = args;
523}
524
525inline
526std::pair<ApertureType, std::vector<double> > ElementBase::getAperture() const {
527 return aperture_m;
528}
529
530inline
531bool ElementBase::isInside(const Vector_t &r) const {
532 const double length = getElementLength();
533 return r(2) >= 0.0 && r(2) < length && isInsideTransverse(r);
534}
535
536inline
540
541inline
545
546inline
550
551inline
555
556inline
558 return positionIsFixed;
559}
560
561inline
562void ElementBase::setActionRange(const std::queue<std::pair<double, double> > &range) {
563 actionRange_m = range;
564
565 if (!actionRange_m.empty())
566 elementEdge_m = actionRange_m.front().first;
567}
568
569inline
570void ElementBase::setRotationAboutZ(double rotation) {
571 rotationZAxis_m = rotation;
572}
573
574inline
576 return rotationZAxis_m;
577}
578
579inline
580std::string ElementBase::getTypeString() const
581{ return getTypeString(getType());}
582
583inline
584void ElementBase::setElementPosition(double elemedge) {
585 elementPosition_m = elemedge;
586 elemedgeSet_m = true;
587}
588
589inline
591 if (elemedgeSet_m)
592 return elementPosition_m;
593
594 throw GeneralClassicException("ElementBase::getElementPosition()",
595 std::string("ELEMEDGE for \"") + getName() + "\" not set");
596}
597
598inline
600 return elemedgeSet_m;
601}
602
603inline
605 return 10;
606}
607
608inline
613
614inline
619
620#endif // CLASSIC_ElementBase_HH
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
ElementType
Definition ElementBase.h:89
ApertureType
const std::string name
Map of std::string versus double value.
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
void setElementPosition(double elemedge)
Access to ELEMEDGE attribute.
virtual ~ElementBase()
virtual Channel * getChannel(const std::string &aKey, bool create=false)
Construct a read/write channel.
virtual void setName(const std::string &name)
Set element name.
virtual const std::string & getName() const
Get element name.
virtual void removeAttribute(const std::string &aKey)
Remove an existing attribute.
virtual double getArcLength() const
Get arc length.
void fixPosition()
static const std::map< ElementType, std::string > elementTypeToString_s
Definition ElementBase.h:71
virtual double getExit() const
Get exit position.
void setAperture(const ApertureType &type, const std::vector< double > &args)
virtual const BGeometryBase & getGeometry() const =0
Get geometry.
virtual ParticleMatterInteractionHandler * getParticleMatterInteraction() const
bool getFlagDeleteOnTransverseExit() const
virtual double getElementLength() const
Get design length.
bool update(const AttributeSet &)
Update element.
virtual Euclid3D getExitPatch() const
Get patch.
bool isPositioned() const
std::pair< ApertureType, std::vector< double > > getAperture() const
std::string outputfn_m
virtual void setElementLength(double length)
Set design length.
void releasePosition()
ParticleMatterInteractionHandler * parmatint_m
virtual Euclid3D getExitFrame() const
Get transform.
CoordinateSystemTrafo misalignment_m
void setMisalignment(const CoordinateSystemTrafo &cst)
CoordinateSystemTrafo getMisalignment() const
void getMisalignment(double &x, double &y, double &s) const
virtual const ConstChannel * getConstChannel(const std::string &aKey) const
Construct a read-only channel.
void operator=(const ElementBase &)
bool deleteOnTransverseExit_m
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
virtual ElementBase * clone() const =0
Return clone.
bool elemedgeSet_m
CoordinateSystemTrafo getCSTrafoGlobal2Local() const
virtual void setAttribute(const std::string &aKey, double val)
Set value of an attribute.
virtual double getOrigin() const
Get origin position.
bool isInsideTransverse(const Vector_t &r) const
virtual Euclid3D getEntranceFrame() const
Get transform.
std::string getOutputFN() const
Get output filename.
virtual ElementType getType() const =0
Get element type std::string.
void setOutputFN(std::string fn)
Set output filename.
virtual bool isInside(const Vector_t &r) const
std::pair< ApertureType, std::vector< double > > aperture_m
virtual bool hasBoundaryGeometry() const
double elementPosition_m
ELEMEDGE attribute.
virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler *spys)
void setFlagDeleteOnTransverseExit(bool=true)
virtual Euclid3D getTransform(double fromS, double toS) const
Get transform.
virtual void makeSharable()
Set sharable flag.
virtual bool hasAttribute(const std::string &aKey) const
Test for existence of an attribute.
WakeFunction * wake_m
bool isElementPositionSet() const
bool positionIsFixed
void setRotationAboutZ(double rotation)
Set rotation about z axis in bend frame.
std::queue< std::pair< double, double > > actionRange_m
void setCSTrafoGlobal2Local(const CoordinateSystemTrafo &ori)
virtual BoundaryGeometry * getBoundaryGeometry() const
return the attached boundary geometrt object if there is any
virtual double getEntrance() const
Get entrance position.
virtual CoordinateSystemTrafo getEdgeToBegin() const
std::string getTypeString() const
double getElementPosition() const
AttributeSet userAttribs
virtual ElementBase * copyStructure()
Make a structural copy.
double getRotationAboutZ() const
BoundaryGeometry * bgeometry_m
virtual Euclid3D getTotalTransform() const
Get transform.
bool isSharable() const
Test if the element can be shared.
void setActionRange(const std::queue< std::pair< double, double > > &range)
virtual int getRequiredNumberOfTimeSteps() const
virtual Euclid3D getEntrancePatch() const
Get patch.
virtual WakeFunction * getWake() const
return the attached wake object if there is any
void setCurrentSCoordinate(double s)
std::string elementID
virtual double getAttribute(const std::string &aKey) const
Get attribute value.
virtual bool hasParticleMatterInteraction() const
virtual CoordinateSystemTrafo getEdgeToEnd() const
virtual bool hasWake() const
virtual void getElementDimensions(double &begin, double &end) const
double rotationZAxis_m
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
virtual BGeometryBase & getGeometry()=0
Get geometry.
double elementEdge_m
virtual BoundingBox getBoundingBoxInLabCoords() const
CoordinateSystemTrafo csTrafoGlobal2Local_m
Displacement and rotation in space.
Definition Euclid3D.h:68
Abstract base class for accelerator geometry classes.
Definition Geometry.h:43
virtual Euclid3D getTransform(double fromS, double toS) const =0
Get transform.
virtual Euclid3D getExitFrame() const
Get transform.
Definition Geometry.cpp:66
virtual Euclid3D getExitPatch() const
Get patch.
Definition Geometry.cpp:76
virtual void setElementLength(double length)
Set geometry length.
Definition Geometry.cpp:32
virtual double getEntrance() const
Get entrance position.
Definition Geometry.cpp:41
virtual double getExit() const
Get exit position.
Definition Geometry.cpp:46
virtual Euclid3D getTotalTransform() const
Get transform.
Definition Geometry.cpp:51
virtual double getElementLength() const =0
Get geometry length.
virtual double getOrigin() const
Get origin position.
Definition Geometry.cpp:36
virtual Euclid3D getEntranceFrame() const
Get transform.
Definition Geometry.cpp:61
virtual Euclid3D getEntrancePatch() const
Get patch.
Definition Geometry.cpp:71
virtual double getArcLength() const =0
Get arc length.
Abstract interface for read/write access to variable.
Definition Channel.h:32
Abstract interface for read-only access to variable.
Abstract base class for reference counted objects.
Definition RCObject.h:40
Vektor< double, 3 > Vector_t
Definition Vektor.h:6