OpalCyclotron.cpp 9.73 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// ------------------------------------------------------------------------
// $RCSfile: OpalCyclotron.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalCyclotron
//   The class of OPAL cyclotron.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:39 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------

snuverink_j's avatar
snuverink_j committed
19 20
#include <numeric>

gsell's avatar
gsell committed
21 22 23 24
#include "Elements/OpalCyclotron.h"
#include "AbstractObjects/Attribute.h"
#include "Attributes/Attributes.h"
#include "BeamlineCore/CyclotronRep.h"
adelmann's avatar
adelmann committed
25
#include "Structure/BoundaryGeometry.h"
gsell's avatar
gsell committed
26
#include "Physics/Physics.h"
27
#include "Utilities/OpalException.h"
gsell's avatar
gsell committed
28

frey_m's avatar
frey_m committed
29 30 31
#include "TrimCoils/OpalTrimCoil.h"
#include "TrimCoils/TrimCoil.h"

gsell's avatar
gsell committed
32 33 34 35 36
// Class OpalCyclotron
// ------------------------------------------------------------------------

OpalCyclotron::OpalCyclotron():
    OpalElement(SIZE, "CYCLOTRON",
adelmann's avatar
adelmann committed
37
                "The \"CYCLOTRON\" defines an cyclotron"),
