OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalSolenoid.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalSolenoid.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalSolenoid
10 // The class of OPAL solenoids.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:40 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Elements/OpalSolenoid.h"
21 #include "Attributes/Attributes.h"
23 #include "Physics/Physics.h"
24 
25 
26 // Class OpalSolenoid
27 // ------------------------------------------------------------------------
28 
30  OpalElement(SIZE, "SOLENOID",
31  "The \"SOLENOID\" element defines a Solenoid.") {
33  ("KS", "Normalised solenoid strength in m**(-1)");
35  ("DKS", "Normalised solenoid strength error in m**(-1)");
37  ("FMAPFN", "Solenoid field map filename ");
39  ("FAST", "Faster but less accurate", true);
40 
42  registerRealAttribute("DKS");
43  registerStringAttribute("FMAPFN");
44 
46 
47  setElement((new SolenoidRep("SOLENOID"))->makeAlignWrapper());
48 }
49 
50 
51 OpalSolenoid::OpalSolenoid(const std::string &name, OpalSolenoid *parent):
52  OpalElement(name, parent) {
53  setElement((new SolenoidRep(name))->makeAlignWrapper());
54 }
55 
56 
58 {}
59 
60 
61 OpalSolenoid *OpalSolenoid::clone(const std::string &name) {
62  return new OpalSolenoid(name, this);
63 }
64 
65 
66 void OpalSolenoid::
69 
70  if(flag != ERROR_FLAG) {
71  const SolenoidRep *sol =
72  dynamic_cast<const SolenoidRep *>(base.removeWrappers());
73  double length = sol->getElementLength();
74  double ks = length * sol->getBz() * Physics::c / OpalData::getInstance()->getP0();
75  attributeRegistry["KS"]->setReal(ks);
76  }
77 }
78 
79 
82 
83  SolenoidRep *sol =
84  dynamic_cast<SolenoidRep *>(getElement()->removeWrappers());
85  double length = Attributes::getReal(itsAttr[LENGTH]);
87  bool fast = Attributes::getBool(itsAttr[FAST]);
88 
89  sol->setElementLength(length);
91  sol->setFast(fast);
92  sol->setBz(Bz);
95 
96  // Transmit "unknown" attributes.
98 }
OpalSolenoid()
Exemplar constructor.
virtual void update()
Update the embedded CLASSIC solenoid.
static AttCell * registerStringAttribute(const std::string &name)
Register a ``string&#39;&#39; element attribute.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
double getP0() const
Return value of global reference momentum.
Definition: OpalData.cpp:623
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual void setBz(double Bz)
Set field.
virtual ElementBase * removeWrappers()
Return the design element.
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:515
virtual ~OpalSolenoid()
void setKS(double ks)
Definition: Solenoid.cpp:233
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
virtual OpalSolenoid * clone(const std::string &name)
Make clone.
The SOLENOID element.
Definition: OpalSolenoid.h:28
virtual double getElementLength() const override
Get design length.
Definition: Solenoid.cpp:256
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
Tepresentation for a solenoid magnet.
Definition: SolenoidRep.h:32
static OpalData * getInstance()
Definition: OpalData.cpp:209
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
void setFast(bool fast)
Definition: Solenoid.cpp:79
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
Base class for all beam line elements.
Definition: OpalElement.h:41
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
virtual void update()
Update the embedded CLASSIC element.
void setFieldMapFN(std::string fn)
Definition: Solenoid.cpp:75
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
void setDKS(double ks)
Definition: Solenoid.cpp:237
virtual double getBz() const
Get field.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307