Cyclotron.h 8.89 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12
#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
13
//   Defines the abstract interface for a cyclotron.
gsell's avatar
gsell committed
14 15 16 17 18 19 20 21 22 23 24
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2007/08/01 $
// $Author: Yang, Adelmann $
//
// ------------------------------------------------------------------------

#include "AbsBeamline/Component.h"
snuverink_j's avatar
snuverink_j committed
25 26 27

#include <string>
#include <vector>
gsell's avatar
gsell committed
28 29

class Fieldmap;
30
class LossDataSink;
31
class TrimCoil;
gsell's avatar
gsell committed
32

ext-rogers_c's avatar
ext-rogers_c committed
33
enum BFieldType {PSIBF,CARBONBF,ANSYSBF,AVFEQBF,FFABF,BANDRF,SYNCHRO};
gsell's avatar
gsell committed
34 35 36 37

struct BfieldData {
    std::string filename;
    // known from file: field and three theta derivatives
38 39 40 41
    std::vector<double> bfld;   //Bz
    std::vector<double> dbt;    //dBz/dtheta
    std::vector<double> dbtt;   //d2Bz/dtheta2
    std::vector<double> dbttt;  //d3Bz/dtheta3
gsell's avatar
gsell committed
42 43

    // to be calculated in getdiffs: all other derivatives:
44 45 46
    std::vector<double> dbr;    // dBz/dr
    std::vector<double> dbrr;   // ...
    std::vector<double> dbrrr;
gsell's avatar
gsell committed
47

48 49 50
    std::vector<double> dbrt;
    std::vector<double> dbrrt;
    std::vector<double> dbrtt;
gsell's avatar
gsell committed
51 52

    // used to get (Br,Btheta,Bz) at any off-plane point
53 54 55
    std::vector<double> f2;  // for Bz
    std::vector<double> f3;  // for Br
    std::vector<double> g3;  // for Btheta
gsell's avatar
gsell committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

    // 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 {
74
    // these 4 parameters are need to be read from field file.
gsell's avatar
gsell committed
75 76 77 78
    double  rmin, delr;
    double  tetmin, dtet;

    // Radii and step width of initial Grid
79
    std::vector<double> rarr;
gsell's avatar
gsell committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

    //  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 &);
99

gsell's avatar
gsell committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    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);
117
    void setRFFCoeffFN(std::vector<std::string> rff_coeff_fn);
118
    void setRFVCoeffFN(std::vector<std::string> rfv_coeff_fn);
119 120
    
    int getFieldFlag(const std::string& type) const;
gsell's avatar
gsell committed
121 122

    void setType(std::string t);
123 124
    const std::string &getCyclotronType() const;
    virtual ElementBase::ElementType getType() const;
gsell's avatar
gsell committed
125 126 127

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

128 129
    unsigned int getNumberOfTrimcoils() const;

gsell's avatar
gsell committed
130 131 132 133
    void setCyclHarm(double h);
    virtual double getCyclHarm() const;

    void setRfPhi(std::vector<double> f);
134
    double getRfPhi(unsigned int i) const;
gsell's avatar
gsell committed
135 136

    void setRfFrequ(std::vector<double> f);
137
    double getRfFrequ(unsigned int i) const;
gsell's avatar
gsell committed
138 139 140 141 142 143 144 145 146 147 148 149 150

    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;

151 152
    void   setZinit(double zinit);
    virtual double getZinit() const;
153

154 155 156
    void   setPZinit(double zinit);
    virtual double getPZinit() const;

gsell's avatar
gsell committed
157 158 159 160
    void   setBScale(double bs);
    virtual double getBScale() const;

    void   setEScale(std::vector<double> bs);
161
    virtual double getEScale(unsigned int i) const;
gsell's avatar
gsell committed
162

frey_m's avatar
frey_m committed
163
    void setTrimCoils(const std::vector<TrimCoil*> &trimcoils);
164

165
    void setSuperpose(std::vector<bool> flag);
166
    virtual bool getSuperpose(unsigned int i) const;
167

168 169 170 171 172 173 174 175 176 177
    void setMinR(double r);
    virtual double getMinR() const;
    void setMaxR(double r);
    virtual double getMaxR() const;

    void setMinZ(double z);
    virtual double getMinZ() const;
    void setMaxZ(double z);
    virtual double getMaxZ() const;

178 179 180 181
    void setFMLowE(double e);
    virtual double getFMLowE() const;
    void setFMHighE(double e);
    virtual double getFMHighE() const;
182

183 184 185
    void setTrimCoilThreshold(double);
    virtual double getTrimCoilThreshold() const;

186 187 188
    void setSpiralFlag(bool spiral_flag);
    virtual bool getSpiralFlag() const;

189
    virtual bool apply(const size_t &id, const double &t, Vector_t &E, Vector_t &B);
