PartBunchBase.h 17.7 KB
Newer Older
1 2 3
#ifndef PART_BUNCH_BASE_H
#define PART_BUNCH_BASE_H

4 5
#include "Ippl.h"
#include "Particle/AbstractParticle.h" //TODO should be in Ippl.h
6
#include "Algorithms/PBunchDefs.h"
7 8 9 10 11 12 13 14 15
#include "Algorithms/OpalParticle.h"
#include "Algorithms/CoordinateSystemTrafo.h"
#include "FixedAlgebra/FMatrix.h"
#include "FixedAlgebra/FVector.h"
#include "Algorithms/PartBins.h"
#include "Algorithms/PartBinsCyc.h"
#include "Algorithms/PartData.h"
#include "Algorithms/Quaternion.h"

16 17
#include <memory>
#include <utility>
18 19 20 21
#include <vector>

#include "Structure/FieldSolver.h"
#include "Algorithms/ListElem.h"
snuverink_j's avatar
snuverink_j committed
22

frey_m's avatar
frey_m committed
23
class Distribution;
24 25 26

template <class T, int, int> class FMatrix;
template <class T, int> class FVector;
27 28 29 30

template <class T, unsigned Dim>
class PartBunchBase
{
31
public:
32
    typedef typename AbstractParticle<T, Dim>::ParticlePos_t   ParticlePos_t;
33
    typedef typename AbstractParticle<T, Dim>::ParticleIndex_t ParticleIndex_t;
34 35
    typedef typename AbstractParticle<T, Dim>::UpdateFlags     UpdateFlags_t;
    typedef typename AbstractParticle<T, Dim>::Position_t      Position_t;
kraus's avatar
kraus committed
36

37
    typedef std::pair<Vector_t, Vector_t> VectorPair_t;
kraus's avatar
kraus committed
38

39
    static const unsigned Dimension = Dim;
kraus's avatar
kraus committed
40

41
    enum UnitState_t { units = 0, unitless = 1 };
kraus's avatar
kraus committed
42

43
public:
kraus's avatar
kraus committed
44

45
    explicit PartBunchBase(AbstractParticle<T, Dim>* pb);
kraus's avatar
kraus committed
46

frey_m's avatar
frey_m committed
47
    virtual ~PartBunchBase() { }
kraus's avatar
kraus committed
48

frey_m's avatar
frey_m committed
49
    PartBunchBase(AbstractParticle<T, Dim>* pb, const PartData *ref);
kraus's avatar
kraus committed
50

51
    PartBunchBase(const PartBunchBase &rhs) = delete; // implement if needed
kraus's avatar
kraus committed
52

53 54 55
    /*
     * Bunch common member functions
     */
kraus's avatar
kraus committed
56

57 58
    // This is required since we initialize the Layout and the RegionLayout with default constructor
    virtual void initialize(FieldLayout_t *fLayout) = 0;
kraus's avatar
kraus committed
59

60
    bool getIfBeamEmitting();
kraus's avatar
kraus committed
61

62
    int getLastEmittedEnergyBin();
kraus's avatar
kraus committed
63

64
    size_t getNumberOfEmissionSteps();
kraus's avatar
kraus committed
65

66
    int getNumberOfEnergyBins();
kraus's avatar
kraus committed
67

68
    void Rebin();
kraus's avatar
kraus committed
69

70
    void setEnergyBins(int numberOfEnergyBins);
kraus's avatar
kraus committed
71

72
    bool weHaveEnergyBins();
kraus's avatar
kraus committed
73

74
    //FIXME: unify methods, use convention that all particles have own dt
75
    void switchToUnitlessPositions(bool use_dt_per_particle = false);
kraus's avatar
kraus committed
76

77
    //FIXME: unify methods, use convention that all particles have own dt
78
    void switchOffUnitlessPositions(bool use_dt_per_particle = false);
kraus's avatar
kraus committed
79

80 81
    void setDistribution(Distribution *d,
                         std::vector<Distribution *> addedDistributions,
82
                         size_t &np);
kraus's avatar
kraus committed
83

84
    bool isGridFixed() const;
85

86
    bool hasBinning() const;
kraus's avatar
kraus committed
87 88


89 90 91
    /*
       Energy bins related functions
     */
kraus's avatar
kraus committed
92

93
    void setTEmission(double t);
kraus's avatar
kraus committed
94

95
    double getTEmission();
kraus's avatar
kraus committed
96

97
    bool doEmission();
kraus's avatar
kraus committed
98

99
    bool weHaveBins() const;
kraus's avatar
kraus committed
100

101
    void setPBins(PartBins *pbin);
kraus's avatar
kraus committed
102

103
    void setPBins(PartBinsCyc *pbin);
kraus's avatar
kraus committed
104

105 106 107 108
    /** \brief Emit particles in the given bin
        i.e. copy the particles from the bin structure into the
        particle container
    */
109
    size_t emitParticles(double eZ);
kraus's avatar
kraus committed
110

111
    void updateNumTotal();
kraus's avatar
kraus committed
112

113
    void rebin();
kraus's avatar
kraus committed
114

115
    int getLastemittedBin();
kraus's avatar
kraus committed
116

117 118
    void setLocalBinCount(size_t num, int bin);

119
    /** \brief Compute the gammas of all bins */
120
    void calcGammas();
kraus's avatar
kraus committed
121

122
    void calcGammas_cycl();
kraus's avatar
kraus committed
123

124 125
    /** \brief Get gamma of one bin */
    double getBinGamma(int bin);
kraus's avatar
kraus committed
126

127
    /** \brief Set the charge of one bin to the value of q and all other to zero */
128
    virtual void setBinCharge(int bin, double q);
kraus's avatar
kraus committed
129

130
    /** \brief Set the charge of all other the ones in bin to zero */
131
    virtual void setBinCharge(int bin);
kraus's avatar
kraus committed
132

133
    /** \brief returns the number of particles outside of a box defined by x */
134
    size_t calcNumPartsOutside(Vector_t x);
kraus's avatar
kraus committed
135

136 137
    void calcLineDensity(unsigned int nBins, std::vector<double> &lineDensity,
                         std::pair<double, double> &meshInfo);
kraus's avatar
kraus committed
138

139 140
    void setBeamFrequency(double v);

141 142 143
    /*
       Mesh and Field Layout related functions
     */
kraus's avatar
kraus committed
144

145
    virtual void boundp();
kraus's avatar
kraus committed
146

frey_m's avatar
frey_m committed
147 148
    /** delete particles which are too far away from the center of beam*/
    void boundp_destroy();
kraus's avatar
kraus committed
149

150
    /** This is only temporary in order to get the collimator and pepperpot working */
frey_m's avatar
frey_m committed
151
    size_t boundp_destroyT();
kraus's avatar
kraus committed
152

frey_m's avatar
frey_m committed
153
    size_t destroyT();
kraus's avatar
kraus committed
154

155 156 157
    /*
       Read out coordinates
     */
kraus's avatar
kraus committed
158

159 160
    virtual double getPx(int i);
    virtual double getPy(int i);
161 162 163
    virtual double getPz(int i);

