OPAL (Object Oriented Parallel Accelerator Library) 2022.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
23class ElementBase;
24
25template <class T, unsigned Dim>
26class PartBunchBase;
27
28enum class WakeType: unsigned short {
32};
33
35
36public:
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
51protected:
52 const unsigned int nBins_m;
53
54private:
55 const std::string name_m;
56};
57
58class LineDensity: public std::vector<double> {
59public:
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
64inline 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
WakeType
Definition: WakeFunction.h:28
@ CSRIGFWakeFunction
@ CSRWakeFunction
const std::string name
const unsigned int nBins_m
Definition: WakeFunction.h:52
const std::string & getName() const
Definition: WakeFunction.h:49
const std::string name_m
Definition: WakeFunction.h:55
WakeFunction(std::string name, unsigned int n)
Definition: WakeFunction.h:37
virtual void initialize(const ElementBase *)
Definition: WakeFunction.h:43
virtual ~WakeFunction()
Definition: WakeFunction.h:41
virtual WakeType getType() const =0
virtual void apply(PartBunchBase< double, 3 > *bunch)=0
LineDensity(int size=0, double defaultValue=0.0)
Definition: WakeFunction.h:60
void getFirstDerivative(std::vector< double > &firstDerivative, const double &hz)
Definition: WakeFunction.h:64