38
    obgeo_m(nullptr)  {
gsell's avatar
gsell committed
39 40
    itsAttr[CYHARMON] = Attributes::makeReal
                        ("CYHARMON", "the harmonic number of the cyclotron");
41

gsell's avatar
gsell committed
42 43
    itsAttr[SYMMETRY] = Attributes::makeReal
                        ("SYMMETRY", "defines how the field is stored");
44 45

    itsAttr[RINIT]    = Attributes::makeReal
winklehner_d's avatar
winklehner_d committed
46
                        ("RINIT", "Initial radius of the reference particle [mm]");
47 48 49 50 51 52 53 54

    itsAttr[PRINIT]   = Attributes::makeReal
                        ("PRINIT", "Initial radial momentum of the reference particle, pr = beta_r * gamma");

    itsAttr[PHIINIT]  = Attributes::makeReal
                        ("PHIINIT", "Initial azimuth of the reference particle [deg]");

    itsAttr[ZINIT]    = Attributes::makeReal
winklehner_d's avatar
winklehner_d committed
55
                        ("ZINIT", "Initial z-coordinate of the reference particle [mm]. Default = 0 mm", 0.0);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

    itsAttr[PZINIT]   = Attributes::makeReal
                        ("PZINIT", "Initial vertical momentum of the reference particle pz = beta_z * gamma. Default = 0", 0.0);

    itsAttr[FMAPFN]   = Attributes::makeString
                        ("FMAPFN", "Filename for the B fieldmap");

    itsAttr[BSCALE]   = Attributes::makeReal
                        ("BSCALE", "Scale factor for the B-field", 1.0);

    itsAttr[RFFREQ]   = Attributes::makeRealArray
                        ("RFFREQ", "RF Frequency(ies) [MHz]");

    itsAttr[ESCALE]   = Attributes::makeRealArray
                        ("ESCALE", "Scale factor for the RF field(s)");

72
    itsAttr[SUPERPOSE]= Attributes::makeBoolArray
73
                        ("SUPERPOSE", "If TRUE, all of the electric field maps are superposed, only used when TYPE = BANDRF");
74 75

    itsAttr[RFMAPFN]  = Attributes::makeStringArray
76 77 78 79
                        ("RFMAPFN", "Filename(s) for the RF fieldmap(s)");

    itsAttr[RFFCFN]   = Attributes::makeStringArray
                        ("RFFCFN", "Filename(s) for the RF Frequency Coefficients");
80

81 82 83
    itsAttr[RFVCFN]   = Attributes::makeStringArray
                        ("RFVCFN", "Filename(s) for the RF Voltage Coefficients");

84 85 86
    itsAttr[RFPHI]    = Attributes::makeRealArray
                        ("RFPHI", "Initial phase(s) of the electric field map(s) [deg]");

87
    itsAttr[TYPE]     = Attributes::makeUpperCaseString
88
                        ("TYPE", "Used to identify special cyclotron types");
89 90 91 92 93 94 95 96 97 98 99 100 101

    itsAttr[MINZ]     = Attributes::makeReal
                        ("MINZ","Minimal vertical extent of the machine [mm]",-10000.0);

    itsAttr[MAXZ]     = Attributes::makeReal
                        ("MAXZ","Maximal vertical extent of the machine [mm]",10000.0);

    itsAttr[MINR]     = Attributes::makeReal
                        ("MINR","Minimal radial extent of the machine [mm]", 0.0);

    itsAttr[MAXR]     = Attributes::makeReal
                        ("MAXR","Maximal radial extent of the machine [mm]", 10000.0);

adelmann's avatar
adelmann committed
102
    itsAttr[GEOMETRY] = Attributes::makeString
adelmann's avatar
adelmann committed
103
                        ("GEOMETRY", "Boundary Geometry for the Cyclotron");
104

105
    itsAttr[FMLOWE]     = Attributes::makeReal
frey_m's avatar
frey_m committed
106
                        ("FMLOWE", "Minimal Energy [GeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
107 108

    itsAttr[FMHIGHE]     = Attributes::makeReal
frey_m's avatar
frey_m committed
109
                        ("FMHIGHE","Maximal Energy [GeV] the fieldmap can accept. Used in GAUSSMATCHED", -1.0);
110

111 112
    itsAttr[SPIRAL]     = Attributes::makeBool
                        ("SPIRAL","Flag whether or not this is a spiral inflector simulation", false);
113 114 115 116

    itsAttr[TRIMCOILTHRESHOLD] = Attributes::makeReal
                        ("TRIMCOILTHRESHOLD","Minimum magnetic field [T] for which trim coils are applied", 0.0);

117 118
    itsAttr[TRIMCOIL]   = Attributes::makeStringArray
                        ("TRIMCOIL", "List of trim coils");
119 120


gsell's avatar
gsell committed
121
    registerStringAttribute("FMAPFN");
adelmann's avatar
adelmann committed
122
    registerStringAttribute("GEOMETRY");
gsell's avatar
gsell committed
123
    registerStringAttribute("RFMAPFN");
124
    registerStringAttribute("RFFCFN");
125
    registerStringAttribute("RFVCFN");
gsell's avatar
gsell committed
126 127 128 129 130
    registerStringAttribute("TYPE");
    registerRealAttribute("CYHARMON");
    registerRealAttribute("RINIT");
    registerRealAttribute("PRINIT");
    registerRealAttribute("PHIINIT");
131 132
    registerRealAttribute("ZINIT");
    registerRealAttribute("PZINIT");
gsell's avatar
gsell committed
133 134 135 136 137
    registerRealAttribute("SYMMETRY");
    registerRealAttribute("RFFREQ");
    registerRealAttribute("BSCALE");
    registerRealAttribute("ESCALE");
    registerRealAttribute("RFPHI");
138 139 140 141
    registerRealAttribute("MINZ");
    registerRealAttribute("MAXZ");
    registerRealAttribute("MINR");
    registerRealAttribute("MAXR");
142 143
    registerRealAttribute("FMLOWE");
    registerRealAttribute("FMHIGHE");
144
    registerRealAttribute("TRIMCOILTHRESHOLD");
145

146 147
    registerOwnership();

gsell's avatar
gsell committed
148 149 150
    setElement((new CyclotronRep("CYCLOTRON"))->makeAlignWrapper());
}

151
OpalCyclotron::OpalCyclotron(const std::string &name, OpalCyclotron *parent):
adelmann's avatar
adelmann committed
152
    OpalElement(name, parent),
153
    obgeo_m(nullptr) {
gsell's avatar
gsell committed
154 155 156 157 158 159 160 161
    setElement((new CyclotronRep(name))->makeAlignWrapper());
}


OpalCyclotron::~OpalCyclotron()
{}


162
OpalCyclotron *OpalCyclotron::clone(const std::string &name) {
gsell's avatar
gsell committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176
    return new OpalCyclotron(name, this);
}


void OpalCyclotron::
fillRegisteredAttributes(const ElementBase &base, ValueFlag flag) {
    OpalElement::fillRegisteredAttributes(base, flag);
}


void OpalCyclotron::update() {
    CyclotronRep *cycl =
        dynamic_cast<CyclotronRep *>(getElement()->removeWrappers());

177
    std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
gsell's avatar
gsell committed
178

179
    std::string type = Attributes::getString(itsAttr[TYPE]);
gsell's avatar
gsell committed
180

181
    double harmnum  = Attributes::getReal(itsAttr[CYHARMON]);
gsell's avatar
gsell committed
182
    double symmetry = Attributes::getReal(itsAttr[SYMMETRY]);
183 184 185 186 187 188
    double rinit    = Attributes::getReal(itsAttr[RINIT]);
    double prinit   = Attributes::getReal(itsAttr[PRINIT]);
    double phiinit  = Attributes::getReal(itsAttr[PHIINIT]);
    double zinit    = Attributes::getReal(itsAttr[ZINIT]);
    double pzinit   = Attributes::getReal(itsAttr[PZINIT]);
    double bscale   = Attributes::getReal(itsAttr[BSCALE]);
gsell's avatar
gsell committed
189

190 191 192 193 194
    double minz = Attributes::getReal(itsAttr[MINZ]);
    double maxz = Attributes::getReal(itsAttr[MAXZ]);
    double minr = Attributes::getReal(itsAttr[MINR]);
    double maxr = Attributes::getReal(itsAttr[MAXR]);

195
    double fmLowE  = Attributes::getReal(itsAttr[FMLOWE]);
196 197
    double fmHighE = Attributes::getReal(itsAttr[FMHIGHE]);

198
    bool spiral_flag = Attributes::getBool(itsAttr[SPIRAL]);
199
    double trimCoilThreshold = Attributes::getReal(itsAttr[TRIMCOILTHRESHOLD]);
200

gsell's avatar
gsell committed
201 202 203 204 205 206
    cycl->setFieldMapFN(fmapfm);
    cycl->setSymmetry(symmetry);

    cycl->setRinit(rinit);
    cycl->setPRinit(prinit);
    cycl->setPHIinit(phiinit);
207
    cycl->setZinit(zinit);
208
    cycl->setPZinit(pzinit);
209

gsell's avatar
gsell committed
210 211 212 213 214
    cycl->setBScale(bscale);

    cycl->setType(type);
    cycl->setCyclHarm(harmnum);

215 216 217 218 219
    cycl->setMinR(minr);
    cycl->setMaxR(maxr);
    cycl->setMinZ(minz);
    cycl->setMaxZ(maxz);

220 221 222
    cycl->setFMLowE(fmLowE);
    cycl->setFMHighE(fmHighE);

223
    cycl->setSpiralFlag(spiral_flag);
224
    cycl->setTrimCoilThreshold(trimCoilThreshold);
225

226
    std::vector<std::string> fm_str     = Attributes::getStringArray(itsAttr[RFMAPFN]);
227
    std::vector<std::string> rffcfn_str = Attributes::getStringArray(itsAttr[RFFCFN]);
228
    std::vector<std::string> rfvcfn_str = Attributes::getStringArray(itsAttr[RFVCFN]);
229 230 231 232
    std::vector<double> scale_str       = Attributes::getRealArray(itsAttr[ESCALE]);
    std::vector<double> phi_str         = Attributes::getRealArray(itsAttr[RFPHI]);
    std::vector<double> rff_str         = Attributes::getRealArray(itsAttr[RFFREQ]);
    std::vector<bool> superpose_str     = Attributes::getBoolArray(itsAttr[SUPERPOSE]);
233
    std::vector<std::string> trimcoil   = Attributes::getStringArray(itsAttr[TRIMCOIL]);
gsell's avatar
gsell committed
234

frey_m's avatar
frey_m committed
235
    if ( !trimcoil.empty() ) {
kraus's avatar
kraus committed
236

frey_m's avatar
frey_m committed
237
        std::vector<TrimCoil* > trimcoils;
kraus's avatar
kraus committed
238

frey_m's avatar
frey_m committed
239 240 241 242
        for (std::vector<std::string>::const_iterator tit = trimcoil.begin();
             tit != trimcoil.end(); ++tit)
        {
            OpalTrimCoil *tc = OpalTrimCoil::find(*tit);
kraus's avatar
kraus committed
243

frey_m's avatar
frey_m committed
244 245
            if ( tc ) {
                tc->initOpalTrimCoil();
frey_m's avatar
frey_m committed
246
                trimcoils.push_back(tc->trimcoil_m.get());
frey_m's avatar
frey_m committed
247 248
            }
        }
frey_m's avatar
frey_m committed
249
        cycl->setTrimCoils(trimcoils);
frey_m's avatar
frey_m committed
250
    }
251

gsell's avatar
gsell committed
252 253 254
    cycl->setRfPhi(phi_str);
    cycl->setEScale(scale_str);
    cycl->setRfFieldMapFN(fm_str);
255
    cycl->setRFFCoeffFN(rffcfn_str);
256
    cycl->setRFVCoeffFN(rfvcfn_str);
gsell's avatar
gsell committed
257
    cycl->setRfFrequ(rff_str);
258
    cycl->setSuperpose(superpose_str);
adelmann's avatar
adelmann committed
259

260
    if(itsAttr[GEOMETRY] && obgeo_m == nullptr) {
261
      obgeo_m = BoundaryGeometry::find(Attributes::getString(itsAttr[GEOMETRY]));
adelmann's avatar
adelmann committed
262
      if(obgeo_m) {
kraus's avatar
kraus committed
263
          cycl->setBoundaryGeometry(obgeo_m);
adelmann's avatar
adelmann committed
264 265 266
      }
    }

gsell's avatar
gsell committed
267 268
    // Transmit "unknown" attributes.
    OpalElement::updateUnknown(cycl);
269
}