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 <boost/optional.hpp>
76
77#include <map>
78#include <queue>
79#include <string>
80
81class BeamlineVisitor;
83class Channel;
84class ConstChannel;
86class WakeFunction;
87
120
127
128class ElementBase: public RCObject {
129
130public:
132 explicit ElementBase(const std::string &name);
133
134 ElementBase();
135 ElementBase(const ElementBase &);
136 virtual ~ElementBase();
137
139 virtual const std::string &getName() const;
140
142 virtual void setName(const std::string &name);
143
145 virtual ElementType getType() const = 0;
146
147 std::string getTypeString() const;
148 static std::string getTypeString(ElementType type);
149
151 // Return the element geometry.
152 // Version for non-constant object.
154
156 // Return the element geometry
157 // Version for constant object.
158 virtual const BGeometryBase &getGeometry() const = 0;
159
161 // Return the entire arc length measured along the design orbit
162 virtual double getArcLength() const;
163
165 // Return the design length defined by the geometry.
166 // This may be the arc length or the straight length.
167 virtual double getElementLength() const;
168
170 // Set the design length defined by the geometry.
171 // This may be the arc length or the straight length.
172 virtual void setElementLength(double length);
173
174 virtual void getElementDimensions(double &begin,
175 double &end) const {
176 begin = 0.0;
178 }
179
181 // Return the arc length from the entrance to the origin of the element
182 // (origin >= 0)
183 virtual double getOrigin() const;
184
186 // Return the arc length from the origin to the entrance of the element
187 // (entrance <= 0)
188 virtual double getEntrance() const;
189
191 // Return the arc length from the origin to the exit of the element
192 // (exit >= 0)
193 virtual double getExit() const;
194
196 // Return the transform of the local coordinate system from the
197 // position [b]fromS[/b] to the position [b]toS[/b].
198 virtual Euclid3D getTransform(double fromS, double toS) const;
199
201 // Equivalent to getTransform(0.0, s).
202 // Return the transform of the local coordinate system from the
203 // origin and [b]s[/b].
204 virtual Euclid3D getTransform(double s) const;
205
207 // Equivalent to getTransform(getEntrance(), getExit()).
208 // Return the transform of the local coordinate system from the
209 // entrance to the exit of the element.
211
213 // Equivalent to getTransform(0.0, getEntrance()).
214 // Return the transform of the local coordinate system from the
215 // origin to the entrance of the element.
216 virtual Euclid3D getEntranceFrame() const;
217
219 // Equivalent to getTransform(0.0, getExit()).
220 // Return the transform of the local coordinate system from the
221 // origin to the exit of the element.
222 virtual Euclid3D getExitFrame() const;
223
225 // Returns the entrance patch (transformation) which is used to transform
226 // the global geometry to the local geometry for a misaligned element
227 // at its entrance. The default behaviour returns identity transformation.
228 // This function should be overridden by derived concrete classes which
229 // model complex geometries.
230 virtual Euclid3D getEntrancePatch() const;
231
233 // Returns the entrance patch (transformation) which is used to transform
234 // the local geometry to the global geometry for a misaligned element
235 // at its exit. The default behaviour returns identity transformation.
236 // This function should be overridden by derived concrete classes which
237 // model complex geometries.
238 virtual Euclid3D getExitPatch() const;
239
241 // If the attribute does not exist, return zero.
242 virtual double getAttribute(const std::string &aKey) const;
243
245 // If the attribute exists, return true, otherwise false.
246 virtual bool hasAttribute(const std::string &aKey) const;
247
249 virtual void removeAttribute(const std::string &aKey);
250
252 virtual void setAttribute(const std::string &aKey, double val);
253
255 // This method constructs a Channel permitting read/write access to
256 // the attribute [b]aKey[/b] and returns it.
257 // If the attribute does not exist, it returns nullptr.
258 virtual Channel *getChannel(const std::string &aKey, bool create = false);
259
261 // This method constructs a Channel permitting read-only access to
262 // the attribute [b]aKey[/b] and returns it.
263 // If the attribute does not exist, it returns nullptr.
264 virtual const ConstChannel *getConstChannel(const std::string &aKey) const;
265
267 // This method must be overridden by derived classes. It should call the
268 // method of the visitor corresponding to the element class.
269 // If any error occurs, this method throws an exception.
270 virtual void accept(BeamlineVisitor &visitor) const = 0;
271
273 // Return an identical deep copy of the element.
274 virtual ElementBase *clone() const = 0;
275
277 // Return a fresh copy of any beam line structure is made,
278 // but sharable elements remain shared.
279 virtual ElementBase *copyStructure();
280
282 bool isSharable() const;
283
285 // The whole structure depending on [b]this[/b] is marked as sharable.
286 // After this call a [b]copyStructure()[/b] call reuses the element.
287 virtual void makeSharable();
288
290 // This method stores all attributes contained in the AttributeSet to
291 // "*this". The return value [b]true[/b] indicates success.
292 bool update(const AttributeSet &);
293
295 void setElementPosition(double elemedge);
296 double getElementPosition() const;
300 virtual void setBoundaryGeometry(BoundaryGeometry *geo);
301
304
305 virtual bool hasBoundaryGeometry() const;
306
308 virtual void setWake(WakeFunction *wf);
309
311 virtual WakeFunction *getWake() const;
312
313 virtual bool hasWake() const;
314
316
318
319 virtual bool hasParticleMatterInteraction() const;
320
325 bool isPositioned() const;
326
329
330 void setAperture(const ApertureType& type, const std::vector<double> &args);
331 std::pair<ApertureType, std::vector<double> > getAperture() const;
332
333 virtual bool isInside(const Vector_t &r) const;
334
336
337 void getMisalignment(double &x, double &y, double &s) const;
339
340 void setActionRange(const std::queue<std::pair<double, double> > &range);
341 void setCurrentSCoordinate(double s);
342
344 void setRotationAboutZ(double rotation);
345 double getRotationAboutZ() const;
346
348
349 virtual int getRequiredNumberOfTimeSteps() const;
350
352 void setOutputFN(std::string fn);
354 std::string getOutputFN() const;
355
358
359protected:
360 bool isInsideTransverse(const Vector_t &r) const;
361
362 // Sharable flag.
363 // If this flag is true, the element is always shared.
364 mutable bool shareFlag;
365
368
369 std::pair<ApertureType, std::vector<double> > aperture_m;
370
372
374
375
376private:
377 // Not implemented.
378 void operator=(const ElementBase &);
379
380 // The element's name
381 std::string elementID;
382
383 static const std::map<ElementType, std::string> elementTypeToString_s;
384
385 // The user-defined set of attributes.
387
389
391
393
399 std::queue<std::pair<double, double> > actionRange_m;
400
401 std::string outputfn_m;
402
404};
405
406
407// Inline functions.
408// ------------------------------------------------------------------------
409
410inline
412{ return getGeometry().getArcLength(); }
413
414inline
417
418inline
420{ getGeometry().setElementLength(length); }
421
422inline
424{ return getGeometry().getOrigin(); }
425
426inline
428{ return getGeometry().getEntrance(); }
429
430inline
432{ return getGeometry().getExit(); }
433
434inline
435Euclid3D ElementBase::getTransform(double fromS, double toS) const
436{ return getGeometry().getTransform(fromS, toS); }
437
438inline
441
442inline
444{ return getGeometry().getTransform(s); }
445
446inline
449
450inline
453
454inline
457
458inline
461
462inline
464{ return shareFlag; }
465
466inline
469
470inline
472{ return wake_m != nullptr; }
473
474inline
477
478inline
480{ return bgeometry_m != nullptr; }
481
482inline
485
486inline
488{ return parmatint_m != nullptr; }
489
490inline
492 if (positionIsFixed) return;
493
494 csTrafoGlobal2Local_m = trafo;
495}
496
497inline
501
502inline
504 CoordinateSystemTrafo ret(Vector_t(0, 0, 0),
505 Quaternion(1, 0, 0, 0));
506
507 return ret;
508}
509
510inline
513 Quaternion(1, 0, 0, 0));
514
515 return ret;
516}
517
518inline
519void ElementBase::setAperture(const ApertureType& type, const std::vector<double> &args) {
520 aperture_m.first = type;
521 aperture_m.second = args;
522}
523
524inline
525std::pair<ApertureType, std::vector<double> > ElementBase::getAperture() const {
526 return aperture_m;
527}
528
529inline
530bool ElementBase::isInside(const Vector_t &r) const {
531 const double length = getElementLength();
532 return r(2) >= 0.0 && r(2) < length && isInsideTransverse(r);
533}
534
535inline
539
540inline
544
545inline
549
550inline
554
555inline
557 return positionIsFixed;
558}
559
560inline
561void ElementBase::setActionRange(const std::queue<std::pair<double, double> > &range) {
562 actionRange_m = range;
563
564 if (!actionRange_m.empty())
565 elementEdge_m = actionRange_m.front().first;
566}
567
568inline
569void ElementBase::setRotationAboutZ(double rotation) {
570 rotationZAxis_m = rotation;
571}
572
573inline
575 return rotationZAxis_m;
576}
577
578inline
579std::string ElementBase::getTypeString() const
580{ return getTypeString(getType());}
581
582inline
583void ElementBase::setElementPosition(double elemedge) {
584 elementPosition_m = elemedge;
585 elemedgeSet_m = true;
586}
587
588inline
590 if (elemedgeSet_m)
591 return elementPosition_m;
592
593 throw GeneralClassicException("ElementBase::getElementPosition()",
594 std::string("ELEMEDGE for \"") + getName() + "\" not set");
595}
596
597inline
599 return elemedgeSet_m;
600}
601
602inline
604 return 10;
605}
606
607inline
612
613inline
618
619#endif // CLASSIC_ElementBase_HH
ElementType
Definition ElementBase.h:88
ApertureType
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
@ RFCAVITY
Definition IndexMap.cpp:171
@ MULTIPOLE
Definition IndexMap.cpp:169
@ SOLENOID
Definition IndexMap.cpp:170
@ MONITOR
Definition IndexMap.cpp:172
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.
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.
bool isInsideTransverse(const Vector_t &r) const
virtual Euclid3D getEntranceFrame() const
Get transform.
std::string getOutputFN() const
Get output filename.
virtual Euclid3D getTransform(double s) const
Get transform.
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
static const std::string type
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
Vektor< double, 3 > Vector_t