OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalTravelingWave.cpp
Go to the documentation of this file.
1 //
2 // Class OpalTravelingWave
3 // The TRAVELINGWAVE 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 //
20 #include "Attributes/Attributes.h"
22 #include "Structure/OpalWake.h"
23 #include "Physics/Physics.h"
24 
26  OpalElement(SIZE, "TRAVELINGWAVE",
27  "The \"TRAVELINGWAVE\" element defines a traveling wave structure."),
28  owk_m(NULL) {
30  ("VOLT", "RF voltage in MV/m");
32  ("DVOLT", "RF voltage error in MV/m");
34  ("FREQ", "RF frequency in MHz");
36  ("LAG", "Phase lag in rad");
38  ("DLAG", "Phase lag error in rad");
40  ("FMAPFN", "Filename for the fieldmap");
42  ("FAST", "Faster but less accurate", true);
44  ("APVETO", "Do not use this cavity in the Autophase procedure", false);
46  ("NUMCELLS", "Number of cells in a TW structure");
48  ("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
50  ("MODE", "The phase shift between neighboring cells in 2*pi", 1.0/3.0);
51 
53 
54  setElement(new TravelingWaveRep("TRAVELINGWAVE"));
55 }
56 
57 
59  OpalElement(name, parent),
60  owk_m(NULL) {
62 }
63 
64 
66  delete owk_m;
67 }
68 
69 
71  return new OpalTravelingWave(name, this);
72 }
73 
74 
77 
78  TravelingWaveRep *rfc =
79  dynamic_cast<TravelingWaveRep *>(getElement());
80 
81  double length = Attributes::getReal(itsAttr[LENGTH]);
82  double vPeak = Attributes::getReal(itsAttr[VOLT]);
83  double vPeakError = Attributes::getReal(itsAttr[DVOLT]);
84  double phase = Attributes::getReal(itsAttr[LAG]);
85  double phaseError = Attributes::getReal(itsAttr[DLAG]);
86  double freq = (1.0e6 * Physics::two_pi) * Attributes::getReal(itsAttr[FREQ]);
87  std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
88  bool fast = Attributes::getBool(itsAttr[FAST]);
89  bool apVeto = Attributes::getBool(itsAttr[APVETO]);
90 
91  // std::string type = Attributes::getString(itsAttr[TYPE]);
92  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
93 
94  rfc->setElementLength(length);
95  rfc->setAmplitude(1.0e6 * vPeak);
96  rfc->setFrequency(freq);
97  rfc->setPhase(phase);
98 
99  rfc->setFieldMapFN(fmapfm);
100  rfc->setFast(fast);
101  rfc->setAutophaseVeto(apVeto);
102  rfc->setAmplitudem(vPeak);
103  rfc->setAmplitudeError(vPeakError);
104  rfc->setFrequencym(freq);
105  rfc->setPhasem(phase);
106  rfc->setPhaseError(phaseError);
109  rfc->setDesignEnergy(kineticEnergy);
110 
111  if(itsAttr[WAKEF] && owk_m == NULL) {
112  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
113  owk_m->initWakefunction(*rfc);
114  rfc->setWake(owk_m->wf_m);
115  }
116 
117  // Transmit "unknown" attributes.
119 }
@ 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
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
constexpr double two_pi
The value of.
Definition: Physics.h:33
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:125
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:281
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:436
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
virtual void setAmplitudeError(double vPeakError)
Definition: RFCavity.h:378
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:368
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:418
virtual void setFrequencym(double freq)
Definition: RFCavity.h:393
virtual void setAutophaseVeto(bool veto=true)
Definition: RFCavity.h:448
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:343
virtual void setFast(bool fast)
Definition: RFCavity.h:438
virtual void setFieldMapFN(std::string fmapfn)
Set the name of the field map.
Definition: RFCavity.h:358
void setNumCells(int NumCells)
void setMode(double mode)
virtual void setPhasem(double phase) override
virtual void setPhase(double phi)
Set phase.
virtual void setFrequency(double f)
Set frequency.
virtual void setAmplitude(double V)
Set amplitude.
virtual void updateUnknown(ElementBase *)
Transmit the `‘unknown’' (not known to OPAL) attributes to CLASSIC.
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const
virtual void update()
Update the embedded CLASSIC cavity.
OpalTravelingWave()
Exemplar constructor.
virtual OpalTravelingWave * clone(const std::string &name)
Make clone.
WakeFunction * wf_m
Definition: OpalWake.h:57
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:125
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:146