OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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
60  itsAttr[IS_CLOSED] = Attributes::makeBool("IS_CLOSED",
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 
68 
69  setElement(new Ring("RING"));
70 }
71 
73  return new OpalRingDefinition(name, this);
74 }
75 
76 void OpalRingDefinition::print(std::ostream& out) const {
77  OpalElement::print(out);
78 }
79 
81  OpalElement(name, parent) {
82  setElement(new Ring(name));
83 }
84 
86 
88  Ring *ring = dynamic_cast<Ring*>(getElement());
89  double degree = Physics::pi/180.;
90  double metres = 1e3;
95 
100 
104  double minR = -1;
105  double maxR = -1;
106 
107  if (itsAttr[MIN_R]) {
109  if (!itsAttr[MAX_R]) {
110  throw (""); // EXCEPTION
111  }
112  }
113  if (itsAttr[MAX_R]) {
115  if (!itsAttr[MIN_R]) {
116  throw (""); // EXCEPTION
117  }
118  ring->setRingAperture(minR, maxR);
119  }
120 
121  setElement(ring);
122 }
@ SIZE
Definition: IndexMap.cpp:174
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
constexpr double pi
The value of.
Definition: Physics.h:30
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
Ring describes a ring type geometry for tracking.
Definition: Ring.h:64
void setSymmetry(double symmetry)
Definition: Ring.h:280
void setBeamRInit(double rInit)
Definition: Ring.h:232
void setIsClosed(bool isClosed)
Definition: Ring.h:289
void setLatticeThetaInit(double thetaInit)
Definition: Ring.h:271
void setHarmonicNumber(double cyclHarm)
Definition: Ring.h:219
void setLatticePhiInit(double phiInit)
Definition: Ring.h:256
void setRingAperture(double minR, double maxR)
Definition: Ring.cpp:378
void setScale(double scale)
Definition: Ring.h:283
void setBeamPRInit(double pRInit)
Definition: Ring.h:244
void setBeamPhiInit(double phiInit)
Definition: Ring.h:238
void setRFFreq(double rfFreq)
Definition: Ring.h:226
void setLatticeRInit(double rInit)
Definition: Ring.h:250
virtual void print(std::ostream &) const
Print the object.
void registerOwnership() const
virtual void print(std::ostream &) const
virtual OpalRingDefinition * clone(const std::string &name)