    virtual double getPx0(int i);
164
    virtual double getPy0(int i);
165 166 167 168 169 170 171 172 173

    virtual double getX(int i);
    virtual double getY(int i);
    virtual double getZ(int i);

    virtual double getX0(int i);
    virtual double getY0(int i);

    virtual void setZ(int i, double zcoo);
kraus's avatar
kraus committed
174

175
    void get_bounds(Vector_t &rmin, Vector_t &rmax);
kraus's avatar
kraus committed
176

177
    void getLocalBounds(Vector_t &rmin, Vector_t &rmax);
kraus's avatar
kraus committed
178

179
    std::pair<Vector_t, double> getBoundingSphere();
kraus's avatar
kraus committed
180

181
    std::pair<Vector_t, double> getLocalBoundingSphere();
kraus's avatar
kraus committed
182 183


184 185 186
    /*
       Compatibility function push_back
     */
kraus's avatar
kraus committed
187

188
    void push_back(OpalParticle p);
kraus's avatar
kraus committed
189

190 191
    void set_part(FVector<double, 6> z, int ii);

192
    void set_part(OpalParticle p, int ii);
kraus's avatar
kraus committed
193

194
    OpalParticle get_part(int ii);
kraus's avatar
kraus committed
195

196 197 198 199 200 201
    /// Return maximum amplitudes.
    //  The matrix [b]D[/b] is used to normalise the first two modes.
    //  The maximum normalised amplitudes for these modes are stored
    //  in [b]axmax[/b] and [b]aymax[/b].
    void maximumAmplitudes(const FMatrix<double, 6, 6> &D,
                           double &axmax, double &aymax);
kraus's avatar
kraus committed
202

203
    void   setdT(double dt);
204 205 206
    double getdT() const;

