OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
OpalWake.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: OpalWake.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.3.4.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: OpalWake
10 // The class for the OPAL WAKE command.
11 //
12 // $Date: 2003/08/11 22:09:00 $
13 // $Author: A. Adelmann $
14 //
15 // ------------------------------------------------------------------------
16 
17 #include "Structure/OpalWake.h"
22 #include "Attributes/Attributes.h"
23 #include "Physics/Physics.h"
26 #include "Utilities/OpalFilter.h"
27 #include "Utilities/Util.h"
28 
29 extern Inform *gmsg;
30 
31 using namespace Physics;
32 
33 
34 // Class OpalWake
35 // ------------------------------------------------------------------------
36 
37 // The attributes of class OpalWake.
38 namespace {
39  enum {
40  // DESCRIPTION OF SINGLE PARTICLE:
41  TYPE, // The type of the wake
42  NBIN, // Number of bins for the line density
43  CONST_LENGTH,// True if the length of the Bunch is considered as constant
44  CONDUCT, // Conductivity, either AC or DC
45  Z0, //
46  FORM, // From of the tube
47  RADIUS, // Radius of the tube
48  SIGMA,
49  TAU,
50  FILTERS, // List of filters to apply on line density
51  FNAME,
52  SIZE
53  };
54 }
55 
57  Definition(SIZE, "WAKE",
58  "The \"WAKE\" statement defines data for the wakefuction "
59  "on an element."),
60  wf_m(0) {
62  ("TYPE", "Specifies the wake function: 1D-CSR, 1D-CSR-IGF, LONG-SHORT-RANGE, TRANSV-SHORT-RANGE, LONG-TRANSV-SHORT-RANGE");
63 
65  ("NBIN", "Number of bins for the line density calculation");
66 
67  itsAttr[CONST_LENGTH] = Attributes::makeBool
68  ("CONST_LENGTH", "True if the length of the Bunch is considered as constant");
69 
71  ("CONDUCT", "Conductivity: DC, AC");
72 
74  ("Z0", "Impedance of the beam pipe ");
75 
77  ("FORM", "The form of the beam pipe: ROUND");
78 
80  ("RADIUS", "The radius of the beam pipe [m]");
81 
83  ("SIGMA", "Material constant dependant on the beam pipe material");
84 
86  ("TAU", "Material constant dependant on the beam pipe material");
87 
89  ("FILTERS", "List of filters to apply on line density");
90 
92  ("FNAME", "Filename of the wakefield file");
93 
94  OpalWake *defWake = clone("UNNAMED_WAKE");
95  defWake->builtin = true;
96 
97  try {
98  defWake->update();
99  OpalData::getInstance()->define(defWake);
100  } catch(...) {
101  delete defWake;
102  }
103 
105 }
106 
107 
108 OpalWake::OpalWake(const std::string &name, OpalWake *parent):
109  Definition(name, parent),
110  wf_m(parent->wf_m)
111 {}
112 
113 
115  if (wf_m)
116  delete wf_m;
117 }
118 
119 
121  // Can replace only by another WAKE.
122  return dynamic_cast<OpalWake *>(object) != 0;
123 }
124 
125 
126 OpalWake *OpalWake::clone(const std::string &name) {
127  return new OpalWake(name, this);
128 }
129 
130 
132  update();
133 }
134 
135 
136 OpalWake *OpalWake::find(const std::string &name) {
137  OpalWake *wake = dynamic_cast<OpalWake *>(OpalData::getInstance()->find(name));
138 
139  if (wake == 0) {
140  throw OpalException("OpalWake::find()", "Wake \"" + name + "\" not found.");
141  }
142  return wake;
143 }
144 
145 
147  return (int)Attributes::getReal(itsAttr[NBIN]);
148 }
149 
150 
152  // Set default name.
153  if (getOpalName().empty()) setOpalName("UNNAMED_WAKE");
154 }
155 
156 
158  *gmsg << "* ************* W A K E ************************************************************\n";
159  *gmsg << "OpalWake::initWakefunction ";
160  *gmsg << "for element " << element.getName() << "\n";
161  *gmsg << "* **********************************************************************************" << endl;
162 
163 
164  itsElement_m = &element;
165  std::vector<std::string> filters_str = Attributes::getStringArray(itsAttr[FILTERS]);
166  std::vector<Filter *> filters;
167 
168  for(std::vector<std::string>::const_iterator fit = filters_str.begin(); fit != filters_str.end(); ++ fit) {
169  OpalFilter *f = OpalFilter::find(*fit);
170 
171  if (f) {
172  f->initOpalFilter();
173  filters.push_back(f->filter_m);
174  }
175  }
176 
177  if (Util::toUpper(Attributes::getString(itsAttr[TYPE])) == "1D-CSR") {
178 
179  if (filters.size() == 0 && Attributes::getReal(itsAttr[NBIN]) <= 7) {
180  throw OpalException("OpalWake::initWakeFunction",
181  "At least 8 bins have to be used, ideally far more");
182  }
183 
185  itsElement_m,
186  filters,
187  (int)(Attributes::getReal(itsAttr[NBIN])));
188 
189  } else if (Util::toUpper(Attributes::getString(itsAttr[TYPE])) == "1D-CSR-IGF") {
190 
191  if (filters.size() == 0 && Attributes::getReal(itsAttr[NBIN]) <= 7) {
192  throw OpalException("OpalWake::initWakeFunction",
193  "At least 8 bins have to be used, ideally far more");
194  }
195 
197  itsElement_m,
198  filters,
199  (int)(Attributes::getReal(itsAttr[NBIN])));
200 
201  } else if (Util::toUpper(Attributes::getString(itsAttr[TYPE])) == "LONG-SHORT-RANGE") {
202  int acMode = Util::toUpper(Attributes::getString(itsAttr[CONDUCT])) == "DC"? 2: 1;
203 
205  itsElement_m,
206  filters,
209  Attributes::getReal(itsAttr[RADIUS]),
211  acMode,
213  1,
214  Attributes::getBool(itsAttr[CONST_LENGTH]),
216 
217  } else if (Util::toUpper(Attributes::getString(itsAttr[TYPE])) == "TRANSV-SHORT-RANGE") {
218  int acMode = Util::toUpper(Attributes::getString(itsAttr[CONDUCT])) == "DC"? 2: 1;
219 
221  itsElement_m,
222  filters,
225  Attributes::getReal(itsAttr[RADIUS]),
227  acMode,
229  0,
230  Attributes::getBool(itsAttr[CONST_LENGTH]),
232 
233  } else if (Attributes::getString(itsAttr[TYPE]) == "LONG-TRANSV-SHORT-RANGE") {
234  //FIXME: NOT IMPLEMENTED YET!!!
235  } else {
236  wf_m = 0;
237  INFOMSG("no wakefunction attached" << endl);
238  }
239 }
240 
241 void OpalWake::print(std::ostream &os) const {
242  os << "* ************* W A K E ************************************************************ " << std::endl;
243  os << "* WAKE " << getOpalName() << '\n'
244  << "* BINS " << Attributes::getReal(itsAttr[NBIN]) << '\n'
245  << "* CONST_LENGTH " << Attributes::getReal(itsAttr[CONST_LENGTH]) << '\n'
246  << "* CONDUCT " << Attributes::getReal(itsAttr[CONDUCT]) << '\n'
247  << "* Z0 " << Attributes::getReal(itsAttr[Z0]) << '\n'
248  << "* FORM " << Attributes::getReal(itsAttr[FORM]) << '\n'
249  << "* RADIUS " << Attributes::getReal(itsAttr[RADIUS]) << '\n'
250  << "* SIGMA " << Attributes::getReal(itsAttr[SIGMA]) << '\n'
251  << "* TAU " << Attributes::getReal(itsAttr[TAU]) << '\n';
252  os << "* ********************************************************************************** " << std::endl;
253 }
virtual void update()
Update the WAKE data.
Definition: OpalWake.cpp:151
WakeFunction * wf_m
Definition: OpalWake.h:65
Interface for basic beam line object.
Definition: ElementBase.h:128
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:538
The base class for all OPAL definitions.
Definition: Definition.h:30
void print(std::ostream &os) const
Print the object.
Definition: OpalWake.cpp:241
void initOpalFilter()
Definition: OpalFilter.cpp:142
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Inform * gmsg
Definition: Main.cpp:21
std::string toUpper(const std::string &str)
Definition: Util.cpp:130
virtual const std::string & getName() const
Get element name.
Definition: ElementBase.cpp:95
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
Filter * filter_m
Definition: OpalFilter.h:64
virtual ~OpalWake()
Definition: OpalWake.cpp:114
The WAKE definition.
Definition: OpalWake.h:34
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:66
void initWakefunction(ElementBase &element)
Definition: OpalWake.cpp:157
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Definition: Attributes.cpp:373
static OpalData * getInstance()
Definition: OpalData.cpp:209
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:284
virtual OpalWake * clone(const std::string &name)
Make clone.
Definition: OpalWake.cpp:126
virtual void execute()
Check the WAKE data.
Definition: OpalWake.cpp:131
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:378
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:136
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
#define INFOMSG(msg)
Definition: IpplInfo.h:397
OpalWake()
Exemplar constructor.
Definition: OpalWake.cpp:56
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:618
The base class for all OPAL objects.
Definition: Object.h:48
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:56
const std::string name
ElementBase * itsElement_m
Definition: OpalWake.h:83
void setOpalName(const std::string &name)
Set object name.
Definition: Object.cpp:305
int getNumberOfBins()
Definition: OpalWake.cpp:146
static OpalFilter * find(const std::string &name)
Find named FILTER.
Definition: OpalFilter.cpp:126
The FILTER definition.
Definition: OpalFilter.h:32
bool builtin
Built-in flag.
Definition: Object.h:231
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
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition: OpalWake.cpp:120
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307