OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalVariableRFCavity.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Chris Rogers
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * 1. Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * 2. Redistributions in binary form must reproduce the above copyright notice,
9  * this list of conditions and the following disclaimer in the documentation
10  * and/or other materials provided with the distribution.
11  * 3. Neither the name of STFC nor the names of its contributors may be used to
12  * endorse or promote products derived from this software without specific
13  * prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 
30 #include "Physics/Physics.h"
32 #include "Attributes/Attributes.h"
35 
36 extern Inform *gmsg;
37 
38 const std::string OpalVariableRFCavity::doc_string =
39  std::string("The \"VARIABLE_RF_CAVITY\" element defines an RF cavity ")+
40  std::string("with time dependent frequency, phase and amplitude.");
41 
43  OpalElement(SIZE, "VARIABLE_RF_CAVITY", doc_string.c_str()) {
45  "The name of the phase time dependence model, which should give the phase in [rad].");
46  itsAttr[AMPLITUDE_MODEL] = Attributes::makeString("AMPLITUDE_MODEL",
47  "The name of the amplitude time dependence model, which should give the field in [MV/m]");
48  itsAttr[FREQUENCY_MODEL] = Attributes::makeString("FREQUENCY_MODEL",
49  "The name of the frequency time dependence model, which should give the field in [MHz].");
51  "Full width of the cavity [m].");
53  "Full height of the cavity [m].");
54  registerStringAttribute("PHASE_MODEL");
55  registerStringAttribute("AMPLITUDE_MODEL");
56  registerStringAttribute("FREQUENCY_MODEL");
57  registerRealAttribute("WIDTH");
58  registerRealAttribute("HEIGHT");
59 
61 
62  setElement((new VariableRFCavity("VARIABLE_RF_CAVITY"))->makeAlignWrapper());
63 }
64 
66  OpalVariableRFCavity *parent) :
67  OpalElement(name, parent) {
68  VariableRFCavity *cavity = dynamic_cast<VariableRFCavity*>(
69  parent->getElement()->removeWrappers());
70  setElement((new VariableRFCavity(*cavity))->makeAlignWrapper());
71 }
72 
74 }
75 
77  return new OpalVariableRFCavity(name, this);
78 }
79 
81  return new OpalVariableRFCavity(this->getOpalName(), this);
82 }
83 
87  const VariableRFCavity* cavity = dynamic_cast<const VariableRFCavity*>(&base);
88  if (cavity == NULL) {
89  throw OpalException("OpalVariableRFCavity::fillRegisteredAttributes",
90  "Failed to cast ElementBase to a VariableRFCavity");
91  }
92 
93  attributeRegistry["L"]->setReal(cavity->getLength());
94  std::shared_ptr<AbstractTimeDependence> phase_model = cavity->getPhaseModel();
95  std::shared_ptr<AbstractTimeDependence> freq_model = cavity->getFrequencyModel();
96  std::shared_ptr<AbstractTimeDependence> amp_model = cavity->getAmplitudeModel();
97  std::string phase_name = AbstractTimeDependence::getName(phase_model);
98  std::string amp_name = AbstractTimeDependence::getName(amp_model);
99  std::string freq_name = AbstractTimeDependence::getName(freq_model);
100  attributeRegistry["PHASE_MODEL"]->setString(phase_name);
101  attributeRegistry["AMPLITUDE_MODEL"]->setString(amp_name);
102  attributeRegistry["FREQUENCY_MODEL"]->setString(freq_name);
103  attributeRegistry["WIDTH"]->setReal(cavity->getWidth());
104  attributeRegistry["HEIGHT"]->setReal(cavity->getHeight());
105 }
106 
109 
110  VariableRFCavity *cavity = dynamic_cast<VariableRFCavity*>(
112  double length = Attributes::getReal(itsAttr[LENGTH]);
113  cavity->setLength(length);
114  std::string phaseName = Attributes::getString(itsAttr[PHASE_MODEL]);
115  cavity->setPhaseName(phaseName);
116  std::string ampName = Attributes::getString(itsAttr[AMPLITUDE_MODEL]);
117  cavity->setAmplitudeName(ampName);
118  std::string freqName = Attributes::getString(itsAttr[FREQUENCY_MODEL]);
119  cavity->setFrequencyName(freqName);
120  double width = Attributes::getReal(itsAttr[WIDTH]);
121  cavity->setWidth(width);
122  double height = Attributes::getReal(itsAttr[HEIGHT]);
123  cavity->setHeight(height);
124  setElement(cavity->makeAlignWrapper());
125 }
virtual void setFrequencyName(std::string frequency)
virtual std::shared_ptr< AbstractTimeDependence > getFrequencyModel() const
static AttCell * registerStringAttribute(const std::string &name)
Register a ``string&#39;&#39; element attribute.
Interface for basic beam line object.
Definition: ElementBase.h:128
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
Fill in all registered attributes.
ValueFlag
Switch for value desired on ATTLIST command.
Definition: OpalElement.h:71
virtual std::shared_ptr< AbstractTimeDependence > getAmplitudeModel() const
The base class for all OPAL exceptions.
Definition: OpalException.h:28
virtual ElementBase * removeWrappers()
Return the design element.
Inform * gmsg
Definition: Main.cpp:21
virtual void setLength(double length)
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
static std::map< std::string, OwnPtr< AttCell > > attributeRegistry
The registry for named attributes.
Definition: OpalElement.h:172
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual void setWidth(double fullWidth)
virtual void fillRegisteredAttributes(const ElementBase &, ValueFlag)
virtual double getHeight() const
OpalVariableRFCavity * clone()
virtual void setAmplitudeName(std::string amplitude)
Base class for all beam line elements.
Definition: OpalElement.h:41
virtual double getLength() const
void setElement(ElementBase *)
Assign new CLASSIC element.
Definition: Element.h:133
virtual std::shared_ptr< AbstractTimeDependence > getPhaseModel() const
void registerOwnership() const
virtual void update()
Update the embedded CLASSIC element.
static std::string getName(std::shared_ptr< AbstractTimeDependence > time_dep)
virtual void setPhaseName(std::string phase)
ElementBase * getElement() const
Return the embedded CLASSIC element.
Definition: Element.h:128
virtual double getWidth() const
const std::string name
virtual ElementBase * makeAlignWrapper()
Allow misalignment.
static const std::string doc_string
virtual void setHeight(double fullHeight)
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Definition: Inform.h:41
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
static AttCell * registerRealAttribute(const std::string &name)
Register a ``real&#39;&#39; element attribute.
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307