OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
WakeFunction.h
Go to the documentation of this file.
1 //
2 // Class WakeFunction
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 WAKEFUNCTION_HH
18 #define WAKEFUNCTION_HH
19 
20 #include <string>
21 #include <vector>
22 
23 class ElementBase;
24 
25 template <class T, unsigned Dim>
26 class PartBunchBase;
27 
28 enum class WakeType: unsigned short {
32 };
33 
34 class WakeFunction {
35 
36 public:
37  WakeFunction(std::string name, unsigned int n):
38  nBins_m(n),
39  name_m(name) { };
40 
41  virtual ~WakeFunction(){ };
42 
43  virtual void initialize(const ElementBase* /*elref*/) { };
44 
45  virtual void apply(PartBunchBase<double, 3>* bunch) = 0;
46 
47  virtual WakeType getType() const = 0;
48 
49  const std::string& getName() const { return name_m; }
50 
51 protected:
52  const unsigned int nBins_m;
53 
54 private:
55  const std::string name_m;
56 };
57 
58 class LineDensity: public std::vector<double> {
59 public:
60  LineDensity(int size = 0, double defaultValue = 0.0) : std::vector<double>(size, defaultValue) {}
61  void getFirstDerivative(std::vector<double>& firstDerivative, const double& hz);
62 };
63 
64 inline void LineDensity::getFirstDerivative(std::vector<double>& firstDerivative, const double& hz) {
65  const size_t size = this->size();
66  if(firstDerivative.size() != size)
67  firstDerivative.resize(size, 0.0);
68 
69  firstDerivative[0] = ((*this)[1] - (*this)[0]) / hz;
70  for(unsigned int i = 1; i + 1 < size; ++i)
71  firstDerivative[i] = ((*this)[i + 1] - (*this)[i - 1]) / hz;
72  firstDerivative[size - 1] = ((*this)[size - 1] - (*this)[size - 2]) / hz;
73 }
74 
75 #endif // WAKEFUNCTION_HH
const unsigned int nBins_m
Definition: WakeFunction.h:52
virtual WakeType getType() const =0
const std::string & getName() const
Definition: WakeFunction.h:49
WakeFunction(std::string name, unsigned int n)
Definition: WakeFunction.h:37
virtual ~WakeFunction()
Definition: WakeFunction.h:41
void getFirstDerivative(std::vector< double > &firstDerivative, const double &hz)
Definition: WakeFunction.h:64
LineDensity(int size=0, double defaultValue=0.0)
Definition: WakeFunction.h:60
const std::string name_m
Definition: WakeFunction.h:55
const std::string name
WakeType
Definition: WakeFunction.h:28
virtual void apply(PartBunchBase< double, 3 > *bunch)=0
virtual void initialize(const ElementBase *)
Definition: WakeFunction.h:43