    void   setT(double t);
207
    void   incrementT();
208
    double getT() const;
kraus's avatar
kraus committed
209

210 211 212 213 214 215
    /**
     * get the spos of the primary beam
     *
     * @param none
     *
     */
216
    double get_sPos() const;
kraus's avatar
kraus committed
217

218 219 220
    void set_sPos(double s);

    double get_gamma() const;
kraus's avatar
kraus committed
221

222 223 224 225 226 227 228 229 230 231 232 233
    double get_meanKineticEnergy() const;
    Vector_t get_origin() const;
    Vector_t get_maxExtent() const;
    Vector_t get_centroid() const;
    Vector_t get_rrms() const;
    Vector_t get_rprms() const;
    Vector_t get_rmean() const;
    Vector_t get_prms() const;
    Vector_t get_pmean() const;
    Vector_t get_pmean_Distribution() const;
    Vector_t get_emit() const;
    Vector_t get_norm_emit() const;
234
    Vector_t get_halo() const;
frey_m's avatar
frey_m committed
235
    virtual Vector_t get_hr() const;
236 237 238 239 240 241

    double get_Dx() const;
    double get_Dy() const;

    double get_DDx() const;
    double get_DDy() const;
kraus's avatar
kraus committed
242

frey_m's avatar
frey_m committed
243
    virtual void set_meshEnlargement(double dh);
244

245 246
    double getMeshEnlargement() const;

247 248
    void gatherLoadBalanceStatistics();
    size_t getLoadBalance(int p) const;
kraus's avatar
kraus committed
249

250
    void get_PBounds(Vector_t &min, Vector_t &max) const;
kraus's avatar
kraus committed
251

252
    void calcBeamParameters();
kraus's avatar
kraus committed
253

254
    void calcBeamParametersInitial(); // Calculate initial beam parameters before emission.
kraus's avatar
kraus committed
255

256 257
    double getCouplingConstant() const;
    void setCouplingConstant(double c);
kraus's avatar
kraus committed
258

259 260 261 262 263 264 265
    // set the charge per simulation particle
    void setCharge(double q);
    // set the charge per simulation particle when total particle number equals 0
    void setChargeZeroPart(double q);

    // set the mass per simulation particle
    void setMass(double mass);
kraus's avatar
kraus committed
266

267 268 269 270 271
    /// get the total charge per simulation particle
    double getCharge() const;

    /// get the macro particle charge
    double getChargePerParticle() const;
kraus's avatar
kraus committed
272

273
    virtual void setSolver(FieldSolver *fs);
kraus's avatar
kraus committed
274

275
    bool hasFieldSolver();
kraus's avatar
kraus committed
276

277
    std::string getFieldSolverType() const;
kraus's avatar
kraus committed
278

279 280 281 282 283 284 285 286 287 288 289 290
    void setStepsPerTurn(int n);
    int getStepsPerTurn() const;

    /// step in multiple TRACK commands
    void setGlobalTrackStep(long long n);
    long long getGlobalTrackStep() const;

