OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 
26 class Component;
27 
53 class OutputPlane: public PluginElement {
54 
55 public:
57 
59  explicit OutputPlane(const std::string& name);
60 
62  OutputPlane();
63 
65  OutputPlane(const OutputPlane&);
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 
216 private:
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 
292 void 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 
316 void OutputPlane::setVerticalExtent(double width) {
317  verticalExtent_m = width;
318 }
319 
321  return radialExtent_m;
322 }
323 
324 void OutputPlane::setRadialExtent(double radius) {
325  radialExtent_m = radius;
326 }
327 
329  return recentre_m;
330 }
331 
332 void 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 
352 void OutputPlane::setVerboseLevel(int verbose) {
353  verbose_m = verbose;
354 }
355 
356 
357 #endif // CLASSIC_OutputPlane_HH
void setGlobalFieldMap(Component *field)
Definition: OutputPlane.h:267
void setHorizontalExtent(double width)
Definition: OutputPlane.h:308
Component * getGlobalFieldMap() const
Definition: OutputPlane.h:263
algorithm algorithm_m
Definition: OutputPlane.h:251
void rk4Test(double tstep, double chargeToMass, double &t, Vector_t &R, Vector_t &P)
BVector Bfield(const Point3D &P) const
Return the field in a point.
Definition: Component.h:202
bool doPreCheck(PartBunchBase< double, 3 > *bunch) override
Record probe hits when bunch particles pass.
Definition: OutputPlane.h:344
void setVerticalExtent(double z)
Definition: OutputPlane.h:316
A geometry representing a straight line.
void setCentre(Vector_t centre)
Definition: OutputPlane.h:284
int getRecentre() const
Definition: OutputPlane.h:328
void operator=(const OutputPlane &)=delete
size_t getMaxIterations() const
Definition: OutputPlane.h:296
ElementBase * clone() const override
Definition: OutputPlane.cpp:58
Definition: TSVMeta.h:24
Vector_t getCentre() const
Definition: OutputPlane.h:280
bool checkOne(const int index, const double tstep, double chargeToMass, double &t, Vector_t &R, Vector_t &P)
virtual void doGoOffline() override
Hook for goOffline.
Definition: OutputPlane.cpp:90
Vector_t centre_m
Definition: OutputPlane.h:243
const NullField & getField() const override
Definition: OutputPlane.h:190
Vector_t getNormal() const
Definition: OutputPlane.h:271
virtual void accept(BeamlineVisitor &) const override
Definition: OutputPlane.cpp:63
double horizontalExtent_m
Definition: OutputPlane.h:246
double getVerticalExtent() const
Definition: OutputPlane.h:312
int getVerboseLevel() const
Definition: OutputPlane.h:348
algorithm getAlgorithm() const
Definition: OutputPlane.h:336
double tolerance_m
Definition: OutputPlane.h:248
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
double getRadialExtent() const
Definition: OutputPlane.h:320
EVector Efield(const Point3D &P) const
Return the field in a point.
Definition: Component.h:199
void setAlgorithm(algorithm alg)
Definition: OutputPlane.h:340
T euclidean_norm(const Vector< T > &)
Euclidean norm.
Definition: Vector.h:243
std::unique_ptr< Stepper< function_t > > stepper_m
Definition: OutputPlane.h:260
std::function< bool(const double &, const size_t &, Vector_t &, Vector_t &)> function_t
Definition: OutputPlane.h:259
void setTolerance(double tolerance)
Definition: OutputPlane.h:292
void recentre(Vector_t R, Vector_t P)
double verticalExtent_m
Definition: OutputPlane.h:245
ElementType
Definition: ElementBase.h:88
double function(PyOpalObjectNS::PyOpalObject< C > pyobject, double t)
void setRadialExtent(double r)
Definition: OutputPlane.h:324
void setMaxIterations(size_t max)
Definition: OutputPlane.h:300
double getHorizontalExtent() const
Definition: OutputPlane.h:304
const StraightGeometry & getGeometry() const override
Definition: OutputPlane.h:195
virtual bool doCheck(PartBunchBase< double, 3 > *bunch, const int turnnumber, const double t, const double tstep) override
Record probe hits when bunch particles pass.
void getDerivatives(const Vector_t &R, const Vector_t &P, const double &t, const double &chargeToMass, double *yp) const
double distanceToPlane(Vector_t point) const
const std::string name
size_t maxIterations_m
Definition: OutputPlane.h:247
Vector_t normal_m
Definition: OutputPlane.h:242
ElementType getType() const override
Get element type std::string.
void RK4Step(const double &tstep, const double &chargeToMass, const double &t, Vector_t &R, Vector_t &P) const
Definition: OutputPlane.cpp:94
void setRecentre(int willRecentre)
Definition: OutputPlane.h:332
bool getFieldsAtPoint(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &Efield, Vector_t &Bfield)
void setVerboseLevel(int verbose)
Definition: OutputPlane.h:352
StraightGeometry & getGeometry() override
Definition: OutputPlane.h:193
constexpr double e
The value of .
Definition: Physics.h:39
A zero electromagnetic field.
Definition: NullField.h:30
virtual void doInitialise(PartBunchBase< double, 3 > *) override
Initialise peakfinder file.
Definition: OutputPlane.cpp:67
virtual ~OutputPlane()
Definition: OutputPlane.cpp:55
Interface for a single beam element.
Definition: Component.h:50
NullField & getField() override
Definition: OutputPlane.h:188
StraightGeometry geom_m
Definition: OutputPlane.h:250
double getTolerance() const
Definition: OutputPlane.h:288
void interpolation(double &t, Vector_t &R, Vector_t &P)
NullField nullfield_m
Definition: OutputPlane.h:249
void setNormal(Vector_t normal)
Definition: OutputPlane.h:275
Component * field_m
Definition: OutputPlane.h:241
double radialExtent_m
Definition: OutputPlane.h:244