OPALX (Object Oriented Parallel Accelerator Library for Exascale) MINIorX
OPALX
VerticalFFAMagnet.h
Go to the documentation of this file.
1//
2// Header file for VerticalFFAMagnet Component
3//
4// Copyright (c) 2019 Chris Rogers
5// All rights reserved.
6//
7// OPAL is licensed under GNU GPL version 3.
8//
9
13#include "PartBunch/PartBunch.h"
14
15#ifndef ABSBEAMLINE_VerticalFFAMagnet_H
16#define ABSBEAMLINE_VerticalFFAMagnet_H
17
18namespace endfieldmodel {
19 class EndFieldModel;
20}
21
29public:
34 explicit VerticalFFAMagnet(const std::string& name);
35
38
40 ElementBase* clone() const;
41
51 inline bool apply(
52 const size_t& i, const double& t, Vector_t<double, 3>& E, Vector_t<double, 3>& B);
53
63 inline bool apply(
64 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& t,
66
75
82 void initialise(PartBunch_t* bunch, double& startField, double& endField);
83
89 void initialise();
90
92 void finalise();
93
99 inline bool bends() const {
100 return false;
101 }
102
104 void getDimensions(double& /*zBegin*/, double& /*zEnd*/) const {
105 }
106
109
111 const BGeometryBase& getGeometry() const;
112
114 EMField& getField();
115
117 const EMField& getField() const;
118
120 void accept(BeamlineVisitor& visitor) const;
121
128 return endField_m.get();
129 }
130
137
140 size_t getMaxOrder() const {
141 return maxOrder_m;
142 }
143
146 void setMaxOrder(size_t maxOrder);
147
149 double getB0() const {
150 return Bz_m / Tesla;
151 }
152
154 void setB0(double Bz) {
155 Bz_m = Bz * Tesla;
156 }
157
159 double getFieldIndex() const {
160 return k_m * mm;
161 } // units are [m^{-1}]
162
164 void setFieldIndex(double index) {
165 k_m = index / mm;
166 }
167
170 return zNegExtent_m / mm;
171 }
172
174 inline void setNegativeVerticalExtent(double negativeExtent);
175
178 return zPosExtent_m / mm;
179 }
180
182 inline void setPositiveVerticalExtent(double positiveExtent);
183
185 double getBBLength() const {
186 return bbLength_m / mm;
187 }
188
190 void setBBLength(double bbLength) {
191 bbLength_m = bbLength * mm;
192 }
193
195 double getWidth() const {
196 return halfWidth_m / mm * 2.;
197 }
198
200 void setWidth(double width) {
201 halfWidth_m = width / 2 * mm;
202 }
203
214 inline std::vector<std::vector<double> > getDfCoefficients() const;
215
216private:
218
221
225
226 size_t maxOrder_m = 0;
227 double k_m = 0.;
228 double Bz_m = 0.;
229 double zNegExtent_m = 0.; // extent downwards from the midplane
230 double zPosExtent_m = 0.; // extent upwards from the midplane
231 double halfWidth_m = 0.; // extent in either +x or -x
232 double bbLength_m = 0.;
233 std::unique_ptr<endfieldmodel::EndFieldModel> endField_m;
234 std::vector<std::vector<double> > dfCoefficients_m;
235
236 const double mm = 1000.;
237 const double Tesla = 10.;
238};
239
241 zNegExtent_m = negativeExtent * mm;
242}
243
245 zPosExtent_m = positiveExtent * mm;
246}
247
249 const size_t& i, const double& t, Vector_t<double, 3>& E, Vector_t<double, 3>& B) {
250 std::shared_ptr<ParticleContainer_t> pc = RefPartBunch_m->getParticleContainer();
251 auto Rview = pc->R.getView();
252 auto Pview = pc->P.getView();
253 const Vector_t<double, 3> R = Rview(i);
254 const Vector_t<double, 3> P = Pview(i);
255 return apply(R, P, t, E, B);
256}
257
259 const Vector_t<double, 3>& R, const Vector_t<double, 3>& /*P*/, const double&,
261 return getFieldValue(R, B);
262}
263
264std::vector<std::vector<double> > VerticalFFAMagnet::getDfCoefficients() const {
265 return dfCoefficients_m;
266}
267
268#endif
Interface for a single beam element.
Definition: Component.h:50
PartBunch_t * RefPartBunch_m
Definition: Component.h:185
Bending magnet with an exponential dependence on field in the vertical plane.
void setBBLength(double bbLength)
Set the length of the bounding box (centred on magnet centre)
void finalise()
Finalise the VerticalFFAMagnet - sets bunch to nullptr.
ElementBase * clone() const
Inheritable copy constructor.
bool bends() const
Return false - VerticalFFAMagnet is a straight magnet.
endfieldmodel::EndFieldModel * getEndField() const
Get the fringe field.
void accept(BeamlineVisitor &visitor) const
Accept a beamline visitor.
VerticalFFAMagnet & operator=(const VerticalFFAMagnet &rhs)
void setWidth(double width)
Set the full width of the bounding box (centred on magnet centre)
void initialise()
Initialise the VerticalFFAMagnet.
double getFieldIndex() const
Get the field index.
size_t getMaxOrder() const
Get the maximum power of x used in the off-midplane expansion;.
std::vector< std::vector< double > > getDfCoefficients() const
Get the coefficients used for the field expansion.
std::unique_ptr< endfieldmodel::EndFieldModel > endField_m
BGeometryBase & getGeometry()
Return the cell geometry.
BMultipoleField dummy
void setMaxOrder(size_t maxOrder)
Set the maximum power of x used in the off-midplane expansion;.
std::vector< std::vector< double > > dfCoefficients_m
double getPositiveVerticalExtent() const
Get the maximum extent above z = 0.
double getNegativeVerticalExtent() const
Get the maximum extent below z = 0.
StraightGeometry straightGeometry_m
EMField & getField()
Return a dummy (0.) field value (what is this for?)
bool apply(const size_t &i, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B)
Calculate the field at the position of the ith particle.
void setB0(double Bz)
Set the centre field at z=0.
double getBBLength() const
Get the length of the bounding box (centred on magnet centre)
double getB0() const
Get the centre field at z=0.
VerticalFFAMagnet(const std::string &name)
Construct a new VerticalFFAMagnet.
void setNegativeVerticalExtent(double negativeExtent)
Set the maximum extent below z = 0.
void setFieldIndex(double index)
Set the field index.
~VerticalFFAMagnet()
Destructor - deletes the field.
bool getFieldValue(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &B) const
Calculate the field at some arbitrary position in cartesian coordinates.
void getDimensions(double &, double &) const
Not implemented.
double getWidth() const
Get the full width of the bounding box (centred on magnet centre)
void setEndField(endfieldmodel::EndFieldModel *endField)
Set the fringe field.
void setPositiveVerticalExtent(double positiveExtent)
set the maximum extent above z = 0
std::shared_ptr< ParticleContainer_t > getParticleContainer()
Definition: PartBunch.h:221
Abstract base class for accelerator geometry classes.
Definition: Geometry.h:43
A geometry representing a straight line.
The magnetic field of a multipole.
Abstract base class for electromagnetic fields.
Definition: EMField.h:188