    /// step in a TRACK command
    void setLocalTrackStep(long long n);
    void incTrackSteps();
    long long getLocalTrackStep() const;

frey_m's avatar
frey_m committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304
    void setNumBunch(short n);
    short getNumBunch() const;

    // used in ParallelCyclotronTracker for multi-bunch mode
    void setTotalNumPerBunch(size_t numpart, short n);
    size_t getTotalNumPerBunch(short n) const;

    void setLocalNumPerBunch(size_t numpart, short n);
    size_t getLocalNumPerBunch(short n) const;

    /* used in initializeTracking_m of ParallelCyclotronTracker
     * for multi-bunch mode
     */
    void countTotalNumPerBunch();
305 306 307 308 309

    void setGlobalMeanR(Vector_t globalMeanR);
    Vector_t getGlobalMeanR();
    void setGlobalToLocalQuaternion(Quaternion_t globalToLocalQuaternion);
    Quaternion_t getGlobalToLocalQuaternion();
kraus's avatar
kraus committed
310

311
    void setSteptoLastInj(int n);
312
    int getSteptoLastInj() const;
kraus's avatar
kraus committed
313

314 315
    /// calculate average angle of longitudinal direction of bins
    double calcMeanPhi();
kraus's avatar
kraus committed
316

317 318
    /// reset Bin[] for each particle according to the method given in paper PAST-AB(064402) by  G. Fubiani et al.
    bool resetPartBinID2(const double eta);
kraus's avatar
kraus committed
319

frey_m's avatar
frey_m committed
320 321
    bool resetPartBinBunch();

322
    ///@{ Access to reference data
323 324 325 326
    double getQ() const;
    double getM() const;
    double getP() const;
    double getE() const;
327 328 329 330 331
    ParticleType::type getPType() const;
    double getInitialBeta() const;
    double getInitialGamma() const;
    ///@}
    ///@{ Set reference data
332 333
    void resetQ(double q);
    void resetM(double m);
334 335
    void setPType(ParticleType::type);
    ///@}
336
    double getdE() const;
337 338 339
    virtual double getGamma(int i);
    virtual double getBeta(int i);
    virtual void actT();
kraus's avatar
kraus committed
340

341
    const PartData *getReference() const;
kraus's avatar
kraus committed
342

343
    double getEmissionDeltaT();
kraus's avatar
kraus committed
344

345 346 347 348 349 350
    Quaternion_t getQKs3D();
    void         setQKs3D(Quaternion_t q);
    Vector_t     getKs3DRefr();
    void         setKs3DRefr(Vector_t r);
    Vector_t     getKs3DRefp();
    void         setKs3DRefp(Vector_t p);
kraus's avatar
kraus committed
351

352
    void iterateEmittedBin(int binNumber);
kraus's avatar
kraus committed
353

354
    void calcEMean();
kraus's avatar
kraus committed
355

356
    Inform &print(Inform &os);
kraus's avatar
kraus committed
357

358
    /*
kraus's avatar
kraus committed
359
     * (Pure) virtual member functions
360
     */
kraus's avatar
kraus committed
361

362
    virtual void runTests();
kraus's avatar
kraus committed
363

frey_m's avatar
frey_m committed
364
    virtual void do_binaryRepart();
kraus's avatar
kraus committed
365

366
    virtual void resetInterpolationCache(bool clearCache = false);
kraus's avatar
kraus committed
367

368 369
    /** \brief calculates back the max/min of the efield on the grid */
    virtual VectorPair_t getEExtrema() = 0;
kraus's avatar
kraus committed
370

371
    virtual double getRho(int x, int y, int z) = 0;
kraus's avatar
kraus committed
372

373
    virtual void computeSelfFields() = 0;
374 375

