OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PluginElement.h
Go to the documentation of this file.
1//
2// Class PluginElement
3// Abstract Interface for (Cyclotron) Plugin Elements (CCollimator, Probe, Stripper, Septum)
4// Implementation via Non-Virtual Interface Template Method
5//
6// Copyright (c) 2018-2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
19#ifndef CLASSIC_PluginElement_HH
20#define CLASSIC_PluginElement_HH
21
23#include <string>
24#include <memory>
25
26template <class T, unsigned Dim>
27class PartBunchBase;
28
29class LossDataSink;
30class PluginElement: public Component {
31
32public:
34 explicit PluginElement(const std::string &name);
35
38 void operator=(const PluginElement &) = delete;
39 virtual ~PluginElement();
40
42 virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) override; // not used?
43 void initialise(PartBunchBase<double, 3> *bunch); // replacement for virtual initialise
44 virtual void finalise() final; // final since virtual hook doFinalise
45 virtual void goOffline() final; // final since virtual hook doGoOffline
46 virtual bool bends() const override;
47 virtual void getDimensions(double &zBegin, double &zEnd) const override;
50 virtual bool apply(const size_t &i,
51 const double &t,
52 Vector_t &E,
53 Vector_t &B) override;
54
55 virtual bool applyToReferenceParticle(const Vector_t &R,
56 const Vector_t &P,
57 const double &t,
58 Vector_t &E,
59 Vector_t &B) override;
61
63 void setDimensions(double xstart, double xend, double ystart, double yend);
64
66 double getXStart() const;
67 double getXEnd() const;
68 double getYStart() const;
69 double getYEnd() const;
72 bool check(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep);
74 int checkPoint(const double & x, const double & y) const;
76 void save();
77
78protected:
80 void setGeom(const double dist);
82 void changeWidth(PartBunchBase<double, 3> *bunch, int i, const double tstep, const double tangle);
84 double calculateIncidentAngle(double xp, double yp) const;
85
86private:
88 bool preCheck(PartBunchBase<double, 3> *bunch) {return doPreCheck(bunch);}
90 bool finaliseCheck(PartBunchBase<double, 3> *bunch, bool flagNeedUpdate) {return doFinaliseCheck(bunch, flagNeedUpdate);}
92 virtual void doInitialise(PartBunchBase<double, 3>* /*bunch*/) {}
94 virtual bool doCheck(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep) = 0;
96 virtual void doSetGeom() {};
98 virtual bool doPreCheck(PartBunchBase<double, 3>*) {return true;}
100 virtual bool doFinaliseCheck(PartBunchBase<double, 3> *, bool flagNeedUpdate) {return flagNeedUpdate;}
102 virtual void doFinalise() {};
104 virtual void doGoOffline() {};
105
106protected:
107 /* Members */
109 double xstart_m;
110 double xend_m;
111 double ystart_m;
112 double yend_m;
113 double rstart_m;
114 double rend_m;
116 double rmin_m;
118 double A_m, B_m, R_m, C_m;
119
120 std::unique_ptr<LossDataSink> lossDs_m;
122};
123
124#endif // CLASSIC_PluginElement_HH
const std::string name
Interface for a single beam element.
Definition: Component.h:50
virtual void doInitialise(PartBunchBase< double, 3 > *)
Pure virtual hook for initialise.
Definition: PluginElement.h:92
int checkPoint(const double &x, const double &y) const
Checks if coordinate is within element.
void setGeom(const double dist)
Sets geometry geom_m with element width dist.
virtual void getDimensions(double &zBegin, double &zEnd) const override
virtual bool bends() const override
double C_m
Geometric lengths used in calculations.
double getYStart() const
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Pure virtual implementation of Component.
virtual void finalise() final
virtual void doSetGeom()
Virtual hook for setGeom.
Definition: PluginElement.h:96
virtual void doGoOffline()
Virtual hook for goOffline.
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.
int numPassages_m
Number of turns (number of times save() method is called)
Point geom_m[5]
actual geometry positions with adaptive width such that each particle hits element once per turn
bool check(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep)
virtual bool doFinaliseCheck(PartBunchBase< double, 3 > *, bool flagNeedUpdate)
Virtual hook for finaliseCheck.
virtual bool doPreCheck(PartBunchBase< double, 3 > *)
Virtual hook for preCheck.
Definition: PluginElement.h:98
virtual void doFinalise()
Virtual hook for finalise.
virtual void goOffline() final
double getXEnd() const
void operator=(const PluginElement &)=delete
double calculateIncidentAngle(double xp, double yp) const
Calculate angle of particle/bunch wrt to element.
double xstart_m
input geometry positions
void setDimensions(double xstart, double xend, double ystart, double yend)
Set dimensions and consistency checks.
std::unique_ptr< LossDataSink > lossDs_m
Pointer to Loss instance.
double getXStart() const
Member variable access.
bool finaliseCheck(PartBunchBase< double, 3 > *bunch, bool flagNeedUpdate)
Finalise call after check.
Definition: PluginElement.h:90
bool preCheck(PartBunchBase< double, 3 > *bunch)
Check if bunch is close to element.
Definition: PluginElement.h:88
double getYEnd() const
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
double rmin_m
radius closest to the origin
virtual bool doCheck(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep)=0
Pure virtual hook for check.
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
virtual ~PluginElement()
void save()
Save output.