OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Element.cpp
Go to the documentation of this file.
1//
2// Class Element
3// The base class for all OPAL elements.
4// It implements the common behaviour of elements, it can also be used via
5// dynamic casting to determine whether an object represents an element.
6//
7// Each Element object contains a pointer to a CLASSIC beam line element,
8// known as the ``ideal'' element.
9//
10// If sharable flag is set, all occurrences of the element are supposed to
11// have the same imperfections. Thus the assembly is shared when it is used
12// more than once in beam lines or sequences.
13//
14// If the sharable flag is not set, each occurrence of the element is supposed
15// to have its own imperfections, but the same ideal representation.
16//
17// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
18// All rights reserved
19//
20// This file is part of OPAL.
21//
22// OPAL is free software: you can redistribute it and/or modify
23// it under the terms of the GNU General Public License as published by
24// the Free Software Foundation, either version 3 of the License, or
25// (at your option) any later version.
26//
27// You should have received a copy of the GNU General Public License
28// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
29//
33#include "Utilities/Options.h"
34
35
37{}
38
39
41 return (dynamic_cast<Element *>(object) != 0);
42}
43
44
45Element *Element::find(const std::string &name) {
47 Element *element = dynamic_cast<Element *>(opal->find(name));
48 if(element == 0) {
49 throw OpalException("Element::find()",
50 "Element \"" + name + "\" not found.");
51 }
52 return element;
53}
54
55
56const std::string Element::getCategory() const {
57 return "ELEMENT";
58}
59
60
62 return false;
63
64}
65
67 return false;
68}
69
70
72 switch(ref) {
73
74 case IS_CENTRE:
75 return (- getLength() / 2.0);
76
77 case IS_EXIT:
78 return (- getLength());
79
80 default:
81 return 0.0;
82 }
83}
84
85
87 switch(ref) {
88
89 case IS_ENTRY:
90 return getLength();
91
92 case IS_CENTRE:
93 return (getLength() / 2.0);
94
95 default:
96 return 0.0;
97 }
98}
99
100
101void Element::setShared(bool flag) {
102 Object::setShared(flag);
104}
105
106
107Element::Element(int size, const char *name, const char *help):
108 Object(size, name, help)
109{}
110
111
112Element::Element(const std::string &name, Element *parent):
113 Object(name, parent)
114{}
const std::string name
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
Definition: Element.cpp:71
virtual void setShared(bool)
Set shared flag.
Definition: Element.cpp:101
Pointer< ElementBase > itsClassicElement
Definition: Element.h:113
virtual ~Element()
Definition: Element.cpp:36
virtual const std::string getCategory() const
Return the object category as a string.
Definition: Element.cpp:56
virtual double getLength() const =0
Return element length.
static Element * find(const std::string &name)
Find named Element.
Definition: Element.cpp:45
ReferenceType
Reference for element positioning.
Definition: Element.h:44
@ IS_EXIT
Definition: Element.h:47
@ IS_ENTRY
Definition: Element.h:45
@ IS_CENTRE
Definition: Element.h:46
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition: Element.cpp:40
virtual bool shouldTrace() const
Trace flag.
Definition: Element.cpp:61
virtual bool shouldUpdate() const
Update flag.
Definition: Element.cpp:66
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
Definition: Element.cpp:86
The base class for all OPAL objects.
Definition: Object.h:48
virtual void setShared(bool)
Set/reset shared flag.
Definition: Object.cpp:278
The global OPAL structure.
Definition: OpalData.h:49
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:566
static OpalData * getInstance()
Definition: OpalData.cpp:196
virtual void makeSharable()
Set sharable flag.
The base class for all OPAL exceptions.
Definition: OpalException.h:28