OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
26#include "Physics/Units.h"
27
28namespace endfieldmodel {
29 class EndFieldModel;
30}
31
39
40public:
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
164
166 inline void setNegativeVerticalExtent(double negativeExtent);
167
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
198private:
200
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
220 zNegExtent_m = negativeExtent;
221}
222
224 zPosExtent_m = positiveExtent;
225}
226
227bool 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
232bool 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
237std::vector<std::vector<double> > VerticalFFAMagnet::getDfCoefficients() const {
238 return dfCoefficients_m;
239}
240
241#endif
const std::string name
constexpr double T2kG
Definition: Units.h:56
constexpr double kG2T
Definition: Units.h:59
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
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)
bool getFieldValue(const Vector_t &R, Vector_t &B) const
Calculate the field at some arbitrary position in cartesian coordinates.
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?)
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.
void getDimensions(double &, double &) const
Not implemented.
double getWidth() const
Get the full width of the bounding box (centred on magnet centre)
bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
Calculate the field at the position of the ith particle.
void setEndField(endfieldmodel::EndFieldModel *endField)
Set the fringe field.
void setPositiveVerticalExtent(double positiveExtent)
set the maximum extent above z = 0
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