OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 #include "Physics/Units.h"
25 
27  OpalElement(SIZE, "TRAVELINGWAVE",
28  "The \"TRAVELINGWAVE\" element defines a traveling wave structure."),
29  owk_m(nullptr) {
31  ("VOLT", "RF voltage in MV/m");
33  ("DVOLT", "RF voltage error in MV/m");
35  ("FREQ", "RF frequency in MHz");
37  ("LAG", "Phase lag in rad");
39  ("DLAG", "Phase lag error in rad");
41  ("FMAPFN", "Filename for the fieldmap");
43  ("FAST", "Faster but less accurate", true);
45  ("APVETO", "Do not use this cavity in the Autophase procedure", false);
47  ("NUMCELLS", "Number of cells in a TW structure");
49  ("DESIGNENERGY", "the mean energy of the particles at exit", -1.0);
51  ("MODE", "The phase shift between neighboring cells in 2*pi", 1.0/3.0);
52 
54 
55  setElement(new TravelingWaveRep("TRAVELINGWAVE"));
56 }
57 
58 
60  OpalElement(name, parent),
61  owk_m(nullptr) {
62  setElement(new TravelingWaveRep(name));
63 }
64 
65 
67  delete owk_m;
68 }
69 
70 
72  return new OpalTravelingWave(name, this);
73 }
74 
75 
78 
79  TravelingWaveRep *rfc =
80  dynamic_cast<TravelingWaveRep *>(getElement());
81 
82  double length = Attributes::getReal(itsAttr[LENGTH]);
83  double vPeak = Attributes::getReal(itsAttr[VOLT]);
84  double vPeakError = Attributes::getReal(itsAttr[DVOLT]);
85  double phase = Attributes::getReal(itsAttr[LAG]);
86  double phaseError = Attributes::getReal(itsAttr[DLAG]);
88  std::string fmapfm = Attributes::getString(itsAttr[FMAPFN]);
89  bool fast = Attributes::getBool(itsAttr[FAST]);
90  bool apVeto = Attributes::getBool(itsAttr[APVETO]);
91 
92  // std::string type = Attributes::getString(itsAttr[TYPE]);
93  double kineticEnergy = Attributes::getReal(itsAttr[DESIGNENERGY]);
94 
95  rfc->setElementLength(length);
96  rfc->setAmplitude(Units::MVpm2Vpm * vPeak);
97  rfc->setFrequency(freq);
98  rfc->setPhase(phase);
99 
100  rfc->setFieldMapFN(fmapfm);
101  rfc->setFast(fast);
102  rfc->setAutophaseVeto(apVeto);
103  rfc->setAmplitudem(vPeak);
104  rfc->setAmplitudeError(vPeakError);
105  rfc->setFrequencym(freq);
106  rfc->setPhasem(phase);
107  rfc->setPhaseError(phaseError);
110  rfc->setDesignEnergy(kineticEnergy);
111 
112  if(itsAttr[WAKEF] && owk_m == nullptr) {
113  owk_m = (OpalWake::find(Attributes::getString(itsAttr[WAKEF])))->clone(getOpalName() + std::string("_wake"));
114  owk_m->initWakefunction(*rfc);
115  rfc->setWake(owk_m->wf_m);
116  }
117 
118  // Transmit "unknown" attributes.
120 }
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
virtual void setFast(bool fast)
Definition: RFCavity.h:419
WakeFunction * wf_m
Definition: OpalWake.h:56
virtual void setFrequencym(double freq)
Definition: RFCavity.h:379
constexpr double MVpm2Vpm
Definition: Units.h:128
void setNumCells(int NumCells)
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
constexpr double two_pi
The value of .
Definition: Physics.h:33
virtual void setPhase(double phi)
Set phase.
virtual void setAmplitude(double V)
Set amplitude.
virtual void setFieldMapFN(const std::string &fmapfn)
Set the name of the field map.
Definition: RFCavity.h:349
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
virtual void setPhasem(double phase) override
virtual void setWake(WakeFunction *wf)
attach a wake field to the element
virtual void setAmplitudem(double vPeak)
Definition: RFCavity.h:354
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:120
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:147
virtual void setAutophaseVeto(bool veto=true)
Definition: RFCavity.h:429
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:310
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
const std::string name
constexpr double MHz2Hz
Definition: Units.h:113
virtual void update()
Update the embedded CLASSIC cavity.
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
virtual void setDesignEnergy(const double &ekin, bool changeable=true) override
Definition: RFCavity.h:334
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:419
OpalTravelingWave()
Exemplar constructor.
virtual void updateUnknown(ElementBase *)
Transmit the ``unknown&#39;&#39; (not known to OPAL) attributes to CLASSIC.
virtual void setFrequency(double f)
Set frequency.
virtual OpalTravelingWave * clone(const std::string &name)
Make clone.
virtual void setAmplitudeError(double vPeakError)
Definition: RFCavity.h:364
void setMode(double mode)
virtual void setPhaseError(double phaseError)
Definition: RFCavity.h:404
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:127
virtual void update()
Update the embedded CLASSIC element.
void registerOwnership() const