    /** /brief used for self fields with binned distribution */
376
    virtual void computeSelfFields(int bin) = 0;
377

378
    virtual void computeSelfFields_cycl(double gamma) = 0;
379
    virtual void computeSelfFields_cycl(int bin) = 0;
kraus's avatar
kraus committed
380

frey_m's avatar
frey_m committed
381
    virtual void swap(unsigned int i, unsigned int j);
kraus's avatar
kraus committed
382

frey_m's avatar
frey_m committed
383 384 385
    /*
       Mesh and Field Layout related functions
     */
kraus's avatar
kraus committed
386

frey_m's avatar
frey_m committed
387 388 389 390
    virtual void setBCAllPeriodic();
    virtual void setBCAllOpen();

    virtual void setBCForDCBeam();
kraus's avatar
kraus committed
391 392


393
//     virtual void setMesh(Mesh_t* mesh) = 0;
394
//     virtual Mesh_t &getMesh() = 0;
kraus's avatar
kraus committed
395

396 397
//     virtual void setFieldLayout(FieldLayout_t* fLayout) = 0;
    virtual FieldLayout_t &getFieldLayout() = 0;
kraus's avatar
kraus committed
398

399 400
    virtual void resizeMesh() { };

401 402 403
    /*
     * Wrapped member functions of IpplParticleBase
     */
kraus's avatar
kraus committed
404

405 406 407 408
    size_t getTotalNum() const;
    void setTotalNum(size_t n);
    void setLocalNum(size_t n);
    size_t getLocalNum() const;
kraus's avatar
kraus committed
409

410 411
    size_t getDestroyNum() const;
    size_t getGhostNum() const;
kraus's avatar
kraus committed
412

413 414
    unsigned int getMinimumNumberOfParticlesPerCore() const;
    void setMinimumNumberOfParticlesPerCore(unsigned int n);
kraus's avatar
kraus committed
415

416 417
    ParticleLayout<T, Dim> & getLayout();
    const ParticleLayout<T, Dim>& getLayout() const;
kraus's avatar
kraus committed
418

419 420
    bool getUpdateFlag(UpdateFlags_t f) const;
    void setUpdateFlag(UpdateFlags_t f, bool val);
kraus's avatar
kraus committed
421 422


423 424 425
    ParticleBConds<Position_t, Dimension>& getBConds() {
        return pbase->getBConds();
    }
kraus's avatar
kraus committed
426

427 428 429
    void setBConds(const ParticleBConds<Position_t, Dimension>& bc) {
        pbase->setBConds(bc);
    }
kraus's avatar
kraus committed
430

431
    bool singleInitNode() const;
kraus's avatar
kraus committed
432

433
    void resetID();
kraus's avatar
kraus committed
434

435 436
    void update();
    void update(const ParticleAttrib<char>& canSwap);
kraus's avatar
kraus committed
437

438 439 440
    void createWithID(unsigned id);
    void create(size_t M);
    void globalCreate(size_t np);
kraus's avatar
kraus committed
441

442 443 444
    void destroy(size_t M, size_t I, bool doNow = false);
    void performDestroy(bool updateLocalNum = false);
    void ghostDestroy(size_t M, size_t I);
kraus's avatar
kraus committed
445

446
protected:
447
    size_t calcMoments();    // Calculates bunch moments using only emitted particles.
kraus's avatar
kraus committed
448

snuverink_j's avatar
snuverink_j committed
449
    /* Calculates bunch moments by summing over bins
450 451 452
     * (not accurate when any particles have been emitted).
     */
    void calcMomentsInitial();
snuverink_j's avatar
snuverink_j committed
453
    /// angle range [0~2PI) degree
454
    double calculateAngle(double x, double y);
kraus's avatar
kraus committed
455 456


frey_m's avatar
frey_m committed
457
private:
frey_m's avatar
frey_m committed
458
    virtual void updateDomainLength(Vektor<int, 3>& grid) = 0;
kraus's avatar
kraus committed
459

frey_m's avatar
frey_m committed
460
    virtual void updateFields(const Vector_t& hr, const Vector_t& origin);
kraus's avatar
kraus committed
461

frey_m's avatar
frey_m committed
462
    void setup(AbstractParticle<T, Dim>* pb);
kraus's avatar
kraus committed
463

464 465 466 467
public:
    /*
     * Bunch attributes
     */
kraus's avatar
kraus committed
468 469


470 471
    ParticlePos_t& R;
    ParticleIndex_t& ID;
kraus's avatar
kraus committed
472 473


474 475 476 477 478 479 480 481
    // Particle container attributes
    ParticleAttrib< Vector_t > P;      // particle momentum //  ParticleSpatialLayout<double, 3>::ParticlePos_t P;
    ParticleAttrib< double >   Q;      // charge per simulation particle, unit: C.
    ParticleAttrib< double >   M;      // mass per simulation particle, for multi-species particle tracking, unit:GeV/c^2.
    ParticleAttrib< double >   Phi;    // the electric potential
    ParticleAttrib< Vector_t > Ef;     // e field vector
    ParticleAttrib< Vector_t > Eftmp;  // e field vector for gun simulations

482
    ParticleAttrib< Vector_t > Bf;    // b field vector
483 484 485 486 487
    ParticleAttrib< int >      Bin;   // holds the bin in which the particle is in, if zero particle is marked for deletion
    ParticleAttrib< double >   dt;   // holds the dt timestep for particle

