Multipole.h 5.49 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef CLASSIC_Multipole_HH
#define CLASSIC_Multipole_HH

// ------------------------------------------------------------------------
// $RCSfile: Multipole.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
// Description:
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------

#include "AbsBeamline/Component.h"
#include "BeamlineGeometry/StraightGeometry.h"
#include "Fields/BMultipoleField.h"

25 26
template <class T, unsigned Dim>
class PartBunchBase;
gsell's avatar
gsell committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
class Fieldmap;

// Class Multipole
// ------------------------------------------------------------------------
/// Interface for general multipole.
//  Class Multipole defines the abstract interface for magnetic multipoles.
//  The order n of multipole components runs from 1 to N and is dynamically
//  adjusted. It is connected with the number of poles by the table
//
//  [tab 2 b]
//  [ROW]1[&]dipole[/ROW]
//  [ROW]2[&]quadrupole[/ROW]
//  [ROW]3[&]sextupole[/ROW]
//  [ROW]4[&]octupole[/ROW]
//  [ROW]5[&]decapole[/ROW]
//  [ROW]n[&]multipole with 2*n poles[/ROW]
//  [/TAB]
//  Units for multipole strengths are Teslas / m**(n-1).

class Multipole: public Component {

public:

    /// Constructor with given name.
51
    explicit Multipole(const std::string &name);
gsell's avatar
gsell committed
52 53 54 55 56 57

    Multipole();
    Multipole(const Multipole &);
    virtual ~Multipole();

    /// Apply visitor to Multipole.
58
    virtual void accept(BeamlineVisitor &) const override;
gsell's avatar
gsell committed
59 60 61


    /// Get multipole field.
62
    virtual BMultipoleField &getField() override = 0;
gsell's avatar
gsell committed
63 64

    /// Get multipole field. Version for const object.
65
    virtual const BMultipoleField &getField() const override = 0;
gsell's avatar
gsell committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    /// Get normal component.
    //  Return the normal component of order [b]n[/b] in T/m**(n-1).
    //  If [b]n[/b] is larger than the maximum order, the return value is zero.
    double getNormalComponent(int n) const;

    /// Get skew component.
    //  Return the skew component of order [b]n[/b] in T/m**(n-1).
    //  If [b]n[/b] is larger than the maximum order, the return value is zero.
    double getSkewComponent(int n) const;

    /// Set normal component.
    //  Set the normal component of order [b]n[/b] in T/m**(n-1).
    //  If [b]n[/b] is larger than the maximum order, the component is created.
    void setNormalComponent(int, double);

82 83 84 85 86
    /// Set normal component.
    //  Set the normal component of order [b]n[/b] in T/m**(n-1).
    //  If [b]n[/b] is larger than the maximum order, the component is created.
    void setNormalComponent(int, double, double);

gsell's avatar
gsell committed
87 88 89 90 91
    /// Set skew component.
    //  Set the skew component of order [b]n[/b] in T/m**(n-1).
    //  If [b]n[/b] is larger than the maximum order, the component is created.
    void setSkewComponent(int, double);

92 93 94 95 96 97 98
    /// Set skew component.
    //  Set the skew component of order [b]n[/b] in T/m**(n-1).
    //  If [b]n[/b] is larger than the maximum order, the component is created.
    void setSkewComponent(int, double, double);

    size_t getMaxNormalComponentIndex() const;
    size_t getMaxSkewComponentIndex() const;
99
    
100 101
    //set number of slices for map tracking
    void setNSlices(const std::size_t& nSlices);
102
    
103 104
    //set number of slices for map tracking
    std::size_t getNSlices() const;
105 106 107

    bool isFocusing(unsigned int component) const;

gsell's avatar
gsell committed
108
    /// Get geometry.
109
    virtual StraightGeometry &getGeometry() override = 0;
gsell's avatar
gsell committed
110 111

    /// Get geometry.
112
    virtual const StraightGeometry &getGeometry() const override = 0;
gsell's avatar
gsell committed
113

114
    virtual void addKR(int i, double t, Vector_t &K) override;
gsell's avatar
gsell committed
115

116
    virtual void addKT(int i, double t, Vector_t &K) override;
gsell's avatar
gsell committed
117

118
    virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
gsell's avatar
gsell committed
119

120
    virtual bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override;
121

122
    virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override;
gsell's avatar
gsell committed
123

124
    virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override;
gsell's avatar
gsell committed
125

126
    virtual void finalise() override;
gsell's avatar
gsell committed
127

128
    virtual bool bends() const override;
gsell's avatar
gsell committed
129

130
    virtual ElementBase::ElementType getType() const override;
gsell's avatar
gsell committed
131

132
    virtual void getDimensions(double &zBegin, double &zEnd) const override;
gsell's avatar
gsell committed
133

134
    virtual bool isInside(const Vector_t &r) const override;
gsell's avatar
gsell committed
135
private:
136
    void computeField(Vector_t R, Vector_t &E, Vector_t &B);
gsell's avatar
gsell committed
137 138 139 140

    // Not implemented.
    void operator=(const Multipole &);
    std::vector<double> NormalComponents;
141
    std::vector<double> NormalComponentErrors;
gsell's avatar
gsell committed
142
    std::vector<double> SkewComponents;
143
    std::vector<double> SkewComponentErrors;
gsell's avatar
gsell committed
144 145
    int max_SkewComponent_m;
    int max_NormalComponent_m;
146
    std::size_t nSlices_m;
gsell's avatar
gsell committed
147 148
};

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
inline
void Multipole::setNormalComponent(int n, double v) {
    setNormalComponent(n, v, 0.0);
}

inline
void Multipole::setSkewComponent(int n, double v) {
    setSkewComponent(n, v, 0.0);
}

inline
size_t Multipole::getMaxNormalComponentIndex() const {
    return NormalComponents.size();
}

inline
size_t Multipole::getMaxSkewComponentIndex() const {
    return SkewComponents.size();
}

169
#endif // CLASSIC_Multipole_HH