OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
PluginElement.h
Go to the documentation of this file.
1 #ifndef CLASSIC_PluginElement_HH
2 #define CLASSIC_PluginElement_HH
3 
5 #include <string>
6 #include <memory>
7 
8 template <class T, unsigned Dim>
9 class PartBunchBase;
10 
11 class LossDataSink;
12 
13 // Class PluginElement
14 // ------------------------------------------------------------------------
17 
18 class PluginElement: public Component {
19 
20 public:
22  explicit PluginElement(const std::string &name);
23 
24  PluginElement();
26  void operator=(const PluginElement &) = delete;
27  virtual ~PluginElement();
28 
30  virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override; // not used?
31  void initialise(PartBunchBase<double, 3> *bunch); // replacement for virtual initialise
32  virtual void finalise() final; // final since virtual hook doFinalise
33  virtual void goOffline() final; // final since virtual hook doGoOffline
34  virtual bool bends() const override;
35  virtual void getDimensions(double &zBegin, double &zEnd) const override;
38  virtual bool apply(const size_t &i,
39  const double &t,
40  Vector_t &E,
41  Vector_t &B) override;
42 
43  virtual bool applyToReferenceParticle(const Vector_t &R,
44  const Vector_t &P,
45  const double &t,
46  Vector_t &E,
47  Vector_t &B) override;
49 
51  void setOutputFN(std::string fn);
53  std::string getOutputFN() const;
54 
56  void setDimensions(double xstart, double xend, double ystart, double yend);
57 
59  double getXStart() const;
60  double getXEnd() const;
61  double getYStart() const;
62  double getYEnd() const;
65  bool check(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep);
67  int checkPoint(const double & x, const double & y) const;
69  void save();
70 
71 protected:
73  void setGeom(const double dist);
75  void changeWidth(PartBunchBase<double, 3> *bunch, int i, const double tstep, const double tangle);
77  double calculateIncidentAngle(double xp, double yp) const;
78 
79 private:
81  bool preCheck(PartBunchBase<double, 3> *bunch) {return doPreCheck(bunch);}
83  bool finaliseCheck(PartBunchBase<double, 3> *bunch, bool flagNeedUpdate) {return doFinaliseCheck(bunch, flagNeedUpdate);}
85  virtual void doInitialise(PartBunchBase<double, 3> *bunch) {}
87  virtual bool doCheck(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep) = 0;
89  virtual void doSetGeom() {};
91  virtual bool doPreCheck(PartBunchBase<double, 3>*) {return true;}
93  virtual bool doFinaliseCheck(PartBunchBase<double, 3> *, bool flagNeedUpdate) {return flagNeedUpdate;}
95  virtual void doFinalise() {};
97  virtual void doGoOffline() {};
98 
99 protected:
100  /* Members */
101  std::string filename_m;
102  double position_m;
104  double xstart_m;
105  double xend_m;
106  double ystart_m;
107  double yend_m;
108  double rstart_m;
109  double rend_m;
111  double rmin_m;
113  double A_m, B_m, R_m, C_m;
114 
115  std::unique_ptr<LossDataSink> lossDs_m;
116  int numPassages_m = 0;
117 };
118 
119 #endif // CLASSIC_PluginElement_HH
bool preCheck(PartBunchBase< double, 3 > *bunch)
Check if bunch is close to element.
Definition: PluginElement.h:81
void save()
Save output.
double getXStart() const
Member variable access.
void operator=(const PluginElement &)=delete
bool finaliseCheck(PartBunchBase< double, 3 > *bunch, bool flagNeedUpdate)
Finalise call after check.
Definition: PluginElement.h:83
double calculateIncidentAngle(double xp, double yp) const
Calculate angle of particle/bunch wrt to element.
virtual void doGoOffline()
Virtual hook for goOffline.
Definition: PluginElement.h:97
Point geom_m[5]
actual geometry positions with adaptive width such that each particle hits element once per turn ...
virtual void finalise() final
double C_m
Geometric lengths used in calculations.
virtual bool doFinaliseCheck(PartBunchBase< double, 3 > *, bool flagNeedUpdate)
Virtual hook for finaliseCheck.
Definition: PluginElement.h:93
double getYEnd() const
std::unique_ptr< LossDataSink > lossDs_m
Pointer to Loss instance.
virtual void goOffline() final
double rmin_m
radius closest to the origin
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
void changeWidth(PartBunchBase< double, 3 > *bunch, int i, const double tstep, const double tangle)
Change probe width depending on step size and angle of particle.
double getYStart() const
Class: DataSink.
Definition: OpalData.h:29
int numPassages_m
Number of turns (number of times save() method is called)
double xstart_m
input geometry positions
virtual bool bends() const override
virtual bool doPreCheck(PartBunchBase< double, 3 > *)
Virtual hook for preCheck.
Definition: PluginElement.h:91
std::string getOutputFN() const
Get output filename.
std::string filename_m
Definition: PluginElement.h:97
void setGeom(const double dist)
Sets geometry geom_m with element width dist.
virtual void doSetGeom()
Virtual hook for setGeom.
Definition: PluginElement.h:89
virtual void doInitialise(PartBunchBase< double, 3 > *bunch)
Pure virtual hook for initialise.
Definition: PluginElement.h:85
double getXEnd() const
const std::string name
Interface for a single beam element.
Definition: Component.h:51
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Pure virtual implementation of Component.
void setOutputFN(std::string fn)
Set output filename.
virtual bool doCheck(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep)=0
Pure virtual hook for check.
int checkPoint(const double &x, const double &y) const
Checks if coordinate is within element.
bool check(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep)
virtual void getDimensions(double &zBegin, double &zEnd) const override
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
virtual void doFinalise()
Virtual hook for finalise.
Definition: PluginElement.h:95
void setDimensions(double xstart, double xend, double ystart, double yend)
Set dimensions and consistency checks.
virtual ~PluginElement()