    ParticleAttrib< short >    PType; // we can distinguish dark current particles from primary particle
    ParticleAttrib< int >      TriID; // holds the ID of triangle that the particle hit. Only for BoundaryGeometry case.
488
    ParticleAttrib< short >    cavityGapCrossed; ///< particle just crossed cavity gap (for ParallelCyclotronTracker)
kraus's avatar
kraus committed
489

490 491
    ParticleAttrib< short >    bunchNum; // bunch number to which particle belongs (multi-bunch mode)

kraus's avatar
kraus committed
492

493 494
    Vector_t RefPartR_m;
    Vector_t RefPartP_m;
495
    ParticleType::type refPType_m;
496
    CoordinateSystemTrafo toLabTrafo_m;
kraus's avatar
kraus committed
497

498 499 500 501 502 503
    // The structure for particle binning
    PartBins *pbin_m;

    /// timer for IC, can not be in Distribution.h
    IpplTimings::TimerRef distrReload_m;
    IpplTimings::TimerRef distrCreate_m;
504

505 506 507 508 509
    // For AMTS integrator in OPAL-T
    double dtScInit_m, deltaTau_m;

    /// if a local node has less than 2 particles  lowParticleCount_m == true
    bool lowParticleCount_m;
kraus's avatar
kraus committed
510

511 512 513
    // get 2nd order momentum matrix
    FMatrix<double, 2 * Dim, 2 * Dim> getSigmaMatrix();

514 515 516 517
    const Vector_t& getLowerBound() const;

    const Vector_t& getUpperBound() const;

518 519 520 521 522 523 524
private:
    // save particles in case of one core
    std::unique_ptr<Inform> pmsg_m;
    std::unique_ptr<std::ofstream> f_stream;
    /// if the grid does not have to adapt
    bool fixed_grid;

frey_m's avatar
frey_m committed
525
protected:
526
    IpplTimings::TimerRef boundpTimer_m;
527 528
    IpplTimings::TimerRef boundpBoundsTimer_m;
    IpplTimings::TimerRef boundpUpdateTimer_m;
529 530 531
    IpplTimings::TimerRef statParamTimer_m;

    IpplTimings::TimerRef histoTimer_m;
532 533
    /// timer for selfField calculation
    IpplTimings::TimerRef selfFieldTimer_m;
kraus's avatar
kraus committed
534 535


536
    const PartData *reference;
kraus's avatar
kraus committed
537 538


539 540 541 542 543 544 545 546 547 548
//     /*
//       Member variables starts here
//     */

    // unit state of PartBunch
    UnitState_t unit_state_;
    UnitState_t stateOfLastBoundP_;

    /// holds the centroid of the beam
    double centroid_m[2 * Dim];
kraus's avatar
kraus committed
549

550 551 552 553 554 555 556 557 558
    /// 6x6 matrix of the moments of the beam
    FMatrix<double, 2 * Dim, 2 * Dim> moments_m;

