OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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 an 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", 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) [deg]");
83
85 ("MINZ","Minimal vertical extent of the machine [mm]",-10000.0);
86
88 ("MAXZ","Maximal vertical extent of the machine [mm]",10000.0);
89
91 ("MINR","Minimal radial extent of the machine [mm]", 0.0);
92
94 ("MAXR","Maximal radial extent of the machine [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", false);
107
109 ("TRIMCOILTHRESHOLD","Minimum magnetic field [T] for which trim coils are applied", 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
127{}
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 rinit = Attributes::getReal(itsAttr[RINIT]);
146 double prinit = Attributes::getReal(itsAttr[PRINIT]);
147 double phiinit = Attributes::getReal(itsAttr[PHIINIT]);
148 double zinit = Attributes::getReal(itsAttr[ZINIT]);
149 double pzinit = Attributes::getReal(itsAttr[PZINIT]);
150 double bscale = Attributes::getReal(itsAttr[BSCALE]);
151
152 double minz = Attributes::getReal(itsAttr[MINZ]);
153 double maxz = Attributes::getReal(itsAttr[MAXZ]);
154 double minr = Attributes::getReal(itsAttr[MINR]);
155 double maxr = Attributes::getReal(itsAttr[MAXR]);
156
157 double fmLowE = Attributes::getReal(itsAttr[FMLOWE]);
158 double fmHighE = Attributes::getReal(itsAttr[FMHIGHE]);
159
160 bool spiral_flag = Attributes::getBool(itsAttr[SPIRAL]);
161 double trimCoilThreshold = Attributes::getReal(itsAttr[TRIMCOILTHRESHOLD]);
162
163 cycl->setFieldMapFN(fmapfm);
164 cycl->setSymmetry(symmetry);
165
166 cycl->setRinit(rinit);
167 cycl->setPRinit(prinit);
168 cycl->setPHIinit(phiinit);
169 cycl->setZinit(zinit);
170 cycl->setPZinit(pzinit);
171
172 cycl->setBScale(bscale);
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 * Units::GeV2MeV);
183 cycl->setFMHighE(fmHighE * Units::GeV2MeV);
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}
@ 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 makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Definition: Attributes.cpp:473
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
std::vector< bool > getBoolArray(const Attribute &attr)
Get logical array value.
Definition: Attributes.cpp:141
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:478
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeBoolArray(const std::string &name, const std::string &help)
Create a logical array attribute.
Definition: Attributes.cpp:136
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
constexpr double GeV2MeV
Definition: Units.h:80
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
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)
Definition: Cyclotron.cpp:163
void setZinit(double zinit)
Definition: Cyclotron.cpp:147
void setSpiralFlag(bool spiral_flag)
Definition: Cyclotron.cpp:171
void setSuperpose(std::vector< bool > flag)
Definition: Cyclotron.cpp:235
void setMinR(double r)
Definition: Cyclotron.cpp:309
void setRfPhi(std::vector< double > f)
Definition: Cyclotron.cpp:209
void setRFVCoeffFN(std::vector< std::string > rfv_coeff_fn)
Definition: Cyclotron.cpp:205
void setPZinit(double zinit)
Definition: Cyclotron.cpp:155
void setCyclotronType(const std::string &type)
Definition: Cyclotron.cpp:256
void setEScale(std::vector< double > bs)
Definition: Cyclotron.cpp:280
void setSymmetry(double symmetry)
Definition: Cyclotron.cpp:248
void setMaxR(double r)
Definition: Cyclotron.cpp:315
void setFieldMapFN(const std::string &fmapfn)
Definition: Cyclotron.cpp:179
void setMaxZ(double z)
Definition: Cyclotron.cpp:339
void setTrimCoils(const std::vector< TrimCoil * > &trimcoils)
Definition: Cyclotron.cpp:349
void setCyclHarm(double h)
Definition: Cyclotron.cpp:268
void setPHIinit(double phiinit)
Definition: Cyclotron.cpp:139
void setRfFrequ(std::vector< double > f)
Definition: Cyclotron.cpp:222
void setPRinit(double prinit)
Definition: Cyclotron.cpp:131
void setRfFieldMapFN(std::vector< std::string > rffmapfn)
Definition: Cyclotron.cpp:197
void setFMHighE(double e)
Definition: Cyclotron.cpp:361
void setMinZ(double z)
Definition: Cyclotron.cpp:329
void setRinit(double rinit)
Definition: Cyclotron.cpp:123
void setRFFCoeffFN(std::vector< std::string > rff_coeff_fn)
Definition: Cyclotron.cpp:201
void setFMLowE(double e)
Definition: Cyclotron.cpp:353
void setBScale(double bs)
Definition: Cyclotron.cpp:272
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.
Definition: OpalTrimCoil.h:69
void initOpalTrimCoil()
Initialise implementation.
virtual void update()
Update the embedded CLASSIC cavity.
virtual ~OpalCyclotron()
BoundaryGeometry * obgeo_m
Definition: OpalCyclotron.h:79
virtual OpalCyclotron * clone(const std::string &name)
Make clone.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
void registerOwnership() const
static BoundaryGeometry * find(const std::string &name)