Cyclotron.h 6.37 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#ifndef CLASSIC_Cyclotron_HH
#define CLASSIC_Cyclotron_HH

// ------------------------------------------------------------------------
// $RCSfile: Cyclotron.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1.2.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Definitions for class: Cyclotron
//   Defines the abstract interface for a sector bend magnet.
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2007/08/01 $
// $Author: Yang, Adelmann $
//
// ------------------------------------------------------------------------

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

class Fieldmap;

enum BFieldType {PSIBF, CARBONBF,ANSYSBF,AVFEQBF, FFAGBF,BANDRF};

struct BfieldData {
    std::string filename;
    // known from file: field and three theta derivatives
    double *bfld;   //Bz
    double *dbt;    //dBz/dtheta
    double *dbtt;   //d2Bz/dtheta2
    double *dbttt;  //d3Bz/dtheta3

    // to be calculated in getdiffs: all other derivatives:
    double *dbr;    // dBz/dr
    double *dbrr;   // ...
    double *dbrrr;

    double *dbrt;
    double *dbrrt;
    double *dbrtt;

    // used to get (Br,Btheta,Bz) at any off-plane point
    double *f2;  // for Bz
    double *f3;  // for Br
    double *g3;  // for Btheta

    // Grid-Size
    //need to be read from inputfile.
    int nrad, ntet;

    // one more grid line is stored in azimuthal direction:
    int ntetS;

    // total grid points number.
    int ntot;

    // Mean and Maximas
    double bacc, dbtmx, dbttmx, dbtttmx;


};

struct BPositions {
    // this 4 parameters are need to be read from field file.
    double  rmin, delr;
    double  tetmin, dtet;

    // Radii and step width of initial Grid
    double *rarr;

    //  int     ThetaPeriodicity; // Periodicity of Magnetic field
    double  Bfact;      // MULTIPLICATION FACTOR FOR MAGNETIC FIELD
};


// Class Cyclotron
// ------------------------------------------------------------------------
/// Interface for a Cyclotron.
//  This class defines the abstract interface for a Cyclotron.

class Cyclotron: public Component {

public:

    /// Constructor with given name.
    explicit Cyclotron(const std::string &name);

    Cyclotron();
    Cyclotron(const Cyclotron &);
    virtual ~Cyclotron();

    /// Apply visitor to Cyclotron.
    virtual void accept(BeamlineVisitor &) const;

    /// Get number of slices.
    //  Slices and stepsize used to determine integration step.
    virtual double getSlices() const = 0;

    /// Get stepsize.
    //  Slices and stepsize used to determine integration step.
    virtual double getStepsize() const = 0;

    void setFieldMapFN(std::string fmapfn);
    virtual std::string getFieldMapFN() const;

    void setRfFieldMapFN(std::vector<std::string> rffmapfn);

    void setType(std::string t);
    virtual const std::string &getType() const;

    virtual void getDimensions(double &zBegin, double &zEnd) const;

    void setCyclHarm(double h);
    virtual double getCyclHarm() const;

    void setRfPhi(std::vector<double> f);

    void setRfFrequ(std::vector<double> f);

    void setSymmetry(double symmetry);
    virtual double getSymmetry() const;

    void   setRinit(double rinit);
    virtual double getRinit() const;

    void   setPRinit(double prinit);
    virtual double getPRinit() const;

    void   setPHIinit(double phiinit);
    virtual double getPHIinit() const;

    void   setBScale(double bs);
    virtual double getBScale() const;

    void   setEScale(std::vector<double> bs);

    void   setTCr1(double tcr1);
    virtual  double getTCr1() const;

    void   setTCr2(double tcr2);
    virtual  double getTCr2() const;

    void   setMBtc(double mbtc);
    virtual  double getMBtc() const;

    void   setSLPtc(double slptc);
    virtual  double getSLPtc() const;

156 157 158
    void   setSuperpose(bool flag);
    virtual bool getSuperpose() const;

gsell's avatar
gsell committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    virtual bool apply(const int &i, const double &t, double E[], double B[]);

    virtual bool apply(const int &i, const double &t, Vector_t &E, Vector_t &B);

    virtual bool apply(const Vector_t &R, const Vector_t &centroid, const double &t, Vector_t &E, Vector_t &B);

    virtual void initialise(PartBunch *bunch, double &startField, double &endField, const double &scaleFactor);

    virtual void initialise(PartBunch *bunch, const int &fieldflag, const double &scaleFactor);

    virtual void finalise();

    virtual bool bends() const;

    virtual double getRmax() const;

    virtual double getRmin() const;

private:

    std::string fmapfn_m; /* stores the filename of the fieldmap */
    std::vector<double> rffrequ_m;
    std::vector<double> rfphi_m;
    std::vector<double> escale_m; // a scale factor for the E-field
183
    bool superpose_m; // electric fields are superposed or not 
gsell's avatar
gsell committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234

    double symmetry_m;

    double rinit_m;
    double prinit_m;
    double phiinit_m;

    std::string type_m; /* what type of field we use */
    double harm_m;

    double bscale_m; // a scale factor for the B-field

    double tcr1_m;
    double tcr2_m;
    double mbtc_m;
    double slptc_m;

    // Not implemented.
    void operator=(const Cyclotron &);

    // object of Matrics including magnetic field map and its derivates
    BfieldData Bfield;

    // object of parameters about the map grid
    BPositions BP;

    BFieldType myBFieldType_m;
    
    // RF field map handler
    //    Fieldmap *RFfield;
    std::vector<Fieldmap *> RFfields_m; 
    std::vector<std::string> RFfilename_m;

    void   getdiffs();

    double gutdf5d(double *f, double dx, const int kor, const int krl, const int lpr);

    void   initR(double rmin, double dr, int nrad);

    void   getFieldFromFile(const double &scaleFactor);
    void   getFieldFromFile_Carbon(const double &scaleFactor);
    void   getFieldFromFile_CYCIAE(const double &scaleFactor);
    void   getFieldFromFile_AVFEQ(const double &scaleFactor);
    void   getFieldFromFile_FFAG(const double &scaleFactor);
    void   getFieldFromFile_BandRF(const double &scaleFactor);

    inline int idx(int irad, int ktet) {return (ktet + Bfield.ntetS * irad);}

};

#endif // CLASSIC_Cyclotron_HH