gsell's avatar
gsell committed
190

191
    virtual bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B);
gsell's avatar
gsell committed
192

193 194 195 196
    virtual void apply(const double& rad, const double& z,
                       const double& tet_rad, double& br,
                       double& bt, double& bz);

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

199
    virtual void initialise(PartBunchBase<double, 3> *bunch, const int &fieldflag, const double &scaleFactor);
gsell's avatar
gsell committed
200 201 202 203 204 205 206 207

    virtual void finalise();

    virtual bool bends() const;

    virtual double getRmax() const;

    virtual double getRmin() const;
208

209 210 211 212 213 214 215 216
    bool interpolate(const double& rad,
                     const double& tet_rad,
                     double& br,
                     double& bt,
                     double& bz);
    
    void read(const int &fieldflag, const double &scaleFactor);
    
217
private:
218 219 220 221
    /// Apply trim coils (calculate field contributions) with smooth field transition
    void applyTrimCoil  (const double r, const double z, const double tet_rad, double& br, double& bz);
    /// Apply trim coils (calculate field contributions)
    void applyTrimCoil_m(const double r, const double z, const double tet_rad, double *br, double *bz);
222

frey_m's avatar
frey_m committed
223
protected:
224 225
    
    
frey_m's avatar
frey_m committed
226 227 228 229 230
    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);
gsell's avatar
gsell committed
231

frey_m's avatar
frey_m committed
232 233 234 235
    void   getFieldFromFile(const double &scaleFactor);
    void   getFieldFromFile_Carbon(const double &scaleFactor);
    void   getFieldFromFile_CYCIAE(const double &scaleFactor);
    void   getFieldFromFile_AVFEQ(const double &scaleFactor);
ext-rogers_c's avatar
ext-rogers_c committed
236
    void   getFieldFromFile_FFA(const double &scaleFactor);
frey_m's avatar
frey_m committed
237 238 239 240
    void   getFieldFromFile_BandRF(const double &scaleFactor);
    void   getFieldFromFile_Synchrocyclotron(const double &scaleFactor);

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

frey_m's avatar
frey_m committed
242
    
gsell's avatar
gsell committed
243 244 245 246
private:

    std::string fmapfn_m; /* stores the filename of the fieldmap */
    std::vector<double> rffrequ_m;
247
    std::vector< std::vector<double> > rffc_m;
248 249
    std::vector<double> rfvrequ_m;
    std::vector< std::vector<double> > rfvc_m;
gsell's avatar
gsell committed
250
    std::vector<double> rfphi_m;
251
    std::vector<double> escale_m;  // a scale factor for the E-field
252
    std::vector<bool> superpose_m; // electric fields are superposed or not
gsell's avatar
gsell committed
253 254 255 256 257 258

    double symmetry_m;

    double rinit_m;
    double prinit_m;
    double phiinit_m;
259 260
    double zinit_m;
    double pzinit_m;
gsell's avatar
gsell committed
261

262
    bool spiral_flag_m;
263
    double trimCoilThreshold_m; ///< B-field threshold for applying trim coil
264

gsell's avatar
gsell committed
265 266 267 268 269
    std::string type_m; /* what type of field we use */
    double harm_m;

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

270 271
    /// Trim coils
    std::vector<TrimCoil*> trimcoils_m;
272

273 274 275 276 277 278
    double minr_m;
    double maxr_m;

    double minz_m;
    double maxz_m;

279 280 281
    double fmLowE_m;
    double fmHighE_m;

gsell's avatar
gsell committed
282
    // Not implemented.
283
    void operator=(const Cyclotron &) = delete;
gsell's avatar
gsell committed
284 285 286


    BFieldType myBFieldType_m;
287

gsell's avatar
gsell committed
288 289
    // RF field map handler
    //    Fieldmap *RFfield;
290
    std::vector<Fieldmap *> RFfields_m;
gsell's avatar
gsell committed
291
    std::vector<std::string> RFfilename_m;
292
    std::vector<std::string> RFFCoeff_fn_m;
293
    std::vector<std::string> RFVCoeff_fn_m;
294

295
    // handling for store the particle out of region
adelmann's avatar
adelmann committed
296
    std::unique_ptr<LossDataSink> lossDs_m;
297

298
    // Necessary for quick and dirty phase output -DW
299
    int waiting_for_gap = 1;
300

frey_m's avatar
frey_m committed
301
protected:
302
    // object of Matrices including magnetic field map and its derivates
frey_m's avatar
frey_m committed
303
    BfieldData Bfield;
gsell's avatar
gsell committed
304

frey_m's avatar
frey_m committed
305 306
    // object of parameters about the map grid
    BPositions BP;
gsell's avatar
gsell committed
307 308
};

309
#endif // CLASSIC_Cyclotron_HH