OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
27
28#include <cmath>
29
42
43public:
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
256
258 std::string getEndFieldName() const {return endFieldName_m;}
259
260
261private:
268
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
295bool 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
300bool 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
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
const std::string name
constexpr double e
The value of.
Definition: Physics.h:39
ParticlePos_t & R
ParticleAttrib< Vector_t > P
Interface for a single beam element.
Definition: Component.h:50
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
Sector bending magnet with an FFA-style field index and spiral end shape.
bool getFieldValue(const Vector_t &R, Vector_t &B) const
Calculate the field at some arbitrary position in cartesian coordinates.
double getVerticalExtent() const
Get the maximum vertical displacement from the midplane.
std::string endFieldName_m
void setupEndField()
setupEndField does some end field and geometry set-up
bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Calculate the field at the position of the ith particle.
void accept(BeamlineVisitor &visitor) const override
Accept a beamline visitor.
void setAzimuthalExtent(double azimuthalExtent)
Set the maximum azimuthal displacement from \psi=0.
void setRMin(double rMin)
Set the maximum radius.
void finalise() override
Finalise the ScalingFFAMagnet - sets bunch to nullptr.
void setCentre(Vector_t centre)
Set the centre of the sector.
void setR0(double r0)
Set the radius constant R_0.
endfieldmodel::EndFieldModel * endField_m
double getDipoleConstant() const
Get the dipole constant B_0.
void setVerticalExtent(double verticalExtent)
Set the maximum vertical displacement from the midplane.
void initialise()
Initialise the ScalingFFAMagnet.
std::vector< std::vector< double > > getDfCoefficients()
Return the calculated df coefficients.
ScalingFFAMagnet * clone() const override
Inheritable copy constructor.
ScalingFFAMagnet(const std::string &name)
Construct a new ScalingFFAMagnet.
void setTanDelta(double tanDelta)
Set tan delta - delta is the spiral angle.
double getAzimuthalExtent() const
Get the maximum azimuthal displacement from \psi=0.
std::string getEndFieldName() const
Return the end field name.
void setDipoleConstant(double Bz)
Set the dipole constant B_0.
void getDimensions(double &, double &) const override
Not implemented.
bool getFieldValueCylindrical(const Vector_t &R, Vector_t &B) const
Calculate the field at some arbitrary position in cylindrical coordinates.
void calculateDfCoefficients()
Calculate the df coefficients, ready for field generation.
void setPhiStart(double phiStart)
Set the offset of the magnet centre from the start.
const double fp_tolerance
double getRMin() const
Get the maximum radius.
double getPhiEnd() const
Get the offset of the magnet end from the start.
EMField & getField() override
Return a dummy (0.) field value (what is this for?)
size_t getMaxOrder() const
Get the maximum power of y modelled in the off-midplane expansion;.
~ScalingFFAMagnet()
Destructor - deletes map.
Vector_t getCentre() const
Get the centre of the sector.
void setEndField(endfieldmodel::EndFieldModel *endField)
Set the fringe field.
void setMaxOrder(size_t maxOrder)
Set the maximum power of y modelled in the off-midplane expansion;.
BMultipoleField dummy
double getFieldIndex() const
Get the field index k.
void setFieldIndex(double k)
Set the field index k.
void setRMax(double rMax)
Set the maximum radius.
void setEndFieldName(std::string name)
Set the end field name.
void setPhiEnd(double phiEnd)
Set the offset of the magnet end from the start.
endfieldmodel::EndFieldModel * getEndField() const
Get the fringe field.
double getR0() const
Get the radius constant R_0.
double getRMax() const
Get the maximum radius.
std::vector< std::vector< double > > dfCoefficients_m
double getTanDelta() const
Get tan delta - delta is the spiral angle.
double getPhiStart() const
Get the offset of the magnet centre from the start.
BGeometryBase & getGeometry() override
Return the cell geometry.
bool bends() const override
Return true - ScalingFFAMagnet always bends the reference particle.
ScalingFFAMagnet & operator=(const ScalingFFAMagnet &rhs)
PlanarArcGeometry planarArcGeometry_m
Abstract base class for accelerator geometry classes.
Definition: Geometry.h:43
A simple arc in the XZ plane.
The magnetic field of a multipole.
Abstract base class for electromagnetic fields.
Definition: EMField.h:188