WakeFunction.hh 1.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//
// Class WakeFunction
//
// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
gsell's avatar
gsell committed
17 18 19
#ifndef WAKEFUNCTION_HH
#define WAKEFUNCTION_HH

20 21 22
#include <string>
#include <vector>

gsell's avatar
gsell committed
23
class ElementBase;
24 25 26

template <class T, unsigned Dim>
class PartBunchBase;
gsell's avatar
gsell committed
27 28 29

class WakeFunction {
public:
30
    WakeFunction(std::string name, unsigned int n):
31 32
        nBins_m(n),
        name_m(name) { };
33

gsell's avatar
gsell committed
34
    virtual ~WakeFunction(){ };
35
    virtual void initialize(const ElementBase */*elref*/){ };
frey_m's avatar
frey_m committed
36
    virtual void apply(PartBunchBase<double, 3> *bunch) = 0;
gsell's avatar
gsell committed
37
    virtual const std::string getType() const = 0;
38 39 40
    const std::string & getName() const {
        return name_m;
    }
gsell's avatar
gsell committed
41

42 43 44
protected:
    const unsigned int nBins_m;

gsell's avatar
gsell committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
private:
    const std::string name_m;
};

class LineDensity: public std::vector<double> {
public:
    LineDensity(int size = 0, double defaultValue = 0.0) : std::vector<double>(size, defaultValue) {}
    void getFirstDerivative(std::vector<double> &firstDerivative, const double &hz);
};

inline void LineDensity::getFirstDerivative(std::vector<double> &firstDerivative, const double &hz) {
    const size_t size = this->size();
    if(firstDerivative.size() != size)
        firstDerivative.resize(size, 0.0);

    firstDerivative[0] = ((*this)[1] - (*this)[0]) / hz;
    for(unsigned int i = 1; i + 1 < size; ++i)
        firstDerivative[i] = ((*this)[i + 1] - (*this)[i - 1]) / hz;
    firstDerivative[size - 1] = ((*this)[size - 1] - (*this)[size - 2]) / hz;
}

#endif // WAKEFUNCTION_HH