OPALX (Object Oriented Parallel Accelerator Library for Exascale) MINIorX
OPALX
MultipoleT.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, Titus Dascalu
3 * Copyright (c) 2018, Martin Duy Tat
4 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. Neither the name of STFC nor the names of its contributors may be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef CLASSIC_MULTIPOLET_H
30#define CLASSIC_MULTIPOLET_H
31
80//
81#include <vector>
86#include "gsl/gsl_sf.h"
87
88class MultipoleT : public Component {
89public:
93 explicit MultipoleT(const std::string& name);
95 MultipoleT(const MultipoleT& right);
99 ElementBase* clone() const override;
101 EMField& getField() override;
103 const EMField& getField() const override;
105 void getDimensions(double& zBegin, double& zEnd) const override;
115 bool apply(
116 const Vector_t<double, 3>& R, const Vector_t<double, 3>& P, const double& t,
127 bool apply(
128 const size_t& i, const double& t, Vector_t<double, 3>& E, Vector_t<double, 3>& B) override;
134 void initialise(PartBunch_t*, double& startField, double& endField) override;
136 void initialise();
137
139 void finalise() override;
141 bool bends() const override;
143 PlanarArcGeometry& getGeometry() override;
145 const PlanarArcGeometry& getGeometry() const override;
147 void accept(BeamlineVisitor& visitor) const override;
149 double getDipoleConstant() const;
151 void setDipoleConstant(double B0);
153 std::size_t getMaxOrder() const;
158 void setMaxOrder(std::size_t maxOrder);
160 std::size_t getMaxXOrder() const;
164 void setMaxXOrder(std::size_t maxXOrder);
166 std::size_t getTransMaxOrder() const;
170 void setTransMaxOrder(std::size_t transMaxOrder);
176 void setTransProfile(std::size_t n, double Bn);
180 double getTransProfile(int n) const;
182 std::vector<double> getTransProfile() const;
191 bool setFringeField(double s0, double lambda_left, double lambda_right);
195 std::vector<double> getFringeLength() const;
197 void setBendAngle(double angle);
199 double getBendAngle() const;
203 void setEntranceAngle(double entranceAngle);
205 double getEntranceAngle() const;
209 double getBendRadius() const;
214 void setLength(double length);
216 double getLength() const;
218 double getChordLength() const;
224 void setAperture(double vertAp, double horizAp);
228 std::vector<double> getAperture() const;
233 void setRotation(double rot);
235 double getRotation() const;
237 void setVarRadius();
239 bool getVarRadius() const;
241 double getBoundingBoxLength() const;
245 void setBoundingBoxLength(const double& boundingBoxLength);
246
247private:
249 // End fields
255 std::size_t maxOrder_m = 0;
257 std::size_t maxOrderX_m = 0;
259 std::vector<polynomial::RecursionRelationTwo> recursion_VarRadius_m;
260 std::vector<polynomial::RecursionRelation> recursion_ConstRadius_m;
262 std::size_t transMaxOrder_m = 0;
264 std::vector<double> transProfile_m;
281 double length_m;
282 double angle_m;
291 double getBx(const Vector_t<double, 3>& R);
292 double getBz(const Vector_t<double, 3>& R);
293 double getBs(const Vector_t<double, 3>& R);
303 double getFringeDeriv(int n, double s);
308 double getTransDeriv(std::size_t n, double x);
312 bool insideAperture(const Vector_t<double, 3>& R);
322 double getRadius(double s);
327 double getScaleFactor(double x, double s);
335 double getFnDerivX(std::size_t n, double x, double s);
343 double getFnDerivS(std::size_t n, double x, double s);
350 double getFn(std::size_t n, double x, double s);
351};
352
354 variableRadius_m = true;
355}
356inline bool MultipoleT::getVarRadius() const {
357 return variableRadius_m;
358}
359inline void MultipoleT::setEntranceAngle(double entranceAngle) {
360 entranceAngle_m = entranceAngle;
361}
362inline double MultipoleT::getEntranceAngle() const {
363 return entranceAngle_m;
364}
365inline double MultipoleT::getTransProfile(int n) const {
366 return transProfile_m[n];
367}
368inline std::vector<double> MultipoleT::getTransProfile() const {
369 return transProfile_m;
370}
371inline double MultipoleT::getDipoleConstant() const {
372 return transProfile_m[0];
373}
374inline std::size_t MultipoleT::getMaxOrder() const {
375 return maxOrder_m;
376}
377
378inline std::size_t MultipoleT::getMaxXOrder() const {
379 return maxOrderX_m;
380}
381
382inline void MultipoleT::setMaxXOrder(std::size_t maxOrderX) {
383 maxOrderX_m = maxOrderX;
384}
385inline std::size_t MultipoleT::getTransMaxOrder() const {
386 return transMaxOrder_m;
387}
388inline void MultipoleT::setTransMaxOrder(std::size_t transMaxOrder) {
389 transMaxOrder_m = transMaxOrder;
390 transProfile_m.resize(transMaxOrder + 1, 0.);
391}
392inline double MultipoleT::getRotation() const {
393 return rotation_m;
394}
395inline void MultipoleT::setRotation(double rot) {
396 rotation_m = rot;
397}
398inline void MultipoleT::setBendAngle(double angle) {
399 angle_m = angle;
400}
401inline double MultipoleT::getBendAngle() const {
402 return angle_m;
403}
404inline void MultipoleT::setLength(double length) {
405 length_m = std::abs(length);
406}
407inline double MultipoleT::getLength() const {
408 return length_m;
409}
410inline double MultipoleT::getBoundingBoxLength() const {
411 return boundingBoxLength_m;
412}
413inline void MultipoleT::setBoundingBoxLength(const double& boundingBoxLength) {
414 boundingBoxLength_m = boundingBoxLength;
415}
416
417#endif
Interface for a single beam element.
Definition: Component.h:50
Calculate the Tanh function (e.g.
Definition: Tanh.h:48
void setBendAngle(double angle)
Set the bending angle of the magnet.
Definition: MultipoleT.h:398
void setRotation(double rot)
Set the angle of rotation of the magnet around its axis To make skew components.
Definition: MultipoleT.h:395
std::size_t getTransMaxOrder() const
Get the maximum order in the given transverse profile.
Definition: MultipoleT.h:385
std::vector< double > transProfile_m
List of transverse profile coefficients.
Definition: MultipoleT.h:264
void setDipoleConstant(double B0)
Set the dipole constant B_0.
Definition: MultipoleT.cpp:393
double getBoundingBoxLength() const
Get distance between centre of magnet and entrance.
Definition: MultipoleT.h:410
std::size_t transMaxOrder_m
Highest power in given mid-plane field.
Definition: MultipoleT.h:262
void setMaxXOrder(std::size_t maxXOrder)
Set the number of terms used in polynomial expansions.
Definition: MultipoleT.h:382
double horizApert_m
Definition: MultipoleT.h:296
void setAperture(double vertAp, double horizAp)
Set the aperture dimensions This element only supports a rectangular aperture.
Definition: MultipoleT.cpp:407
BMultipoleField dummy
Not implemented.
Definition: MultipoleT.h:298
Vector_t< double, 3 > rotateFrameInverse(Vector_t< double, 3 > &B)
Inverse of the 1st rotation in rotateFrame() method Used to rotate B field back to global coordinate...
Definition: MultipoleT.cpp:167
Vector_t< double, 3 > transformCoords(const Vector_t< double, 3 > &R)
Transform to Frenet-Serret coordinates for sector magnets.
Definition: MultipoleT.cpp:187
MultipoleT operator=(const MultipoleT &rhs)
double getTransDeriv(std::size_t n, double x)
Returns the value of the transverse field n-th derivative at x.
Definition: MultipoleT.cpp:363
double entranceAngle_m
Definition: MultipoleT.h:283
void setMaxOrder(std::size_t maxOrder)
Set the number of terms used in calculation of field components Maximum power of z in Bz is 2 * maxO...
Definition: MultipoleT.cpp:216
std::vector< polynomial::RecursionRelationTwo > recursion_VarRadius_m
Objects for storing differential operator acting on Fn.
Definition: MultipoleT.h:259
void initialise()
Initialises the geometry.
Definition: MultipoleT.cpp:518
bool apply(const Vector_t< double, 3 > &R, const Vector_t< double, 3 > &P, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) override
Calculate the field at some arbitrary position If particle is outside field map true is returned,...
Definition: MultipoleT.cpp:96
endfieldmodel::Tanh fringeField_r
Definition: MultipoleT.h:251
endfieldmodel::Tanh fringeField_l
Definition: MultipoleT.h:250
void setEntranceAngle(double entranceAngle)
Set the entrance angle.
Definition: MultipoleT.h:359
double getBz(const Vector_t< double, 3 > &R)
Definition: MultipoleT.cpp:259
ElementBase * clone() const override
Inheritable copy constructor.
Definition: MultipoleT.cpp:86
bool insideAperture(const Vector_t< double, 3 > &R)
Tests if inside the magnet.
Definition: MultipoleT.cpp:179
double getLength() const
Get the length of the magnet.
Definition: MultipoleT.h:407
void setTransMaxOrder(std::size_t transMaxOrder)
Set the maximum order in the given transverse profile.
Definition: MultipoleT.h:388
~MultipoleT()
Destructor.
Definition: MultipoleT.cpp:83
EMField & getField() override
Return a dummy field value.
Definition: MultipoleT.cpp:540
double getScaleFactor(double x, double s)
Returns the scale factor .
Definition: MultipoleT.cpp:438
double getFnDerivX(std::size_t n, double x, double s)
Calculate partial derivative of fn wrt x using a 5-point finite difference formula Error of order st...
Definition: MultipoleT.cpp:446
void accept(BeamlineVisitor &visitor) const override
Accept a beamline visitor.
Definition: MultipoleT.cpp:400
void setBoundingBoxLength(const double &boundingBoxLength)
Set distance between centre of magnet and enctrance.
Definition: MultipoleT.h:413
double verticalApert_m
Assume rectangular aperture with these dimensions.
Definition: MultipoleT.h:295
double getChordLength() const
Not used.
std::size_t getMaxOrder() const
Get the number of terms used in calculation of field components.
Definition: MultipoleT.h:374
double rotation_m
Definition: MultipoleT.h:284
void getDimensions(double &zBegin, double &zEnd) const override
Not implemented.
Definition: MultipoleT.cpp:404
bool getVarRadius() const
Get the value of variableRadius_m.
Definition: MultipoleT.h:356
double angle_m
Definition: MultipoleT.h:282
double getFnDerivS(std::size_t n, double x, double s)
Calculate partial derivative of fn wrt s using a 5-point finite difference formuln Error of order ste...
Definition: MultipoleT.cpp:460
std::size_t maxOrderX_m
Highest order of polynomial expansions in x.
Definition: MultipoleT.h:257
double getRadius(double s)
Radius of curvature If radius of curvature is infinite, -1 is returned If radius is constant,...
Definition: MultipoleT.cpp:426
std::vector< polynomial::RecursionRelation > recursion_ConstRadius_m
Definition: MultipoleT.h:260
double getBx(const Vector_t< double, 3 > &R)
Get field component methods.
Definition: MultipoleT.cpp:290
std::size_t getMaxXOrder() const
Get highest power of x in polynomial expansions.
Definition: MultipoleT.h:378
double length_m
Magnet parameters.
Definition: MultipoleT.h:281
double getFn(std::size_t n, double x, double s)
Calculate fn(x, s) by expanding the differential operator (from Laplacian and scalar potential) in te...
Definition: MultipoleT.cpp:474
bool setFringeField(double s0, double lambda_left, double lambda_right)
Set fringe field model Tanh model used here .
Definition: MultipoleT.cpp:247
void initialise(PartBunch_t *, double &startField, double &endField) override
Initialise the MultipoleT.
void finalise() override
Finalise the MultipoleT - sets bunch to nullptr.
Definition: MultipoleT.cpp:92
double getFringeDeriv(int n, double s)
Returns the value of the fringe field n-th derivative at s.
Definition: MultipoleT.cpp:353
double getDipoleConstant() const
Get the dipole constant B_0.
Definition: MultipoleT.h:371
void setVarRadius()
Set variable radius flag to true.
Definition: MultipoleT.h:353
PlanarArcGeometry planarArcGeometry_m
Geometry.
Definition: MultipoleT.h:266
void setLength(double length)
Set the length of the magnet If straight-> Actual length If curved -> Arc length .
Definition: MultipoleT.h:404
bool bends() const override
Return true if dipole component not zero.
Definition: MultipoleT.cpp:528
std::vector< double > getAperture() const
Get the aperture dimensions Returns a vector of 2 doubles.
Definition: MultipoleT.cpp:412
double getRotation() const
Get the angle of rotation of the magnet around its axis.
Definition: MultipoleT.h:392
void setTransProfile(std::size_t n, double Bn)
Set transverse profile T(x) T(x) = B_0 + B1 x + B2 x^2 + B3 x^3 + ...
Definition: MultipoleT.cpp:239
double getBendRadius() const
Get the bending radius Not used, when needed radius is found from length_m / angle_m.
std::size_t maxOrder_m
Field expansion parameters Number of terms in z expansion used in calculating field components.
Definition: MultipoleT.h:255
bool variableRadius_m
Variable radius flag.
Definition: MultipoleT.h:286
double boundingBoxLength_m
Distance between centre of magnet and entrance.
Definition: MultipoleT.h:288
MultipoleT(const std::string &name)
Constructor.
Definition: MultipoleT.cpp:42
std::vector< double > getTransProfile() const
Get all terms of transverse profile.
Definition: MultipoleT.h:368
double getEntranceAngle() const
Get the entrance angle.
Definition: MultipoleT.h:362
Vector_t< double, 3 > rotateFrame(const Vector_t< double, 3 > &R)
Rotate frame for skew elements Consecutive rotations: 1st -> about central axis 2nd -> azimuthal rota...
Definition: MultipoleT.cpp:150
double getBendAngle() const
Get the bending angle of the magnet.
Definition: MultipoleT.h:401
double getBs(const Vector_t< double, 3 > &R)
Definition: MultipoleT.cpp:321
PlanarArcGeometry & getGeometry() override
Return the cell geometry.
Definition: MultipoleT.cpp:532
std::vector< double > getFringeLength() const
Return vector of 2 doubles [left fringe length, right fringelength].
Definition: MultipoleT.cpp:419
A simple arc in the XZ plane.
The magnetic field of a multipole.
Abstract base class for electromagnetic fields.
Definition: EMField.h:188