OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
GreenWakeFunction.h
Go to the documentation of this file.
1 //
2 // Class GreenWakeFunction
3 //
4 // Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
5 // All rights reserved
6 //
7 // This file is part of OPAL.
8 //
9 // OPAL is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16 //
17 #ifndef GREENWAKEFUNCTION_HH
18 #define GREENWAKEFUNCTION_HH
19 
20 #include "Filters/Filter.h"
21 #include "Physics/Physics.h"
22 #include "Solvers/WakeFunction.h"
23 #include "Utility/IpplInfo.h"
24 #include "Utility/PAssert.h"
25 
26 #include <complex>
27 #include <map>
28 #include <string>
29 #include <vector>
30 
31 #ifdef WITH_UNIT_TESTS
32 #include <gtest/gtest_prod.h>
33 #endif
34 
35 enum class WakeDirection: unsigned short {
38 };
39 
40 typedef std::map<std::string, int> FilterOptions;
41 
43 public:
45  //IFF: changed direction to int (was double)
46  //IFF: changed acMode to int (was double)
47  GreenWakeFunction(const std::string& name,
48  std::vector<Filter*> filters,
49  int NBIN,
50  double Z0,
51  double radius,
52  double sigma,
53  int acMode,
54  double tau,
55  WakeDirection direction,
56  bool constLength,
57  std::string fname);
58 
59  std::pair<int, int> distrIndices(int vectLen);
60 
61  void apply(PartBunchBase<double, 3>* bunch) override;
62  void setWakeFromFile(int NBin, double spacing);
63  virtual WakeType getType() const override;
64 
65 private:
66 #ifdef WITH_UNIT_TESTS
67  FRIEND_TEST(GreenWakeFunctionTest, TestApply);
68 #endif
69 
70  class Wake {
71 
72  public:
73  Wake(double s, double Z0, double a, double sigma, int acMode, double tau, WakeDirection direction)
74  : Z0_(Z0), a_(a), sigma_(sigma), s_(s), acMode_(acMode), tau_(tau), direction_(direction)
75  {}
76 
84  double operator()(double k) {
85 
86  std::complex <double> i(0, 1);
87  std::complex <double> Z(0, 0);
88  double signK = (k > 0 ? 1 : -1);
89 
90  //1 == AC
91  //2 == DC
92  switch(acMode_) {
93  case 1:
94  Z = (Z0_ / (2 * Physics::pi * a_)) * 1.0 / (std::sqrt(Z0_ * std::abs(k) / 2) * std::sqrt(sigma_ / (1.0 - i * Physics::c * k * tau_)) * (i + signK) / k - (i * k * a_) / 2.0);
95  break;
96  case 2:
97  Z = (Z0_ / (2 * Physics::pi * a_)) * 1.0 / (std::sqrt(sigma_ * Z0_ * std::abs(k) / 2) * (i + signK) / k - (i * k * a_) / 2.0);
98  break;
99  }
100  switch(direction_) {
102  return real(Z) * std::cos(k * s_) * 2.0 * Physics::c / Physics::pi;
103  break;
105  return real(Z) * Physics::c / k * std::cos(k * s_) * 2.0 * Physics::c / Physics::pi;
106  break;
107  }
108  ERRORMSG("We should not be here: " << __FILE__ << " L" << __LINE__ << endl);
109 
110  return 0.0;
111  }
112 
113  private:
115  double Z0_;
117  double a_;
119  double sigma_;
121  double s_;
123  int acMode_;
125  double tau_;
128  };
129 
141  template<class F> double simpson(F& f, double a, double b, unsigned int N) {
142  PAssert(b > a);
143  PAssert(N > 0);
144 
145  double result = 0;
146  double h = (b - a) / N;
147 
148  // boundary values
149  result += (f(a) + 4 * f(a + h / 2) + f(b)) / 2.0;
150 
151  // values between boundaries
152  for(unsigned int i = 1; i < N; ++ i) {
153  result += f(a + i * h) + 2 * f(a + (i + 0.5) * h);
154  }
155 
156  result *= h / 3.0;
157 
158  return result;
159  }
160 
162  std::vector<double> lineDensity_m;
164  std::vector<double> FftWField_m;
165 
167  int NBin_m;
169  double Z0_m;
171  double radius_m;
173  double sigma_m;
175  int acMode_m;
177  double tau_m;
183  std::string filename_m;
184 
185  std::vector<Filter*> filters_m;
186 
187  static const std::map<WakeDirection, std::string> wakeDirectiontoString_s;
188 
189  void compEnergy(const double K, const double charge, const double* lambda, double* OutEnergy);
190  void compEnergy(const double K, const double charge, std::vector<double> lambda, double* OutEnergy);
191  void CalcWakeFFT(double spacing);
192  static std::string getWakeDirectionString(const WakeDirection& direction);
193 };
194 #endif //GREENWAKEFUNCTION_HH
int acMode_
conductivity either 1=&quot;AC&quot; or 2=&quot;DC&quot;
void setWakeFromFile(int NBin, double spacing)
reads in the wakefield from file
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
Wake(double s, double Z0, double a, double sigma, int acMode, double tau, WakeDirection direction)
std::string filename_m
filename of the wakefield
bool constLength_m
true if the length of the particle bunch is considered as constant
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double simpson(F &f, double a, double b, unsigned int N)
Simpson-Integration from the function f from a to b with N steps.
static std::string getWakeDirectionString(const WakeDirection &direction)
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
void apply(PartBunchBase< double, 3 > *bunch) override
GreenWakeFunction(const std::string &name, std::vector< Filter * > filters, int NBIN, double Z0, double radius, double sigma, int acMode, double tau, WakeDirection direction, bool constLength, std::string fname)
WakeDirection direction_
direction either 1=&quot;Longitudinal&quot; 0= &quot;Transversal&quot;
double tau_
material constant
constexpr double pi
The value of .
Definition: Physics.h:30
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
double s_
distance from the particle
int NBin_m
divides the particle bunch in NBin slices
double sigma_
material constant
double operator()(double k)
Used to integrate the function.
int acMode_m
conductivity either 1=&quot;AC&quot; or 2=&quot;DC&quot;
std::vector< double > lineDensity_m
save the line Density of the particle bunch
static const std::map< WakeDirection, std::string > wakeDirectiontoString_s
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
float result
Definition: test.py:2
const std::string name
std::vector< double > FftWField_m
FFT of the zero padded wakefield.
std::vector< Filter * > filters_m
WakeType
Definition: WakeFunction.h:28
double Z0_m
impedance
double radius_m
radius
#define PAssert(c)
Definition: PAssert.h:102
double sigma_m
material constant
std::map< std::string, int > FilterOptions
double tau_m
material constant
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
WakeDirection direction_m
direction either &quot;Longitudinal&quot; - &quot;Transversal&quot;
WakeDirection
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
void CalcWakeFFT(double spacing)
Calculate the FFT of the Wakefunction.
virtual WakeType getType() const override
std::pair< int, int > distrIndices(int vectLen)
given a vector of length N, distribute the indexes among the available processors ...