OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalRingDefinition.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Chris Rogers
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * 1. Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution.
11  * 3. Neither the name of STFC nor the names of its contributors may be used to
12  * endorse or promote products derived from this software without specific
13  * prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 
30 #include <limits>
31 
32 #include "AbsBeamline/Ring.h"
33 #include "Attributes/Attributes.h"
34 #include "Physics/Physics.h"
35 
37  OpalElement(SIZE, "RINGDEFINITION",
38  "The \"RINGDEFINITION\" element defines basic ring parameters.") {
39 
40  itsAttr[HARMONIC_NUMBER] = Attributes::makeReal("HARMONIC_NUMBER",
41  "The assumed harmonic number of the ring (i.e. number of bunches in the ring on a given turn).");
42  itsAttr[LAT_RINIT] = Attributes::makeReal("LAT_RINIT",
43  "The initial radius of the first element to be placed in the ring [m].");
44  itsAttr[LAT_PHIINIT] = Attributes::makeReal("LAT_PHIINIT", "The initial angle around the ring of the first element to be placed. [deg]");
45  itsAttr[LAT_THETAINIT] = Attributes::makeReal("LAT_THETAINIT", "The angle relative to the tangent of the ring for the first element to be placed [deg].");
46  itsAttr[BEAM_PHIINIT] = Attributes::makeReal("BEAM_PHIINIT",
47  "The initial angle around the ring of the beam [deg].");
48  itsAttr[BEAM_PRINIT] = Attributes::makeReal("BEAM_PRINIT",
49  "An initial pr momentum offset of the beam.");
50  itsAttr[BEAM_RINIT] = Attributes::makeReal("BEAM_RINIT",
51  "The initial radius of the beam [m].");
53  "The rotational symmetry of the lattice.");
54  itsAttr[SCALE] = Attributes::makeReal("SCALE", "Scale the fields by a multiplicative factor",1.0);
55  // should be in RF cavity definition; this comes from cyclotron definition,
56  // but not right
58  "The nominal RF frequency of the ring [MHz].");
59  // I see also makeBool, but dont know how it works; no registerBoolAttribute
61  "Set to 'false' to disable checking for closure of the ring");
63  "Minimum allowed radius during tracking [m]. If not defined, any radius is allowed. If MIN_R is defined, MAX_R must also be defined.");
65  "Maximum allowed radius during tracking [m]. If not defined, any radius is allowed. If MAX_R is defined, MIN_R must also be defined.");
66 
67  registerRealAttribute("LAT_RINIT");
68  registerRealAttribute("LAT_PHIINIT");
69  registerRealAttribute("LAT_THETAINIT");
70  registerRealAttribute("BEAM_RINIT");
71  registerRealAttribute("BEAM_PHIINIT");
72  registerRealAttribute("BEAM_PRINIT");
73  registerRealAttribute("HARMONIC_NUMBER");
74  registerRealAttribute("SYMMETRY");
75  registerRealAttribute("SCALE");
76  registerRealAttribute("RFFREQ");
77  registerStringAttribute("IS_CLOSED");
78  registerRealAttribute("SCALE");
79  registerRealAttribute("MIN_R");
80  registerRealAttribute("MAX_R");
81 
83 
84  setElement((new Ring("RING"))->makeAlignWrapper());
85 }
86 
88  return new OpalRingDefinition(name, this);
89 }
90 
91 void OpalRingDefinition::print(std::ostream& out) const {
92  OpalElement::print(out);
93 }
94 
96  OpalElement(name, parent) {
97  setElement((new Ring(name))->makeAlignWrapper());
98 }
99 
101 
103 (const ElementBase &base, ValueFlag flag) {
105 }
106 
108  Ring *ring = dynamic_cast<Ring*>(getElement()->removeWrappers());
109  double degree = Physics::pi/180.;
110  double metres = 1e3;
115 
120 
123  ring->setIsClosed(!(Attributes::getString(itsAttr[IS_CLOSED])=="FALSE"));
124  double minR = -1;
125  double maxR = -1;
126 
127  if (itsAttr[MIN_R]) {
128  minR = Attributes::getReal(itsAttr[MIN_R]);
129  if (!itsAttr[MAX_R]) {
130  throw (""); // EXCEPTION
131  }
132  }
133  if (itsAttr[MAX_R]) {
134  maxR = Attributes::getReal(itsAttr[MAX_R]);
135  if (!itsAttr[MIN_R]) {
136  throw (""); // EXCEPTION
137  }
138  ring->setRingAperture(minR, maxR);
139  }
140 
141  setElement(ring->makeWrappers());
142 }
void setBeamRInit(double rInit)
Definition: Ring.h:232
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.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual ElementBase * removeWrappers()
Return the design element.
virtual OpalRingDefinition * clone(const std::string &name)
void setIsClosed(bool isClosed)
Definition: Ring.h:289
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
void fillRegisteredAttributes(const ElementBase &base, ValueFlag flag)
virtual ElementBase * makeWrappers()
Allow errors.
void setScale(double scale)
Definition: Ring.h:283
constexpr double pi
The value of .
Definition: Physics.h:31
void setRingAperture(double minR, double maxR)
Definition: Ring.cpp:374
Base class for all beam line elements.
Definition: OpalElement.h:41
void setBeamPRInit(double pRInit)
Definition: Ring.h:244
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
void registerOwnership() const
virtual void print(std::ostream &) const
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
void setBeamPhiInit(double phiInit)
Definition: Ring.h:238
const std::string name
void setLatticeThetaInit(double thetaInit)
Definition: Ring.h:271
Ring describes a ring type geometry for tracking.
Definition: Ring.h:64
void setRFFreq(double rfFreq)
Definition: Ring.h:226
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
void setHarmonicNumber(double cyclHarm)
Definition: Ring.h:219
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
void setLatticeRInit(double rInit)
Definition: Ring.h:250
void setLatticePhiInit(double phiInit)
Definition: Ring.h:256
void setSymmetry(double symmetry)
Definition: Ring.h:280
virtual void print(std::ostream &) const
Print the object.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307