    /// holds the timestep in seconds
    double dt_m;
    /// holds the actual time of the integration
    double t_m;
    /// mean energy of the bunch (MeV)
    double eKin_m;
559
    /// energy spread of the beam in MeV
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
    double dE_m;
    /// the position along design trajectory
    double spos_m;

    /// Initialize the translation vector and rotation quaternion
    /// here. Cyclotron tracker will reset these values each timestep
    /// TTracker can just use 0 translation and 0 rotation (quat[1 0 0 0]).
    //Vector_t globalMeanR_m = Vector_t(0.0, 0.0, 0.0);
    //Quaternion_t globalToLocalQuaternion_m = Quaternion_t(1.0, 0.0, 0.0, 0.0);
    Vector_t globalMeanR_m;
    Quaternion_t globalToLocalQuaternion_m;

    /// maximal extend of particles
    Vector_t rmax_m;
    /// minimal extend of particles
    Vector_t rmin_m;

    /// rms beam size (m)
    Vector_t rrms_m;
    /// rms momenta
    Vector_t prms_m;
    /// mean position (m)
    Vector_t rmean_m;
    /// mean momenta
    Vector_t pmean_m;

    /// rms emittance (not normalized)
    Vector_t eps_m;

    /// rms normalized emittance
    Vector_t eps_norm_m;
frey_m's avatar
frey_m committed
591

592
    Vector_t halo_m;
frey_m's avatar
frey_m committed
593

594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
    /// rms correlation
    Vector_t rprms_m;

    /// dispersion x & y
    double Dx_m;
    double Dy_m;

    /// derivative of the dispersion
    double DDx_m;
    double DDy_m;

    /// meshspacing of cartesian mesh
    Vector_t hr_m;
    /// meshsize of cartesian mesh
    Vektor<int, 3> nr_m;

    /// stores the used field solver
    FieldSolver *fs_m;

    double couplingConstant_m;

    double qi_m;
kraus's avatar
kraus committed
616

617
    /// counter to store the distribution dump
618
    int distDump_m;
kraus's avatar
kraus committed
619

620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
    ///
    int fieldDBGStep_m;

    /// Mesh enlargement
    double dh_m; /// in % how much the mesh is enlarged

    /// if larger than 0, emitt particles for tEmission_m [s]
    double tEmission_m;

    /// holds the gamma of the bin
    std::unique_ptr<double[]> bingamma_m;

    //FIXME: this should go into the Bin class!
    // holds number of emitted particles of the bin
    // jjyang: opal-cycl use *nBin_m of pbin_m
    std::unique_ptr<size_t[]> binemitted_m;

    /// steps per turn for OPAL-cycl
    int stepsPerTurn_m;

    /// step in a TRACK command
641
    long long localTrackStep_m;
642 643 644 645 646

    /// if multiple TRACK commands
    long long globalTrackStep_m;

    /// current bunch number
frey_m's avatar
frey_m committed
647 648 649 650 651
    short numBunch_m;

    /// number of particles per bunch
    std::vector<size_t> bunchTotalNum_m;
    std::vector<size_t> bunchLocalNum_m;
652 653 654 655 656 657 658 659 660

    /// this parameter records the current steps since last bunch injection
    /// it helps to inject new bunches correctly in the restart run of OPAL-cycl
    /// it is stored during phase space dump.
    int SteptoLastInj_m;

    /*
      Data structure for particle load balance information
    */
kraus's avatar
kraus committed
661

662 663 664 665 666 667 668
    std::unique_ptr<size_t[]> globalPartPerNode_m;


    Distribution *dist_m;

    // flag to tell if we are a DC-beam
    bool dcBeam_m;
669
    double periodLength_m;
frey_m's avatar
frey_m committed
670
    std::shared_ptr<AbstractParticle<T, Dim> > pbase;
671 672 673 674
};

#include "PartBunchBase.hpp"

675
#endif