38#include <boost/algorithm/string/case_conv.hpp>
49 fringeField_l(right.fringeField_l),
50 fringeField_r(right.fringeField_r),
51 maxFOrder_m(right.maxFOrder_m),
52 maxXOrder_m(right.maxXOrder_m),
53 transProfile_m(right.transProfile_m),
54 transMaxOrder_m(right.transMaxOrder_m),
55 length_m(right.length_m),
56 entranceAngle_m(right.entranceAngle_m),
57 rotation_m(right.rotation_m),
58 bendAngle_m(right.bendAngle_m),
59 variableRadius_m(right.variableRadius_m),
60 boundingBoxLength_m(right.boundingBoxLength_m),
61 verticalApert_m(right.verticalApert_m),
62 horizontalApert_m(right.horizontalApert_m),
63 scalingName_m(right.scalingName_m),
64 scalingTD_m(right.scalingTD_m) {
91 R_pprime[1] = R_prime[1];
175 if (
n > transMaxOrder) {
179 for (std::size_t i = 1; i <=
n; i++) {
180 for (std::size_t j = 0; j <= transMaxOrder; j++) {
182 temp[j] = temp[j + 1] *
static_cast<double>(j + 1);
188 std::size_t k = transMaxOrder -
n + 1;
191 func = func * x + temp[k];
201 double stepSize = 1
e-3;
206 deriv /= 12 * stepSize;
215 double stepSize = 1
e-3;
220 deriv /= 12 * stepSize;
298 double& ,
double& ) {
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > sin(const Tps< T > &x)
Sine.
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double integrate(const double &a, const double &s0, const double &lambdaleft, const double &lambdaright, const int &n)
Perform Cauchy's integral to find derivative.
constexpr double e
The value of.
ParticleAttrib< Vector_t > P
virtual void visitMultipoleT(const MultipoleT &)=0
Apply the algorithm to an arbitrary multipole.
Interface for a single beam element.
PartBunchBase< double, 3 > * RefPartBunch_m
bool getFlagDeleteOnTransverseExit() const
virtual void setElementLength(double length)
Set design length.
double getNegTanh(double x, int n) const
Returns the value of tanh((x-x0)/lambda) or its derivative.
void setX0(double x0)
Set x0 (flat top length)
double getX0() const
Return x0 (flat top length)
void setLambda(double lambda)
Set lambda (end length)
double getLambda() const
Return lambda (end length)
double getTanh(double x, int n) const
Returns the value of tanh((x+x0)/lambda) or its derivative.
Vector_t toMagnetCoords(const Vector_t &R)
void setRotation(double rot)
Set the angle of rotation of the magnet around its axis To make skew components.
std::size_t getTransMaxOrder() const
Get the maximum order in the given transverse profile.
std::vector< double > transProfile_m
List of transverse profile coefficients.
void setScalingName(const std::string &name)
Vector_t localCartesianToOpalCartesian(const Vector_t &r)
std::size_t maxFOrder_m
Number of terms in z expansion used in calculating field components.
void setBendAngle(double angle, bool variableRadius)
Set the bending angle of the magnet.
std::size_t maxXOrder_m
Highest order of polynomial expansions in x.
double getFringeDeriv(const std::size_t &n, const double &s)
Returns the value of the fringe field n-th derivative at s.
void setElementLength(double length) override
Set the length of the magnet If straight-> Actual length If curved -> Arc length.
endfieldmodel::Tanh fringeField_r
endfieldmodel::Tanh fringeField_l
void setEntranceAngle(double entranceAngle)
Set the entrance angle.
void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Initialise the MultipoleT.
ElementBase * clone() const override
Inheritable copy constructor.
std::string scalingName_m
EMField & getField() override
Return a dummy field value.
void accept(BeamlineVisitor &visitor) const override
Accept a beamline visitor.
double verticalApert_m
Assume rectangular aperture with these dimensions.
void setAperture(const double &vertAp, const double &horizAp)
Set the aperture dimensions This element only supports a rectangular aperture.
void setMaxOrder(size_t orderZ, size_t orderX)
Set the number of terms used in calculation of field components .
double length_m
Magnet parameters.
const std::vector< double > & getTransProfile() const
Get all terms of transverse profile.
double localCartesianRotation()
bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
Calculate the field at some arbitrary position If particle is outside field map true is returned,...
void finalise() override
Finalise the MultipoleT - sets bunch to nullptr.
Vector_t rotateFrame(const Vector_t &R) const
Rotate the frame to account for the rotation and entry angles.
bool insideAperture(const Vector_t &R) const
double getTransDeriv(const std::size_t &n, const double &x) const
Returns the value of the transverse field n-th derivative at x Transverse field is a polynomial in x...
BGeometryBase & getGeometry() override
Return the cell geometry.
bool bends() const override
Return true if dipole component not zero.
void initialiseTimeDepencencies() const
std::shared_ptr< AbstractTimeDependence > scalingTD_m
double getFnDerivS(const std::size_t &n, const double &x, const double &s)
Calculate partial derivative of fn wrt s using a 5-point finite difference formula Error of order ste...
double getFnDerivX(const std::size_t &n, const double &x, const double &s)
Calculate partial derivative of fn wrt x using a 5-point finite difference formula Error of order ste...
void chooseImplementation()
bool insideBoundingBox(const Vector_t &R) const
double boundingBoxLength_m
MultipoleT(const std::string &name)
Constructor.
void setFringeField(const double &s0, const double &lambda_left, const double &lambda_right)
Set fringe field model Tanh model used here .
std::tuple< double, double, double > getFringeField() const
Get the fringe field model.
void setEntryOffset(double offset)
Set the offset of the entry point from the standard position.
void setBoundingBoxLength(double boundingBoxLength)
Set the bounding box size.
void setTransProfile(const std::vector< double > &profile)
Set the the transverse profile.
std::unique_ptr< MultipoleTBase > implementation_
static std::shared_ptr< AbstractTimeDependence > getTimeDependence(std::string name)
Look up the time dependence that has a given name.
Abstract base class for accelerator geometry classes.