OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
OpalWake.cpp
Go to the documentation of this file.
1 //
2 // Class OpalWake
3 // The class for the OPAL WAKE command.
4 //
5 // Copyright (c) 2008 - 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 //
18 
19 #include "Structure/OpalWake.h"
24 #include "Attributes/Attributes.h"
27 #include "Utilities/OpalFilter.h"
28 
29 extern Inform *gmsg;
30 
31 // The attributes of class OpalWake.
32 namespace {
33  enum {
34  // DESCRIPTION OF SINGLE PARTICLE:
35  TYPE, // The type of the wake
36  NBIN, // Number of bins for the line density
37  CONST_LENGTH,// True if the length of the Bunch is considered as constant
38  CONDUCT, // Conductivity, either AC or DC
39  Z0, //
40  RADIUS, // Radius of the tube
41  SIGMA,
42  TAU,
43  FILTERS, // List of filters to apply on line density
44  FNAME,
45  SIZE
46  };
47 }
48 
50  Definition(SIZE, "WAKE",
51  "The \"WAKE\" statement defines data for the wakefuction "
52  "on an element."),
53  wf_m(0) {
55  ("TYPE", "Specifies the wake function.", {"1D-CSR", "1D-CSR-IGF", "LONG-SHORT-RANGE", "TRANSV-SHORT-RANGE"});
56 
58  ("NBIN", "Number of bins for the line density calculation");
59 
60  itsAttr[CONST_LENGTH] = Attributes::makeBool
61  ("CONST_LENGTH", "True if the length of the Bunch is considered as constant");
62 
64  ("CONDUCT", "Conductivity.", {"DC", "AC"});
65 
67  ("Z0", "Impedance of the beam pipe ");
68 
70  ("RADIUS", "The radius of the beam pipe [m]");
71 
73  ("SIGMA", "Material constant dependant on the beam pipe material");
74 
76  ("TAU", "Material constant dependant on the beam pipe material");
77 
79  ("FILTERS", "List of filters to apply on line density");
80 
82  ("FNAME", "Filename of the wakefield file");
83 
84  OpalWake *defWake = clone("UNNAMED_WAKE");
85  defWake->builtin = true;
86 
87  try {
88  defWake->update();
89  OpalData::getInstance()->define(defWake);
90  } catch(...) {
91  delete defWake;
92  }
93 
95 }
96 
97 
98 OpalWake::OpalWake(const std::string &name, OpalWake *parent):
99  Definition(name, parent),
100  wf_m(parent->wf_m)
101 {}
102 
103 
105  delete wf_m;
106 }
107 
108 
110  // Can replace only by another WAKE.
111  return dynamic_cast<OpalWake *>(object) != 0;
112 }
113 
114 
115 OpalWake *OpalWake::clone(const std::string &name) {
116  return new OpalWake(name, this);
117 }
118 
119 
121  update();
122 }
123 
124 
125 OpalWake *OpalWake::find(const std::string &name) {
126  OpalWake *wake = dynamic_cast<OpalWake *>(OpalData::getInstance()->find(name));
127 
128  if (wake == 0) {
129  throw OpalException("OpalWake::find()", "Wake \"" + name + "\" not found.");
130  }
131  return wake;
132 }
133 
134 
136  return (int)Attributes::getReal(itsAttr[NBIN]);
137 }
138 
139 
141  // Set default name.
142  if (getOpalName().empty()) setOpalName("UNNAMED_WAKE");
143 }
144 
145 
147  *gmsg << "* ************* W A K E ************************************************************\n";
148  *gmsg << "OpalWake::initWakefunction ";
149  *gmsg << "for element " << element.getName() << "\n";
150  *gmsg << "* **********************************************************************************" << endl;
151 
152 
153  std::vector<std::string> filters_str = Attributes::getStringArray(itsAttr[FILTERS]);
154  std::vector<Filter *> filters;
155 
156  for(std::vector<std::string>::const_iterator fit = filters_str.begin(); fit != filters_str.end(); ++ fit) {
157  OpalFilter *f = OpalFilter::find(*fit);
158 
159  if (f) {
160  f->initOpalFilter();
161  filters.push_back(f->filter_m);
162  }
163  }
164  std::string type = Attributes::getString(itsAttr[TYPE]);
165  if (type == "1D-CSR") {
166 
167  if (filters.size() == 0 && Attributes::getReal(itsAttr[NBIN]) <= 7) {
168  throw OpalException("OpalWake::initWakeFunction",
169  "At least 8 bins have to be used, ideally far more");
170  }
171 
173  filters,
174  (int)(Attributes::getReal(itsAttr[NBIN])));
175 
176  } else if (type == "1D-CSR-IGF") {
177 
178  if (filters.size() == 0 && Attributes::getReal(itsAttr[NBIN]) <= 7) {
179  throw OpalException("OpalWake::initWakeFunction",
180  "At least 8 bins have to be used, ideally far more");
181  }
182 
184  filters,
185  (int)(Attributes::getReal(itsAttr[NBIN])));
186 
187  } else if (type == "LONG-SHORT-RANGE") {
188  int acMode = Attributes::getString(itsAttr[CONDUCT]) == "DC"? 2: 1;
189 
191  filters,
194  Attributes::getReal(itsAttr[RADIUS]),
196  acMode,
198  1,
199  Attributes::getBool(itsAttr[CONST_LENGTH]),
201 
202  } else if (type == "TRANSV-SHORT-RANGE") {
203  int acMode = Attributes::getString(itsAttr[CONDUCT]) == "DC" ? 2: 1;
204 
206  filters,
209  Attributes::getReal(itsAttr[RADIUS]),
211  acMode,
213  0,
214  Attributes::getBool(itsAttr[CONST_LENGTH]),
216  }
217 }
218 
219 void OpalWake::print(std::ostream &os) const {
220  os << "* ************* W A K E ************************************************************ " << std::endl;
221  os << "* WAKE " << getOpalName() << '\n'
222  << "* BINS " << Attributes::getReal(itsAttr[NBIN]) << '\n'
223  << "* CONST_LENGTH " << Attributes::getReal(itsAttr[CONST_LENGTH]) << '\n'
224  << "* CONDUCT " << Attributes::getReal(itsAttr[CONDUCT]) << '\n'
225  << "* Z0 " << Attributes::getReal(itsAttr[Z0]) << '\n'
226  << "* RADIUS " << Attributes::getReal(itsAttr[RADIUS]) << '\n'
227  << "* SIGMA " << Attributes::getReal(itsAttr[SIGMA]) << '\n'
228  << "* TAU " << Attributes::getReal(itsAttr[TAU]) << '\n';
229  os << "* ********************************************************************************** " << std::endl;
230 }
@ SIZE
Definition: IndexMap.cpp:174
Inform * gmsg
Definition: Main.cpp:62
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
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 makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Definition: Attributes.cpp:473
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Definition: Attributes.cpp:409
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::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:478
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
The base class for all OPAL definitions.
Definition: Definition.h:30
The base class for all OPAL objects.
Definition: Object.h:48
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:281
void setOpalName(const std::string &name)
Set object name.
Definition: Object.cpp:302
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
bool builtin
Built-in flag.
Definition: Object.h:233
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:565
static OpalData * getInstance()
Definition: OpalData.cpp:195
void define(Object *newObject)
Define a new object.
Definition: OpalData.cpp:488
virtual const std::string & getName() const
Get element name.
void print(std::ostream &os) const
Print the object.
Definition: OpalWake.cpp:219
WakeFunction * wf_m
Definition: OpalWake.h:57
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Definition: OpalWake.cpp:109
OpalWake()
Exemplar constructor.
Definition: OpalWake.cpp:49
static OpalWake * find(const std::string &name)
Find named WAKE.
Definition: OpalWake.cpp:125
virtual ~OpalWake()
Definition: OpalWake.cpp:104
void initWakefunction(const ElementBase &element)
Definition: OpalWake.cpp:146
virtual void update()
Update the WAKE data.
Definition: OpalWake.cpp:140
int getNumberOfBins()
Definition: OpalWake.cpp:135
virtual void execute()
Check the WAKE data.
Definition: OpalWake.cpp:120
virtual OpalWake * clone(const std::string &name)
Make clone.
Definition: OpalWake.cpp:115
The base class for all OPAL exceptions.
Definition: OpalException.h:28
The FILTER definition.
Definition: OpalFilter.h:32
void initOpalFilter()
Definition: OpalFilter.cpp:142
static OpalFilter * find(const std::string &name)
Find named FILTER.
Definition: OpalFilter.cpp:126
Filter * filter_m
Definition: OpalFilter.h:64
Definition: Inform.h:42