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
52
54
55public:
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
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
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
335
339
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)
const std::string name
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
Component(const std::string &name)
Constructor with given name.
Definition Component.cpp:53
EVector Efield(const Point3D &P) const
Return the field in a point.
Definition Component.h:199
void setAlgorithm(algorithm alg)
Vector_t centre_m
virtual ~OutputPlane()
bool getFieldsAtPoint(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &Efield, Vector_t &Bfield)
void setVerticalExtent(double z)
void setCentre(Vector_t centre)
double tolerance_m
void operator=(const OutputPlane &)=delete
void RK4Step(const double &tstep, const double &chargeToMass, const double &t, Vector_t &R, Vector_t &P) const
void rk4Test(double tstep, double chargeToMass, double &t, Vector_t &R, Vector_t &P)
OutputPlane(const std::string &name)
void setNormal(Vector_t normal)
void getDerivatives(const Vector_t &R, const Vector_t &P, const double &t, const double &chargeToMass, double *yp) const
const NullField & getField() const override
int getVerboseLevel() const
double distanceToPlane(Vector_t point) const
bool checkOne(const int index, const double tstep, double chargeToMass, double &t, Vector_t &R, Vector_t &P)
StraightGeometry & getGeometry() override
NullField nullfield_m
double getVerticalExtent() const
algorithm getAlgorithm() const
virtual void doInitialise(PartBunchBase< double, 3 > *) override
Initialise peakfinder file.
int getRecentre() const
const StraightGeometry & getGeometry() const override
Vector_t getCentre() const
NullField & getField() override
ElementType getType() const override
Get element type std::string.
void setTolerance(double tolerance)
double radialExtent_m
void setRadialExtent(double r)
bool doPreCheck(PartBunchBase< double, 3 > *bunch) override
Record probe hits when bunch particles pass.
StraightGeometry geom_m
ElementBase * clone() const override
std::function< bool(const double &, const size_t &, Vector_t &, Vector_t &)> function_t
size_t maxIterations_m
virtual void doGoOffline() override
Hook for goOffline.
double getRadialExtent() const
Component * getGlobalFieldMap() const
void recentre(Vector_t R, Vector_t P)
double getHorizontalExtent() const
algorithm algorithm_m
size_t getMaxIterations() const
Vector_t normal_m
void setVerboseLevel(int verbose)
double horizontalExtent_m
void setGlobalFieldMap(Component *field)
void setMaxIterations(size_t max)
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
Vector_t getNormal() const
Component * field_m
virtual void accept(BeamlineVisitor &) const override
void setHorizontalExtent(double width)
void setRecentre(int willRecentre)
std::unique_ptr< Stepper< function_t > > stepper_m
double getTolerance() const
PluginElement(const std::string &name)
Constructor with given name.
A geometry representing a straight line.
A zero electromagnetic field.
Definition NullField.h:30
Vektor< double, 3 > Vector_t