OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
GreenWakeFunction.hh
Go to the documentation of this file.
1 #ifndef GREENWAKEFUNCTION_HH
2 #define GREENWAKEFUNCTION_HH
3 
4 #include "Filters/Filter.h"
6 #include "Physics/Physics.h"
7 #include "Utility/IpplInfo.h"
8 
9 #include <vector>
10 #include <cassert>
11 #include <map>
12 #include <string>
13 #include <complex>
14 
15 //#define USE_FFTW
16 
18 typedef std::map<std::string, int> FilterOptions;
19 
21 
23 public:
25  //IFF: changed direction to int (was double)
26  //IFF: changed acMode to int (was double)
27  GreenWakeFunction(const std::string &name,
28  ElementBase *element,
29  std::vector<Filter *> filters,
30  int NBIN,
31  double Z0,
32  double radius,
33  double sigma,
34  int acMode,
35  double tau,
36  int direction,
37  bool constLength,
38  std::string fname);
39 
40  std::pair<int, int> distrIndices(int vectLen);
41 
42  void apply(PartBunchBase<double, 3> *bunch);
43  void setWakeFromFile(int NBin, double spacing);
44  virtual const std::string getType() const;
45 
46 private:
47  class Wake {
48 
49  public:
50 
51  Wake(double s, double Z0, double a, double sigma, int acMode, double tau, int direction)
52  : Z0_(Z0), a_(a), sigma_(sigma), s_(s), acMode_(acMode), tau_(tau), direction_(direction)
53  {}
54 
62  double operator()(double k) {
63 
64  std::complex <double> i(0, 1);
65  std::complex <double> Z(0, 0);
66  double signK = (k > 0 ? 1 : -1);
67 
68  //1 == AC
69  //2 == DC
70  switch(acMode_) {
71  case 1:
72  Z = (Z0_ / (2 * Physics::pi * a_)) * 1.0 / (sqrt(Z0_ * std::abs(k) / 2) * sqrt(sigma_ / (1.0 - i * Physics::c * k * tau_)) * (i + signK) / k - (i * k * a_) / 2.0);
73  break;
74  case 2:
75  Z = (Z0_ / (2 * Physics::pi * a_)) * 1.0 / (sqrt(sigma_ * Z0_ * std::abs(k) / 2) * (i + signK) / k - (i * k * a_) / 2.0);
76  break;
77  }
78  switch(direction_) {
79  case LONGITUDINAL:
80  return real(Z) * cos(k * s_) * 2.0 * Physics::c / Physics::pi;
81  break;
82  case TRANSVERSAL:
83  return real(Z) * Physics::c / k * cos(k * s_) * 2.0 * Physics::c / Physics::pi;
84  break;
85  }
86  ERRORMSG("We should not be here: " << __FILE__ << " L" << __LINE__ << endl);
87 
88  return 0.0;
89  }
90 
91  private:
92 
94  double Z0_;
96  double a_;
98  double sigma_;
100  double s_;
102  int acMode_;
104  double tau_;
107 
108  };
109 
121  template<class F> double simpson(F &f, double a, double b, unsigned int N) {
122  assert(b > a);
123  assert(N > 0);
124 
125  double result = 0;
126  double h = (b - a) / N;
127 
128  // boundary values
129  result += (f(a) + 4 * f(a + h / 2) + f(b)) / 2.0;
130 
131  // values between boundaries
132  for(unsigned int i = 1; i < N; ++ i) {
133  result += f(a + i * h) + 2 * f(a + (i + 0.5) * h);
134  }
135 
136  result *= h / 3.0;
137 
138  return result;
139 
140  }
142  std::vector<double> lineDensity_m;
144  std::vector<double> FftWField_m;
145 
147  int NBin_m;
149  double Z0_m;
151  double radius_m;
153  double sigma_m;
155  int acMode_m;
157  double tau_m;
163  std::string filename_m;
164 
165  std::vector<Filter *> filters_m;
166 
167  void testApply(PartBunchBase<double, 3> *bunch);
168  void compEnergy(const double K, const double charge, const double *lambda, double *OutEnergy);
169  void compEnergy(const double K, const double charge, std::vector<double> lambda, double *OutEnergy);
170  void CalcWakeFFT(double spacing);
171 };
172 #endif //GREENWAKEFUNCTION_HH
std::vector< double > FftWField_m
FFT of the zero padded wakefield.
void setWakeFromFile(int NBin, double spacing)
reads in the wakefield from file
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
std::map< std::string, int > FilterOptions
double Z0_m
impedance
Interface for basic beam line object.
Definition: ElementBase.h:128
GreenWakeFunction(const std::string &name, ElementBase *element, std::vector< Filter * > filters, int NBIN, double Z0, double radius, double sigma, int acMode, double tau, int direction, bool constLength, std::string fname)
just a Testfunction! Calculate the energy of the Wakefunction with the lambda
std::vector< double > lineDensity_m
save the line Density of the particle bunch
double operator()(double k)
Used to integrate the function.
double tau_
material constant
double s_
distance from the particle
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
Wake(double s, double Z0, double a, double sigma, int acMode, double tau, int direction)
double sigma_m
material constant
double sigma_
material constant
std::pair< int, int > distrIndices(int vectLen)
given a vector of length N, distribute the indexes among the available processors ...
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
virtual const std::string getType() const
int acMode_
conductivity either 1=&quot;AC&quot; or 2=&quot;DC&quot;
double simpson(F &f, double a, double b, unsigned int N)
Simpson-Integration from the function f from a to b with N steps.
int acMode_m
conductivity either 1=&quot;AC&quot; or 2=&quot;DC&quot;
constexpr double pi
The value of .
Definition: Physics.h:31
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
int direction_m
direction either 1=&quot;Longitudinal&quot; 2= &quot;Transversal&quot;
void testApply(PartBunchBase< double, 3 > *bunch)
Just a test function.
void apply(PartBunchBase< double, 3 > *bunch)
double radius_m
radius
double tau_m
material constant
void CalcWakeFFT(double spacing)
Calculate the FFT of the Wakefunction.
std::vector< Filter * > filters_m
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
int NBin_m
divides the particle bunch in NBin slices
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
bool constLength_m
true if the length of the particle bunch is considered as constant
const std::string name
std::string filename_m
filename of the wakefield
#define K
Definition: integrate.cpp:118
void compEnergy(const double K, const double charge, const double *lambda, double *OutEnergy)
just a Testfunction! Calculate the energy of the Wakefunction with the lambda
int direction_
direction either 1=&quot;Longitudinal&quot; 0= &quot;Transversal&quot;
Inform & endl(Inform &inf)
Definition: Inform.cpp:42