OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
VerticalFFAMagnet.h
Go to the documentation of this file.
1 //
2 // Class VerticalFFAMagnet
3 // Defines the abstract interface for a vertical FFA magnet
4 // with vertical scaling fringe fields.
5 //
6 // Copyright (c) 2019 - 2023, Chris Rogers, STFC Rutherford Appleton Laboratory, Didcot, UK
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 ABSBEAMLINE_VerticalFFAMagnet_H
20 #define ABSBEAMLINE_VerticalFFAMagnet_H
21 
22 #include "AbsBeamline/Component.h"
23 #include "Algorithms/PartBunch.h"
25 #include "Fields/BMultipoleField.h"
26 #include "Physics/Units.h"
27 
28 namespace endfieldmodel {
29  class EndFieldModel;
30 }
31 
39 
40 public:
45  explicit VerticalFFAMagnet(const std::string& name);
46 
49 
51  ElementBase* clone() const;
52 
62  inline bool apply(const size_t& i, const double& t, Vector_t& E, Vector_t& B);
63 
73  inline bool apply(const Vector_t& R, const Vector_t& P,
74  const double& t,Vector_t& E, Vector_t& B);
75 
83  bool getFieldValue(const Vector_t& R, Vector_t& B) const;
84 
91  void initialise(PartBunchBase<double, 3>* bunch, double& startField, double& endField);
92 
98  void initialise();
99 
101  void finalise();
102 
108  inline bool bends() const {return false;}
109 
111  void getDimensions(double& /*zBegin*/, double& /*zEnd*/) const {}
112 
115 
117  const BGeometryBase& getGeometry() const;
118 
120  EMField& getField();
121 
123  const EMField& getField() const;
124 
126  void accept(BeamlineVisitor& visitor) const;
127 
134 
141 
144  size_t getMaxOrder() const {return maxOrder_m;}
145 
148  void setMaxOrder(size_t maxOrder);
149 
151  double getB0() const {return Bz_m * Units::kG2T;}
152 
154  void setB0(double Bz) {Bz_m = Bz * Units::T2kG;}
155 
157  double getFieldIndex() const {return k_m;} // units are [m^{-1}]
158 
160  void setFieldIndex(double index) {k_m = index;}
161 
163  double getNegativeVerticalExtent() const {return zNegExtent_m;}
164 
166  inline void setNegativeVerticalExtent(double negativeExtent);
167 
169  double getPositiveVerticalExtent() const {return zPosExtent_m;}
170 
172  inline void setPositiveVerticalExtent(double positiveExtent);
173 
175  double getBBLength() const {return bbLength_m;}
176 
178  void setBBLength(double bbLength) {bbLength_m = bbLength;}
179 
181  double getWidth() const {return halfWidth_m * 2.;}
182 
184  void setWidth(double width) {halfWidth_m = width / 2;}
185 
196  inline std::vector<std::vector<double> > getDfCoefficients() const;
197 
198 private:
200 
202  VerticalFFAMagnet(const VerticalFFAMagnet& right);
203 
207 
208  size_t maxOrder_m = 0;
209  double k_m = 0.;
210  double Bz_m = 0.;
211  double zNegExtent_m = 0.; // extent downwards from the midplane
212  double zPosExtent_m = 0.; // extent upwards from the midplane
213  double halfWidth_m = 0.; // extent in either +x or -x
214  double bbLength_m = 0.;
215  std::unique_ptr<endfieldmodel::EndFieldModel> endField_m;
216  std::vector<std::vector<double> > dfCoefficients_m;
217 };
218 
219 void VerticalFFAMagnet::setNegativeVerticalExtent(double negativeExtent) {
220  zNegExtent_m = negativeExtent;
221 }
222 
223 void VerticalFFAMagnet::setPositiveVerticalExtent(double positiveExtent) {
224  zPosExtent_m = positiveExtent;
225 }
226 
227 bool VerticalFFAMagnet::apply(const size_t& i, const double& t,
228  Vector_t& E, Vector_t& B) {
229  return apply(RefPartBunch_m->R[i], RefPartBunch_m->P[i], t, E, B);
230 }
231 
232 bool VerticalFFAMagnet::apply(const Vector_t& R, const Vector_t& /*P*/,
233  const double& , Vector_t& /*E*/, Vector_t& B) {
234  return getFieldValue(R, B);
235 }
236 
237 std::vector<std::vector<double> > VerticalFFAMagnet::getDfCoefficients() const {
238  return dfCoefficients_m;
239 }
240 
241 #endif
void setPositiveVerticalExtent(double positiveExtent)
ElementBase * clone() const
A geometry representing a straight line.
void setFieldIndex(double index)
double getPositiveVerticalExtent() const
VerticalFFAMagnet & operator=(const VerticalFFAMagnet &rhs)
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
void setEndField(endfieldmodel::EndFieldModel *endField)
ParticleAttrib< Vector_t > P
void accept(BeamlineVisitor &visitor) const
VerticalFFAMagnet(const std::string &name)
StraightGeometry straightGeometry_m
Abstract base class for accelerator geometry classes.
Definition: Geometry.h:43
constexpr double T2kG
Definition: Units.h:56
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
void setB0(double Bz)
endfieldmodel::EndFieldModel * getEndField() const
double getNegativeVerticalExtent() const
double getB0() const
std::vector< std::vector< double > > dfCoefficients_m
std::vector< std::vector< double > > getDfCoefficients() const
void setWidth(double width)
double getBBLength() const
double getFieldIndex() const
bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
void setBBLength(double bbLength)
const std::string name
ParticlePos_t & R
BGeometryBase & getGeometry()
BMultipoleField dummy
std::unique_ptr< endfieldmodel::EndFieldModel > endField_m
void setNegativeVerticalExtent(double negativeExtent)
void getDimensions(double &, double &) const
Interface for a single beam element.
Definition: Component.h:50
void setMaxOrder(size_t maxOrder)
bool getFieldValue(const Vector_t &R, Vector_t &B) const
constexpr double kG2T
Definition: Units.h:59
The magnetic field of a multipole.
size_t getMaxOrder() const
double getWidth() const