OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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 <boost/optional.hpp>
76
77#include <map>
78#include <queue>
79#include <string>
80
81class BeamlineVisitor;
83class Channel;
84class ConstChannel;
85class ParticleMatterInteractionHandler;
86class WakeFunction;
87
106
113
114class ElementBase : public RCObject {
115public:
117 explicit ElementBase(const std::string& name);
118
119 ElementBase();
120 ElementBase(const ElementBase&);
121 virtual ~ElementBase();
122
124 virtual const std::string& getName() const;
125
127 virtual void setName(const std::string& name);
128
130 virtual ElementType getType() const = 0;
131
132 std::string getTypeString() const;
133 static std::string getTypeString(ElementType type);
134
136 // Return the element geometry.
137 // Version for non-constant object.
139
141 // Return the element geometry
142 // Version for constant object.
143 virtual const BGeometryBase& getGeometry() const = 0;
144
146 // Return the entire arc length measured along the design orbit
147 virtual double getArcLength() const;
148
150 // Return the design length defined by the geometry.
151 // This may be the arc length or the straight length.
152 virtual double getElementLength() const;
153
155 // Set the design length defined by the geometry.
156 // This may be the arc length or the straight length.
157 virtual void setElementLength(double length);
158
159 virtual void getElementDimensions(double& begin, double& end) const {
160 begin = 0.0;
162 }
163
165 // Return the arc length from the entrance to the origin of the element
166 // (origin >= 0)
167 virtual double getOrigin() const;
168
170 // Return the arc length from the origin to the entrance of the element
171 // (entrance <= 0)
172 virtual double getEntrance() const;
173
175 // Return the arc length from the origin to the exit of the element
176 // (exit >= 0)
177 virtual double getExit() const;
178
180 // Return the transform of the local coordinate system from the
181 // position [b]fromS[/b] to the position [b]toS[/b].
182 virtual Euclid3D getTransform(double fromS, double toS) const;
183
185 // Equivalent to getTransform(0.0, s).
186 // Return the transform of the local coordinate system from the
187 // origin and [b]s[/b].
188 virtual Euclid3D getTransform(double s) const;
189
191 // Equivalent to getTransform(getEntrance(), getExit()).
192 // Return the transform of the local coordinate system from the
193 // entrance to the exit of the element.
194 virtual Euclid3D getTotalTransform() const;
195
197 // Equivalent to getTransform(0.0, getEntrance()).
198 // Return the transform of the local coordinate system from the
199 // origin to the entrance of the element.
200 virtual Euclid3D getEntranceFrame() const;
201
203 // Equivalent to getTransform(0.0, getExit()).
204 // Return the transform of the local coordinate system from the
205 // origin to the exit of the element.
206 virtual Euclid3D getExitFrame() const;
207
209 // Returns the entrance patch (transformation) which is used to transform
210 // the global geometry to the local geometry for a misaligned element
211 // at its entrance. The default behaviour returns identity transformation.
212 // This function should be overridden by derived concrete classes which
213 // model complex geometries.
214 virtual Euclid3D getEntrancePatch() const;
215
217 // Returns the entrance patch (transformation) which is used to transform
218 // the local geometry to the global geometry for a misaligned element
219 // at its exit. The default behaviour returns identity transformation.
220 // This function should be overridden by derived concrete classes which
221 // model complex geometries.
222 virtual Euclid3D getExitPatch() const;
223
225 // If the attribute does not exist, return zero.
226 virtual double getAttribute(const std::string& aKey) const;
227
229 // If the attribute exists, return true, otherwise false.
230 virtual bool hasAttribute(const std::string& aKey) const;
231
233 virtual void removeAttribute(const std::string& aKey);
234
236 virtual void setAttribute(const std::string& aKey, double val);
237
239 // This method constructs a Channel permitting read/write access to
240 // the attribute [b]aKey[/b] and returns it.
241 // If the attribute does not exist, it returns nullptr.
242 virtual Channel* getChannel(const std::string& aKey, bool create = false);
243
245 // This method constructs a Channel permitting read-only access to
246 // the attribute [b]aKey[/b] and returns it.
247 // If the attribute does not exist, it returns nullptr.
248 virtual const ConstChannel* getConstChannel(const std::string& aKey) const;
249
251 // This method must be overridden by derived classes. It should call the
252 // method of the visitor corresponding to the element class.
253 // If any error occurs, this method throws an exception.
254 virtual void accept(BeamlineVisitor& visitor) const = 0;
255
257 // Return an identical deep copy of the element.
258 virtual ElementBase* clone() const = 0;
259
261 // Return a fresh copy of any beam line structure is made,
262 // but sharable elements remain shared.
263 virtual ElementBase* copyStructure();
264
266 bool isSharable() const;
267
269 // The whole structure depending on [b]this[/b] is marked as sharable.
270 // After this call a [b]copyStructure()[/b] call reuses the element.
271 virtual void makeSharable();
272
274 // This method stores all attributes contained in the AttributeSet to
275 // "*this". The return value [b]true[/b] indicates success.
276 bool update(const AttributeSet&);
277
279 void setElementPosition(double elemedge);
280 double getElementPosition() const;
284 virtual void setBoundaryGeometry(BoundaryGeometry* geo);
285
288
289 virtual bool hasBoundaryGeometry() const;
290
292 virtual void setWake(WakeFunction* wf);
293
295 virtual WakeFunction* getWake() const;
296
297 virtual bool hasWake() const;
298
299 virtual void setParticleMatterInteraction(ParticleMatterInteractionHandler* spys);
300
301 virtual ParticleMatterInteractionHandler* getParticleMatterInteraction() const;
302
303 virtual bool hasParticleMatterInteraction() const;
304
309 bool isPositioned() const;
310
313
314 void setAperture(const ApertureType& type, const std::vector<double>& args);
315 std::pair<ApertureType, std::vector<double> > getAperture() const;
316
317 virtual bool isInside(const Vector_t<double, 3>& r) const;
318
320
321 void getMisalignment(double& x, double& y, double& s) const;
323
324 void setActionRange(const std::queue<std::pair<double, double> >& range);
325 void setCurrentSCoordinate(double s);
326
328 void setRotationAboutZ(double rotation);
329 double getRotationAboutZ() const;
330
332
333 virtual int getRequiredNumberOfTimeSteps() const;
334
336 void setOutputFN(std::string fn);
338 std::string getOutputFN() const;
339
342
343protected:
344 bool isInsideTransverse(const Vector_t<double, 3>& r) const;
345
346 // Sharable flag.
347 // If this flag is true, the element is always shared.
348 mutable bool shareFlag;
349
352
353 std::pair<ApertureType, std::vector<double> > aperture_m;
354
356
358
359private:
360 // Not implemented.
361 void operator=(const ElementBase&);
362
363 // The element's name
364 std::string elementID;
365
366 static const std::map<ElementType, std::string> elementTypeToString_s;
367
368 // The user-defined set of attributes.
370
371 WakeFunction* wake_m;
372
374
375 ParticleMatterInteractionHandler* parmatint_m;
376
382 std::queue<std::pair<double, double> > actionRange_m;
383
384 std::string outputfn_m;
385
387};
388
389// Inline functions.
390// ------------------------------------------------------------------------
391
392inline double ElementBase::getArcLength() const {
393 return getGeometry().getArcLength();
394}
395
396inline double ElementBase::getElementLength() const {
397 return getGeometry().getElementLength();
398}
399
400inline void ElementBase::setElementLength(double length) {
402}
403
404inline double ElementBase::getOrigin() const {
405 return getGeometry().getOrigin();
406}
407
408inline double ElementBase::getEntrance() const {
409 return getGeometry().getEntrance();
410}
411
412inline double ElementBase::getExit() const {
413 return getGeometry().getExit();
414}
415
416inline Euclid3D ElementBase::getTransform(double fromS, double toS) const {
417 return getGeometry().getTransform(fromS, toS);
418}
419
423
424inline Euclid3D ElementBase::getTransform(double s) const {
425 return getGeometry().getTransform(s);
426}
427
431
433 return getGeometry().getExitFrame();
434}
435
439
441 return getGeometry().getExitPatch();
442}
443
444inline bool ElementBase::isSharable() const {
445 return shareFlag;
446}
447
448inline WakeFunction* ElementBase::getWake() const {
449 return wake_m;
450}
451
452inline bool ElementBase::hasWake() const {
453 return wake_m != nullptr;
454}
455
459
461 return bgeometry_m != nullptr;
462}
463
464inline ParticleMatterInteractionHandler* ElementBase::getParticleMatterInteraction() const {
465 return parmatint_m;
466}
467
469 return parmatint_m != nullptr;
470}
471
473 if (positionIsFixed)
474 return;
475
476 csTrafoGlobal2Local_m = trafo;
477}
478
482
484 CoordinateSystemTrafo ret(Vector_t<double, 3>({0, 0, 0}), Quaternion(1, 0, 0, 0));
485 return ret;
486}
487
490 Vector_t<double, 3>({0, 0, getElementLength()}), Quaternion(1, 0, 0, 0));
491
492 return ret;
493}
494
495inline void ElementBase::setAperture(const ApertureType& type, const std::vector<double>& args) {
496 aperture_m.first = type;
497 aperture_m.second = args;
498}
499
500inline std::pair<ApertureType, std::vector<double> > ElementBase::getAperture() const {
501 return aperture_m;
502}
503
504inline bool ElementBase::isInside(const Vector_t<double, 3>& r) const {
505 const double length = getElementLength();
506 return r(2) >= 0.0 && r(2) < length && isInsideTransverse(r);
507}
508
510 misalignment_m = cst;
511}
512
516
518 positionIsFixed = false;
519}
520
522 positionIsFixed = true;
523}
524
525inline bool ElementBase::isPositioned() const {
526 return positionIsFixed;
527}
528
529inline void ElementBase::setActionRange(const std::queue<std::pair<double, double> >& range) {
530 actionRange_m = range;
531
532 if (!actionRange_m.empty())
533 elementEdge_m = actionRange_m.front().first;
534}
535
536inline void ElementBase::setRotationAboutZ(double rotation) {
537 rotationZAxis_m = rotation;
538}
539
540inline double ElementBase::getRotationAboutZ() const {
541 return rotationZAxis_m;
542}
543
544inline std::string ElementBase::getTypeString() const {
545 return getTypeString(getType());
546}
547
548inline void ElementBase::setElementPosition(double elemedge) {
549 elementPosition_m = elemedge;
550 elemedgeSet_m = true;
551}
552
553inline double ElementBase::getElementPosition() const {
554 if (elemedgeSet_m)
555 return elementPosition_m;
556
558 "ElementBase::getElementPosition()",
559 std::string("ELEMEDGE for \"") + getName() + "\" not set");
560}
561
563 return elemedgeSet_m;
564}
565
567 return 10;
568}
569
573
577
578#endif // CLASSIC_ElementBase_HH
ElementType
Definition ElementBase.h:88
ApertureType
@ RFCAVITY
Definition IndexMap.cpp:170
@ MULTIPOLE
Definition IndexMap.cpp:168
@ SOLENOID
Definition IndexMap.cpp:169
ippl::Vector< T, Dim > Vector_t
PartBunch< T, Dim >::ConstIterator end(PartBunch< T, Dim > const &bunch)
PartBunch< T, Dim >::ConstIterator begin(PartBunch< T, Dim > const &bunch)
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:69
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.
ElementBase(const std::string &name)
Constructor with given name.
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.
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.
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)
bool isInsideTransverse(const Vector_t< double, 3 > &r) const
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
virtual bool isInside(const Vector_t< double, 3 > &r) 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.
RCObject()
Default constructor.
Definition RCObject.h:98