OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
OpalRingDefinition.cpp
Go to the documentation of this file.
1 //
2 // Class OpalRingDefinition
3 // The Opal Ring element.
4 //
5 // Copyright (c) 2012 - 2023, Chris Rogers, STFC Rutherford Appleton Laboratory, Didcot, UK
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
19 
20 #include "AbsBeamline/Ring.h"
21 #include "Attributes/Attributes.h"
22 #include "Physics/Units.h"
24 
25 #include <cmath>
26 #include <limits>
27 
29  OpalElement(SIZE, "RINGDEFINITION",
30  "The \"RINGDEFINITION\" element defines basic ring parameters.") {
31 
33  ("HARMONIC_NUMBER", "The assumed harmonic number of the ring (i.e. number of bunches in the ring on a given turn) (default = 1).", 1.0);
34 
36  ("LAT_RINIT", "The initial radius of the first element to be placed in the ring [m].");
37 
39  ("LAT_PHIINIT", "The initial angle around the ring of the first element to be placed. [deg]");
40 
42  ("LAT_THETAINIT", "The angle relative to the tangent of the ring for the first element to be placed [deg].");
43 
45  ("BEAM_PHIINIT", "The initial angle around the ring of the beam [deg].");
46 
48  ("BEAM_THETAINIT", "Defines an angular offset of the beam relative to the tangent vector, in the x-y plane [deg] (default = 0).", 0.0);
49 
51  ("BEAM_PRINIT", "An initial pr momentum offset of the beam.");
52 
54  ("BEAM_RINIT", "The initial radius of the beam [m].");
55 
57  ("SYMMETRY", "The rotational symmetry of the lattice.", 1.0);
58 
60  ("SCALE", "Scale the fields by a multiplicative factor", 1.0);
61 
62  // should be in RF cavity definition; this comes from cyclotron definition,
63  // but not right
65  ("RFFREQ", "The nominal RF frequency of the ring [MHz].");
66 
67  // I see also makeBool, but dont know how it works; no registerBoolAttribute
69  ("IS_CLOSED", "Set to 'false' to disable checking for closure of the ring");
70 
72  ("MIN_R", "Minimum allowed radius during tracking [m]. If not defined, any radius is allowed. If MIN_R is defined, MAX_R must also be defined.");
73 
75  ("MAX_R", "Maximum allowed radius during tracking [m]. If not defined, any radius is allowed. If MAX_R is defined, MIN_R must also be defined.");
76 
78 
79  setElement(new Ring("RING"));
80 }
81 
83  return new OpalRingDefinition(name, this);
84 }
85 
86 void OpalRingDefinition::print(std::ostream& out) const {
87  OpalElement::print(out);
88 }
89 
91  OpalElement(name, parent) {
92  setElement(new Ring(name));
93 }
94 
96 
98  Ring* ring = dynamic_cast<Ring*>(getElement());
99 
105  ring->setLatticePhiInit(Attributes::getReal(itsAttr[LAT_PHIINIT]) * Units::deg2rad);
107 
110 
114 
115  if (itsAttr[MIN_R] && itsAttr[MAX_R]) {
116  double minR = Attributes::getReal(itsAttr[MIN_R]);
117  double maxR = Attributes::getReal(itsAttr[MAX_R]);
118  ring->setRingAperture(minR, maxR);
119  } else if (itsAttr[MIN_R] && !itsAttr[MAX_R]) {
120  throw OpalException("OpalRingDefinition::update",
121  "If MIN_R is defined, MAX_R must also be defined.");
122  } else if (!itsAttr[MIN_R] && itsAttr[MAX_R]) {
123  throw OpalException("OpalRingDefinition::update",
124  "If MAX_R is defined, MIN_R must also be defined.");
125  }
126 
127  setElement(ring);
128 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
void setRFFreq(double rfFreq)
Definition: Ring.h:216
void setLatticeRInit(double rInit)
Definition: Ring.h:246
void setSymmetry(double symmetry)
Definition: Ring.h:276
void setScale(double scale)
Definition: Ring.h:279
virtual void print(std::ostream &) const
Print the object.
void setIsClosed(bool isClosed)
Definition: Ring.h:285
virtual void print(std::ostream &) const
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
void setBeamRInit(double rInit)
Definition: Ring.h:222
The base class for all OPAL exceptions.
Definition: OpalException.h:28
constexpr double deg2rad
Definition: Units.h:143
void setBeamPhiInit(double phiInit)
Definition: Ring.h:228
void setRingAperture(double minR, double maxR)
Definition: Ring.cpp:376
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
void setHarmonicNumber(double cyclHarm)
Definition: Ring.h:209
const std::string name
void setBeamPRInit(double pRInit)
Definition: Ring.h:240
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
void setLatticeThetaInit(double thetaInit)
Definition: Ring.h:267
void setBeamThetaInit(double thetaInit)
Definition: Ring.h:234
Ring describes a ring type geometry for tracking.
Definition: Ring.h:53
void registerOwnership() const
virtual OpalRingDefinition * clone(const std::string &name)
void setLatticePhiInit(double phiInit)
Definition: Ring.h:252