OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
OutputPlane.h
Go to the documentation of this file.
1// Copyright (c) 2023, Chris Rogers
2// All rights reserved
3//
4// This file is part of OPAL.
5//
6// OPAL is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// You should have received a copy of the GNU General Public License
12// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
13//
14
15#ifndef CLASSIC_OutputPlane_HH
16#define CLASSIC_OutputPlane_HH
17
20#include "Fields/NullField.h"
21#include "Steppers/Steppers.h"
22#include "Steppers/RK4.h"
23
24#include <string>
25
26class Component;
27
54
55public:
56 enum class algorithm {RK4STEP, INTERPOLATION};
57
59 explicit OutputPlane(const std::string& name);
60
63
66
68 virtual ~OutputPlane();
69
71 ElementBase* clone() const override;
72
74 virtual void accept(BeamlineVisitor&) const override;
75
77 inline Component* getGlobalFieldMap() const;
79 inline void setGlobalFieldMap(Component* field);
80
82 inline Vector_t getNormal() const;
84 inline void setNormal(Vector_t normal);
85
87 inline Vector_t getCentre() const;
89 inline void setCentre(Vector_t centre);
90
92 inline double getTolerance() const;
94 inline void setTolerance(double tolerance);
95
97 inline size_t getMaxIterations() const;
99 inline void setMaxIterations(size_t max);
100
102 inline int getRecentre() const;
104 inline void setRecentre(int willRecentre);
105
107 inline double getRadialExtent() const;
109 inline void setRadialExtent(double r);
110
113 inline double getVerticalExtent() const;
115 inline void setVerticalExtent(double z);
116
119 inline double getHorizontalExtent() const;
121 inline void setHorizontalExtent(double width);
122
124 inline algorithm getAlgorithm() const;
126 inline void setAlgorithm(algorithm alg);
127
130 inline int getVerboseLevel() const;
137 inline void setVerboseLevel(int verbose);
138
184 bool checkOne(const int index, const double tstep, double chargeToMass,
185 double& t, Vector_t& R, Vector_t& P);
186
188 NullField& getField() override {return nullfield_m;}
190 const NullField& getField() const override {return nullfield_m;}
191
193 StraightGeometry& getGeometry() override {return geom_m;}
195 const StraightGeometry& getGeometry() const override {return geom_m;}
203 void RK4Step(const double& tstep,
204 const double& chargeToMass,
205 const double& t,
206 Vector_t& R,
207 Vector_t& P) const;
208
209 void operator=(const OutputPlane&) = delete;
210
211 //ElementBase::ElementType getType() const;
212 ElementType getType() const override;
213 void recentre(Vector_t R, Vector_t P);
214
215
216private:
218 virtual void doInitialise(PartBunchBase<double, 3>* /*bunch*/) override;
219
221 inline bool doPreCheck(PartBunchBase<double, 3> *bunch) override;
222
224 virtual bool doCheck(PartBunchBase<double, 3> *bunch,
225 const int turnnumber,
226 const double t,
227 const double tstep) override;
229 virtual void doGoOffline() override;
230 void getDerivatives(const Vector_t& R,
231 const Vector_t& P,
232 const double& t,
233 const double& chargeToMass,
234 double* yp) const;
235 double distanceToPlane(Vector_t point) const;
236 void rk4Test(double tstep, double chargeToMass,
237 double& t, Vector_t& R, Vector_t& P);
238 void interpolation(double& t, Vector_t& R, Vector_t& P);
239 bool getFieldsAtPoint(const Vector_t& R, const Vector_t& P, const double& t, Vector_t& Efield, Vector_t& Bfield);
240
241 Component* field_m = NULL; // field map - this is a borrowed pointer
242 Vector_t normal_m; // normal to the output plane
243 Vector_t centre_m; // centre of the output plane
244 double radialExtent_m = -1.0; // maximum radial extent of the plane (circular)
245 double verticalExtent_m = -1.0; // maximum vertical extent of the plane (rectangular)
246 double horizontalExtent_m = -1.0; // maximum horizontal extent of the plane (rectangular)
247 size_t maxIterations_m = 10; // maximum number of iterations when finding intercept
248 double tolerance_m = 1e-9; // tolerance on distance from plane when finding intercept
249 NullField nullfield_m; // dummy variable for inheritance
250 StraightGeometry geom_m; // dummy variable for inheritance
251 algorithm algorithm_m; // sets interpolation or RK4
252 int recentre_m = -1; // particle index for recentring
253 int nHits_m = 0; // counter for number of hits on the plane
254 int verbose_m = 0; // verbosity
255
256 typedef std::function<bool(const double&,
257 const size_t&,
258 Vector_t&,
260 std::unique_ptr<Stepper<function_t> > stepper_m;
261};
262
264 return field_m;
265}
266
268 field_m = field;
269}
270
272 return normal_m;
273}
274
276 normal_m = normal;
277 normal_m /= euclidean_norm(normal);
278}
279
281 return centre_m;
282}
283
285 centre_m = centre;
286}
287
289 return tolerance_m;
290}
291
292void OutputPlane::setTolerance(double tolerance) {
293 tolerance_m = tolerance;
294}
295
297 return maxIterations_m;
298}
299
302}
303
305 return horizontalExtent_m;
306}
307
309 horizontalExtent_m = width;
310}
311
313 return verticalExtent_m;
314}
315
317 verticalExtent_m = width;
318}
319
321 return radialExtent_m;
322}
323
324void OutputPlane::setRadialExtent(double radius) {
325 radialExtent_m = radius;
326}
327
329 return recentre_m;
330}
331
332void OutputPlane::setRecentre(int recentre) {
334}
335
337 return algorithm_m;
338}
339
341 algorithm_m = alg;
342}
343
345 return true;
346}
347
349 return verbose_m;
350}
351
353 verbose_m = verbose;
354}
355
356
357#endif // CLASSIC_OutputPlane_HH
ElementType
Definition: ElementBase.h:88
T euclidean_norm(const Vector< T > &)
Euclidean norm.
Definition: Vector.h:243
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
const std::string name
constexpr double e
The value of.
Definition: Physics.h:39
double function(PyOpalObjectNS::PyOpalObject< C > pyobject, double t)
Interface for a single beam element.
Definition: Component.h:50
BVector Bfield(const Point3D &P) const
Return the field in a point.
Definition: Component.h:202
EVector Efield(const Point3D &P) const
Return the field in a point.
Definition: Component.h:199
void setAlgorithm(algorithm alg)
Set the algorithm used to interpolate from step to the plane.
Definition: OutputPlane.h:340
Vector_t centre_m
Definition: OutputPlane.h:243
virtual ~OutputPlane()
Destructor.
Definition: OutputPlane.cpp:55
bool getFieldsAtPoint(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &Efield, Vector_t &Bfield)
void setVerticalExtent(double z)
Set the vertical extent from the plane centre.
Definition: OutputPlane.h:316
void setCentre(Vector_t centre)
Set the centre of the plane.
Definition: OutputPlane.h:284
double tolerance_m
Definition: OutputPlane.h:248
void operator=(const OutputPlane &)=delete
void RK4Step(const double &tstep, const double &chargeToMass, const double &t, Vector_t &R, Vector_t &P) const
Make an RK4Step.
Definition: OutputPlane.cpp:94
OutputPlane()
Default constructor (initialise to empty.
Definition: OutputPlane.cpp:26
void rk4Test(double tstep, double chargeToMass, double &t, Vector_t &R, Vector_t &P)
void setNormal(Vector_t normal)
Set the normal to the plane.
Definition: OutputPlane.h:275
void getDerivatives(const Vector_t &R, const Vector_t &P, const double &t, const double &chargeToMass, double *yp) const
const NullField & getField() const override
Returns empty field.
Definition: OutputPlane.h:190
int getVerboseLevel() const
Get the horizontal extent from the plane centre.
Definition: OutputPlane.h:348
double distanceToPlane(Vector_t point) const
bool checkOne(const int index, const double tstep, double chargeToMass, double &t, Vector_t &R, Vector_t &P)
Check for plane crossing.
StraightGeometry & getGeometry() override
Returns empty geometry.
Definition: OutputPlane.h:193
NullField nullfield_m
Definition: OutputPlane.h:249
double getVerticalExtent() const
Get the vertical extent from the plane centre.
Definition: OutputPlane.h:312
algorithm getAlgorithm() const
Get the algorithm used to interpolate from step to the plane.
Definition: OutputPlane.h:336
virtual void doInitialise(PartBunchBase< double, 3 > *) override
Initialise peakfinder file.
Definition: OutputPlane.cpp:67
int getRecentre() const
Return the index of the recentring particle.
Definition: OutputPlane.h:328
const StraightGeometry & getGeometry() const override
Returns empty geometry.
Definition: OutputPlane.h:195
Vector_t getCentre() const
Get the centre of the plane.
Definition: OutputPlane.h:280
NullField & getField() override
Returns empty field.
Definition: OutputPlane.h:188
ElementType getType() const override
Get element type std::string.
void setTolerance(double tolerance)
Set the tolerance, used when finding intersection with the plane.
Definition: OutputPlane.h:292
double radialExtent_m
Definition: OutputPlane.h:244
void setRadialExtent(double r)
Set the radial extent from the centre.
Definition: OutputPlane.h:324
bool doPreCheck(PartBunchBase< double, 3 > *bunch) override
Record probe hits when bunch particles pass.
Definition: OutputPlane.h:344
StraightGeometry geom_m
Definition: OutputPlane.h:250
ElementBase * clone() const override
Inheritable copy operation.
Definition: OutputPlane.cpp:58
std::function< bool(const double &, const size_t &, Vector_t &, Vector_t &)> function_t
Definition: OutputPlane.h:259
size_t maxIterations_m
Definition: OutputPlane.h:247
virtual void doGoOffline() override
Hook for goOffline.
Definition: OutputPlane.cpp:90
double getRadialExtent() const
Get the radial extent from the plane centre.
Definition: OutputPlane.h:320
Component * getGlobalFieldMap() const
Get the field map.
Definition: OutputPlane.h:263
void recentre(Vector_t R, Vector_t P)
double getHorizontalExtent() const
Get the horizontal extent from the plane centre.
Definition: OutputPlane.h:304
algorithm algorithm_m
Definition: OutputPlane.h:251
size_t getMaxIterations() const
Get the maximum allowed iteratiosn when finding intersection.
Definition: OutputPlane.h:296
Vector_t normal_m
Definition: OutputPlane.h:242
void setVerboseLevel(int verbose)
Set the verbose level.
Definition: OutputPlane.h:352
double horizontalExtent_m
Definition: OutputPlane.h:246
void setGlobalFieldMap(Component *field)
Set the field map.
Definition: OutputPlane.h:267
void setMaxIterations(size_t max)
Set the maximum allowed iteratiosn when finding intersection.
Definition: OutputPlane.h:300
virtual bool doCheck(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep) override
Record probe hits when bunch particles pass.
double verticalExtent_m
Definition: OutputPlane.h:245
void interpolation(double &t, Vector_t &R, Vector_t &P)
Vector_t getNormal() const
Get the normal to the plane.
Definition: OutputPlane.h:271
Component * field_m
Definition: OutputPlane.h:241
virtual void accept(BeamlineVisitor &) const override
Apply visitor to output plane.
Definition: OutputPlane.cpp:63
void setHorizontalExtent(double width)
Set the horizontal extent from the plane centre.
Definition: OutputPlane.h:308
void setRecentre(int willRecentre)
Set the index of the recentring particle.
Definition: OutputPlane.h:332
std::unique_ptr< Stepper< function_t > > stepper_m
Definition: OutputPlane.h:260
double getTolerance() const
Get the tolerance, used when finding intersection with the plane.
Definition: OutputPlane.h:288
A geometry representing a straight line.
A zero electromagnetic field.
Definition: NullField.h:30