OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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 an OPALX 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
36
37bool Element::canReplaceBy(Object* object) { return (dynamic_cast<Element*>(object) != 0); }
38
39Element* Element::find(const std::string& name) {
41 Element* element = dynamic_cast<Element*>(opal->find(name));
42 if (element == 0) {
43 throw OpalException("Element::find()", "Element \"" + name + "\" not found.");
44 }
45 return element;
46}
47
48const std::string Element::getCategory() const { return "ELEMENT"; }
49
50bool Element::shouldTrace() const { return false; }
51
52bool Element::shouldUpdate() const { return false; }
53
55 switch (ref) {
56 case IS_CENTRE:
57 return (-getLength() / 2.0);
58
59 case IS_EXIT:
60 return (-getLength());
61
62 default:
63 return 0.0;
64 }
65}
66
68 switch (ref) {
69 case IS_ENTRY:
70 return getLength();
71
72 case IS_CENTRE:
73 return (getLength() / 2.0);
74
75 default:
76 return 0.0;
77 }
78}
79
80void Element::setShared(bool flag) {
82 if (flag) itsOPALXElement->makeSharable();
83}
84
85Element::Element(int size, const char* name, const char* help) : Object(size, name, help) {}
86
87Element::Element(const std::string& name, Element* parent) : Object(name, parent) {}
virtual double getEntrance(ReferenceType) const
Return arc length from origin to entrance (negative !).
Definition Element.cpp:54
virtual void setShared(bool)
Set shared flag.
Definition Element.cpp:80
virtual ~Element()
Definition Element.cpp:35
virtual const std::string getCategory() const
Return the object category as a string.
Definition Element.cpp:48
virtual double getLength() const =0
Return element length.
static Element * find(const std::string &name)
Find named Element.
Definition Element.cpp:39
ReferenceType
Reference for element positioning.
Definition Element.h:43
@ IS_EXIT
Definition Element.h:46
@ IS_ENTRY
Definition Element.h:44
@ IS_CENTRE
Definition Element.h:45
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition Element.cpp:37
virtual bool shouldTrace() const
Trace flag.
Definition Element.cpp:50
virtual bool shouldUpdate() const
Update flag.
Definition Element.cpp:52
virtual double getExit(ReferenceType) const
Return arc length from origin to exit (positive !).
Definition Element.cpp:67
std::shared_ptr< ElementBase > itsOPALXElement
Definition Element.h:113
The base class for all OPAL objects.
Definition Object.h:45
virtual void setShared(bool)
Set/reset shared flag.
Definition Object.cpp:247
The global OPAL structure.
Definition OpalData.h:45
Object * find(const std::string &name)
Find entry.
Definition OpalData.cpp:477
static OpalData * getInstance()
Definition OpalData.cpp:193