BendBase.h 3.97 KB
Newer Older
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
1 2 3 4 5 6 7 8
#ifndef CLASSIC_BENDBASE_H
#define CLASSIC_BENDBASE_H

#include "AbsBeamline/Component.h"

#include <vector>
#include <string>

9 10
class Fieldmap;

Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class BendBase: public Component {
public:
    BendBase();
    BendBase(const BendBase &);
    BendBase(const std::string &);

    /// Indicates that element bends the beam.
    virtual bool bends() const;

    void setLength(double length);
    double getLength() const;
    double getChordLength() const;
    virtual void setBendAngle(double angle);
    double getBendAngle() const;
    virtual void setEntranceAngle(double entranceAngle);
    double getEntranceAngle() const;
27
    virtual double getExitAngle() const = 0;
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
28 29 30
    void setFullGap(double);
    double getFullGap() const;

gsell's avatar
gsell committed
31
    virtual void setDesignEnergy(const double& energy, bool changeable = true);
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
32 33 34 35 36 37 38 39 40
    double getDesignEnergy() const;
    std::vector<Vector_t> getDesignPath() const;

    void setFieldAmplitude(double k0, double k0s);
    double getFieldAmplitude() const;

    void setFieldMapFN(std::string fileName);
    std::string getFieldMapFN() const;
protected:
41 42 43 44 45 46 47 48 49 50 51 52 53
    /// Calculate design radius from design energy and field amplitude
    double calcDesignRadius(double fieldAmplitude) const;
    /// Calculate field amplitude from design energy and radius
    double calcFieldAmplitude(double radius) const;
    /// Calculate bend angle from chord length and design radius
    double calcBendAngle(double chordLength, double radius) const;
    /// Calculate design radius from chord length and bend angle
    double calcDesignRadius(double chordLength, double angle) const;
    /// Calculate gamma from design energy
    double calcGamma() const;
    /// Calculate beta*gamma from design energy
    double calcBetaGamma() const;

Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
54 55
    double length_m;
    double chordLength_m;
56 57 58 59 60
    double angle_m;         ///< Bend angle
    double entranceAngle_m; ///< Angle between incoming reference trajectory
                            ///< and the entrance face of the magnet (radians).
    Fieldmap *fieldmap_m;      ///< Magnet field map.
    const bool fast_m = false; ///< Flag to turn on fast field calculation.
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
61

62
    double gap_m; ///< Full vertical gap of the magnets.
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
63

64
    double designEnergy_m; ///< Bend design energy (eV).
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
65 66 67 68
    bool designEnergyChangeable_m;
    /// Map of reference particle trajectory.
    std::vector<Vector_t> refTrajMap_m;

69 70 71 72 73 74
    double fieldAmplitudeX_m; ///< Field amplitude in x direction.
                              ///< Value not updated if user defines strength with angle
    double fieldAmplitudeY_m; ///< Field amplitude in y direction.
                              ///< Value not updated if user defines strength with angle

    double fieldAmplitude_m;  ///< Field amplitude.
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

    std::string fileName_m;
};

inline
bool BendBase::bends() const {
    return true;
}

inline
void BendBase::setLength(double length) {
    length_m = std::abs(length);
}

inline
double BendBase::getLength() const
{
    return length_m;
}

inline
double BendBase::getChordLength() const {
    return chordLength_m;
}

inline
void BendBase::setBendAngle(double angle) {
    angle_m = angle;
}

inline
double BendBase::getBendAngle() const {
    return angle_m;
}

inline
void BendBase::setEntranceAngle(double angle)
{
    entranceAngle_m = angle;
}

inline
double BendBase::getEntranceAngle() const {
    return entranceAngle_m;
}

inline
void BendBase::setFullGap(double gap) {
    gap_m = std::abs(gap);
}

inline
double BendBase::getFullGap() const {
    return gap_m;
}

inline
gsell's avatar
gsell committed
132
void BendBase::setDesignEnergy(const double& energy, bool changeable) {
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    if (designEnergyChangeable_m) {
        designEnergy_m = std::abs(energy) * 1e6;
        designEnergyChangeable_m = changeable;
    }
}

inline
double BendBase::getDesignEnergy() const {
    return designEnergy_m;
}

inline
double BendBase::getFieldAmplitude() const
{
    return fieldAmplitude_m;
}

inline
void BendBase::setFieldMapFN(std::string fileName) {
    fileName_m = fileName;
}

inline
std::string BendBase::getFieldMapFN() const {
    return fileName_m;
}


161
#endif