OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OpalCyclotron.cpp
Go to the documentation of this file.
1//
2// Class OpalCyclotron
3// The OpalCyclotron element.
4//
5// Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
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
23#include "Physics/Units.h"
26#include "TrimCoils/TrimCoil.h"
28
29#include <numeric>
30
31
33 OpalElement(SIZE, "CYCLOTRON",
34 "The \"CYCLOTRON\" defines a cyclotron"),
35 obgeo_m(nullptr) {
37 ("CYHARMON", "The harmonic number of the cyclotron");
38
40 ("SYMMETRY", "Defines how the field is stored");
41
43 ("RINIT", "Initial radius of the reference particle [mm]");
44
46 ("PRINIT", "Initial radial momentum of the reference particle, pr=beta_r*gamma");
47
49 ("PHIINIT", "Initial azimuth of the reference particle [deg]");
50
52 ("ZINIT", "Initial z-coordinate of the reference particle [mm] (default=0 mm)", 0.0);
53
55 ("PZINIT", "Initial vertical momentum of the reference particle, pz=beta_z*gamma (default=0)", 0.0);
56
58 ("FMAPFN", "Filename for the B fieldmap");
59
61 ("BSCALE", "Scale factor for the B-field (default=1)", 1.0);
62
64 ("RFFREQ", "RF Frequency(ies) [MHz]");
65
67 ("ESCALE", "Scale factor for the RF field(s)");
68
70 ("SUPERPOSE", "If TRUE, all of the electric field maps are superposed, only used when TYPE=BANDRF");
71
73 ("RFMAPFN", "Filename(s) for the RF fieldmap(s)");
74
76 ("RFFCFN", "Filename(s) for the RF Frequency Coefficients");
77
79 ("RFVCFN", "Filename(s) for the RF Voltage Coefficients");
80
82 ("RFPHI", "Initial phase(s) of the electric field map(s) [rad]");
83
85 ("MINZ","Minimal vertical extent of the machine [mm] (default=-10000 mm)",-10000.0);
86
88 ("MAXZ","Maximal vertical extent of the machine [mm] (default=10000 mm)",10000.0);
89
91 ("MINR","Minimal radial extent of the machine [mm] (default=0 mm)", 0.0);
92
94 ("MAXR","Maximal radial extent of the machine [mm] (default=10000 mm)", 10000.0);
95
97 ("GEOMETRY", "Boundary Geometry for the cyclotron");
98
100 ("FMLOWE", "Minimal Energy [GeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
101
103 ("FMHIGHE", "Maximal Energy [GeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
104
106 ("SPIRAL", "Flag whether or not this is a spiral inflector simulation (default=FALSE)", false);
107
109 ("TRIMCOILTHRESHOLD", "Minimum magnetic field [T] for which trim coils are applied (default=0.0)", 0.0);
110
112 ("TRIMCOIL", "List of trim coils");
113
115
116 setElement(new CyclotronRep("CYCLOTRON"));
117}
118
120 OpalElement(name, parent),
121 obgeo_m(nullptr) {
123}
124
125
128
129
131 return new OpalCyclotron(name, this);
132}
133
134
136
137 CyclotronRep* cycl =
138 dynamic_cast<CyclotronRep*>(getElement());
139
140 std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
141 std::string type = Attributes::getString(itsAttr[TYPE]);
142
143 double harmnum = Attributes::getReal(itsAttr[CYHARMON]);
144 double symmetry = Attributes::getReal(itsAttr[SYMMETRY]);
145 double bscale = Attributes::getReal(itsAttr[BSCALE]);
146
147 double rinit = Units::mm2m * Attributes::getReal(itsAttr[RINIT]);
149 double zinit = Units::mm2m * Attributes::getReal(itsAttr[ZINIT]);
150 double prinit = Attributes::getReal(itsAttr[PRINIT]);
151 double pzinit = Attributes::getReal(itsAttr[PZINIT]);
152
157
160
161 bool spiral_flag = Attributes::getBool(itsAttr[SPIRAL]);
162 double trimCoilThreshold = Units::T2kG * Attributes::getReal(itsAttr[TRIMCOILTHRESHOLD]);
163
164 cycl->setFieldMapFN(fmapfm);
165 cycl->setSymmetry(symmetry);
166 cycl->setBScale(bscale);
167
168 cycl->setRinit(rinit);
169 cycl->setPRinit(prinit);
170 cycl->setPHIinit(phiinit);
171 cycl->setZinit(zinit);
172 cycl->setPZinit(pzinit);
173
174 cycl->setCyclotronType(type);
175 cycl->setCyclHarm(harmnum);
176
177 cycl->setMinR(minr);
178 cycl->setMaxR(maxr);
179 cycl->setMinZ(minz);
180 cycl->setMaxZ(maxz);
181
182 cycl->setFMLowE(fmLowE);
183 cycl->setFMHighE(fmHighE);
184
185 cycl->setSpiralFlag(spiral_flag);
186 cycl->setTrimCoilThreshold(trimCoilThreshold);
187
189
190 std::vector<std::string> fm_str = Attributes::getStringArray(itsAttr[RFMAPFN]);
191 std::vector<std::string> rffcfn_str = Attributes::getStringArray(itsAttr[RFFCFN]);
192 std::vector<std::string> rfvcfn_str = Attributes::getStringArray(itsAttr[RFVCFN]);
193 std::vector<double> scale_str = Attributes::getRealArray(itsAttr[ESCALE]);
194 std::vector<double> phi_str = Attributes::getRealArray(itsAttr[RFPHI]);
195 std::vector<double> rff_str = Attributes::getRealArray(itsAttr[RFFREQ]);
196 std::vector<bool> superpose_str = Attributes::getBoolArray(itsAttr[SUPERPOSE]);
197 std::vector<std::string> trimcoil = Attributes::getStringArray(itsAttr[TRIMCOIL]);
198
199 if ( !trimcoil.empty() ) {
200
201 std::vector<TrimCoil* > trimcoils;
202
203 for (std::vector<std::string>::const_iterator tit = trimcoil.begin();
204 tit != trimcoil.end(); ++tit)
205 {
207
208 if ( tc ) {
209 tc->initOpalTrimCoil();
210 trimcoils.push_back(tc->trimcoil_m.get());
211 }
212 }
213 cycl->setTrimCoils(trimcoils);
214 }
215
216 cycl->setRfPhi(phi_str);
217 cycl->setEScale(scale_str);
218 cycl->setRfFieldMapFN(fm_str);
219 cycl->setRFFCoeffFN(rffcfn_str);
220 cycl->setRFVCoeffFN(rfvcfn_str);
221 cycl->setRfFrequ(rff_str);
222 cycl->setSuperpose(superpose_str);
223
224 if (itsAttr[GEOMETRY] && obgeo_m == nullptr) {
226 if (obgeo_m) {
228 }
229 }
230
231 // Transmit "unknown" attributes.
233}
const std::string name
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
bool getBool(const Attribute &attr)
Return logical value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
constexpr double GeV2MeV
Definition Units.h:80
constexpr double mm2m
Definition Units.h:29
constexpr double T2kG
Definition Units.h:56
constexpr double deg2rad
Definition Units.h:143
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
void setTrimCoilThreshold(double)
void setZinit(double zinit)
void setSpiralFlag(bool spiral_flag)
void setSuperpose(std::vector< bool > flag)
void setMinR(double r)
void setRfPhi(std::vector< double > f)
void setRFVCoeffFN(std::vector< std::string > rfv_coeff_fn)
void setPZinit(double zinit)
void setCyclotronType(const std::string &type)
void setEScale(std::vector< double > bs)
void setSymmetry(double symmetry)
void setMaxR(double r)
void setFieldMapFN(const std::string &fmapfn)
void setMaxZ(double z)
void setTrimCoils(const std::vector< TrimCoil * > &trimcoils)
void setCyclHarm(double h)
void setPHIinit(double phiinit)
void setRfFrequ(std::vector< double > f)
void setPRinit(double prinit)
void setRfFieldMapFN(std::vector< std::string > rffmapfn)
void setFMHighE(double e)
void setMinZ(double z)
void setRinit(double rinit)
void setRFFCoeffFN(std::vector< std::string > rff_coeff_fn)
void setFMLowE(double e)
void setBScale(double bs)
virtual void setBoundaryGeometry(BoundaryGeometry *geo)
void setOutputFN(std::string fn)
Set output filename.
static OpalTrimCoil * find(const std::string &name)
Find named trim coil.
std::unique_ptr< TrimCoil > trimcoil_m
Actual implementation.
void initOpalTrimCoil()
Initialise implementation.
virtual void update()
Update the embedded CLASSIC cavity.
virtual ~OpalCyclotron()
BoundaryGeometry * obgeo_m
virtual OpalCyclotron * clone(const std::string &name)
Make clone.
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown'' (not known to OPAL) attributes to CLASSIC.
OpalElement(int size, const char *name, const char *help)
Exemplar constructor.
void registerOwnership() const
static BoundaryGeometry * find(const std::string &name)