OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
ScalingFFAMagnet.h
Go to the documentation of this file.
1 //
2 // Class ScalingFFAMagnet
3 // Defines the abstract interface for a sector FFA magnet
4 // with radially scaling fringe fields.
5 //
6 // Copyright (c) 2017 - 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_ScalingFFAMagnet_H
20 #define ABSBEAMLINE_ScalingFFAMagnet_H
21 
22 #include "AbsBeamline/Component.h"
24 #include "Algorithms/PartBunch.h"
26 #include "Fields/BMultipoleField.h"
27 
28 #include <cmath>
29 
41 class ScalingFFAMagnet: public Component {
42 
43 public:
48  explicit ScalingFFAMagnet(const std::string& name);
49 
52 
54  ScalingFFAMagnet* clone() const override;
55 
65  inline bool apply(const size_t& i, const double& t,
66  Vector_t& E, Vector_t& B) override;
67 
77  inline bool apply(const Vector_t& R, const Vector_t& P, const double& t,
78  Vector_t& E, Vector_t& B) override;
79 
87  bool getFieldValue(const Vector_t& R, Vector_t& B) const;
88 
96  bool getFieldValueCylindrical(const Vector_t& R, Vector_t& B) const;
97 
104  void initialise(PartBunchBase<double, 3>* bunch, double& startField, double& endField) override;
105 
111  void initialise();
112 
114  void finalise() override;
115 
117  inline bool bends() const override;
118 
120  void getDimensions(double& /*zBegin*/, double& /*zEnd*/) const override {}
121 
123  BGeometryBase& getGeometry() override;
124 
126  const BGeometryBase& getGeometry() const override;
127 
129  EMField& getField() override;
130 
132  const EMField& getField() const override;
133 
135  void accept(BeamlineVisitor& visitor) const override;
136 
138  double getTanDelta() const {return tanDelta_m;}
139 
141  void setTanDelta(double tanDelta) {tanDelta_m = tanDelta;}
142 
144  double getFieldIndex() const {return k_m;}
145 
147  void setFieldIndex(double k) {k_m = k;}
148 
150  double getDipoleConstant() const {return Bz_m;}
151 
153  void setDipoleConstant(double Bz) {Bz_m = Bz;}
154 
156  double getR0() const {return r0_m;}
157 
159  void setR0(double r0) {r0_m = r0; r0Sign_m = r0_m / std::abs(r0_m);}
160 
162  Vector_t getCentre() const {return centre_m;}
163 
165  void setCentre(Vector_t centre) {centre_m = centre;}
166 
173 
180 
183  size_t getMaxOrder() const {return maxOrder_m;}
184 
187  void setMaxOrder(size_t maxOrder) {maxOrder_m = maxOrder;}
188 
191  double getPhiStart() const {return phiStart_m;}
192 
195  void setPhiStart(double phiStart) {phiStart_m = phiStart;}
196 
199  double getPhiEnd() const {return phiEnd_m;}
200 
203  void setPhiEnd(double phiEnd) {phiEnd_m = phiEnd;}
204 
207  double getRMin() const {return rMin_m;}
208 
211  void setRMin(double rMin) {rMin_m = rMin;}
212 
215  double getRMax() const {return rMax_m;}
216 
219  void setRMax(double rMax) {rMax_m = rMax;}
220 
223  double getAzimuthalExtent() const {return azimuthalExtent_m;}
224 
227  void setAzimuthalExtent(double azimuthalExtent) {azimuthalExtent_m = azimuthalExtent;}
228 
231  double getVerticalExtent() const {return verticalExtent_m;}
232 
235  void setVerticalExtent(double verticalExtent) {verticalExtent_m = verticalExtent;}
236 
238  std::vector<std::vector<double> > getDfCoefficients() {return dfCoefficients_m;}
239 
248  void setupEndField();
249 
255  void setEndFieldName(std::string name) {endFieldName_m = name;}
256 
258  std::string getEndFieldName() const {return endFieldName_m;}
259 
260 
261 private:
268 
270  ScalingFFAMagnet(const ScalingFFAMagnet& right);
271 
275 
276  size_t maxOrder_m = 0; // maximum order used in the calculation
277  double tanDelta_m = 0.; // tan(spiral angle)
278  double k_m = 0.; // field index
279  double Bz_m = 0.; // nominal field on the radius
280  double r0_m = 0.; // radius; negative for clockwise geometry, else positive
281  double rMin_m = 0.; // minimum radius
282  double rMax_m = 0.; // maximum radius
283  double phiStart_m = 0.; // offsets this element
284  double phiEnd_m = 0.; // used for placement of next element
285  double azimuthalExtent_m = 0.; // maximum distance used for field calculation
286  double verticalExtent_m = 0.; // maximum allowed distance from the midplane
287  double r0Sign_m = 0.0; // -1 for clockwise geometry, else +1
288  Vector_t centre_m; // nominal ring centre
290  std::string endFieldName_m = "";
291  const double fp_tolerance = 1e-18;
292  std::vector<std::vector<double> > dfCoefficients_m;
293 };
294 
295 bool ScalingFFAMagnet::apply(const Vector_t& R, const Vector_t& /*P*/,
296  const double& /*t*/, Vector_t& /*E*/, Vector_t& B) {
297  return getFieldValue(R, B);
298 }
299 
300 bool ScalingFFAMagnet::apply(const size_t& i, const double& t,
301  Vector_t& E, Vector_t& B) {
302  return apply(RefPartBunch_m->R[i], RefPartBunch_m->P[i], t, E, B);
303 }
304 
305 #endif
BGeometryBase & getGeometry() override
bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
size_t getMaxOrder() const
double getTanDelta() const
void setPhiStart(double phiStart)
double getRMax() const
void setTanDelta(double tanDelta)
bool bends() const override
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
void setEndFieldName(std::string name)
ParticleAttrib< Vector_t > P
double getDipoleConstant() const
void setDipoleConstant(double Bz)
BMultipoleField dummy
void finalise() override
void setR0(double r0)
A simple arc in the XZ plane.
double getVerticalExtent() const
Abstract base class for accelerator geometry classes.
Definition: Geometry.h:43
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
std::string endFieldName_m
Vector_t getCentre() const
ScalingFFAMagnet * clone() const override
void setRMax(double rMax)
ScalingFFAMagnet(const std::string &name)
EMField & getField() override
void setEndField(endfieldmodel::EndFieldModel *endField)
PlanarArcGeometry planarArcGeometry_m
bool getFieldValue(const Vector_t &R, Vector_t &B) const
double getPhiStart() const
const double fp_tolerance
bool getFieldValueCylindrical(const Vector_t &R, Vector_t &B) const
std::vector< std::vector< double > > getDfCoefficients()
double getAzimuthalExtent() const
void setMaxOrder(size_t maxOrder)
ScalingFFAMagnet & operator=(const ScalingFFAMagnet &rhs)
endfieldmodel::EndFieldModel * getEndField() const
void getDimensions(double &, double &) const override
void setRMin(double rMin)
void setFieldIndex(double k)
void accept(BeamlineVisitor &visitor) const override
double getR0() const
void setCentre(Vector_t centre)
const std::string name
ParticlePos_t & R
double getRMin() const
std::vector< std::vector< double > > dfCoefficients_m
double getPhiEnd() const
std::string getEndFieldName() const
constexpr double e
The value of .
Definition: Physics.h:39
endfieldmodel::EndFieldModel * endField_m
void setVerticalExtent(double verticalExtent)
Interface for a single beam element.
Definition: Component.h:50
void setAzimuthalExtent(double azimuthalExtent)
void setPhiEnd(double phiEnd)
double getFieldIndex() const
The magnetic field of a multipole.