OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
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 
30 #ifndef CLASSIC_MULTIPOLET_H
31 #define CLASSIC_MULTIPOLET_H
32 
80 #include "Fields/BMultipoleField.h"
81 #include "Algorithms/Vektor.h"
82 #include "AbsBeamline/Component.h"
86 #include "gsl/gsl_sf.h"
87 #include <vector>
88 
89 class MultipoleT: public Component {
90 public:
94  explicit MultipoleT(const std::string &name);
96  MultipoleT(const MultipoleT &right);
98  ~MultipoleT();
100  ElementBase* clone() const override;
102  EMField &getField() override;
104  const EMField &getField() const override;
106  void getDimensions(double &zBegin, double &zEnd) const override;
116  bool apply(const Vector_t &R, const Vector_t &P, const double &t,
117  Vector_t &E, Vector_t &B) override;
127  bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
134  double &startField,
135  double &endField) override;
137  void initialise();
138 
140  void finalise() override;
142  bool bends() const override;
144  PlanarArcGeometry& getGeometry() override;
146  const PlanarArcGeometry& getGeometry() const override;
148  void accept(BeamlineVisitor& visitor) const override;
150  double getDipoleConstant() const;
152  void setDipoleConstant(double B0);
154  std::size_t getMaxOrder() const;
159  void setMaxOrder(std::size_t maxOrder);
161  std::size_t getMaxXOrder() const;
165  void setMaxXOrder(std::size_t maxXOrder);
167  std::size_t getTransMaxOrder() const;
171  void setTransMaxOrder(std::size_t transMaxOrder);
177  void setTransProfile(std::size_t n, double Bn);
181  double getTransProfile(int n) const;
183  std::vector<double> getTransProfile() const;
192  bool setFringeField(double s0, double lambda_left, double lambda_right);
196  std::vector<double> getFringeLength() const;
198  void setBendAngle(double angle);
200  double getBendAngle() const;
204  void setEntranceAngle(double entranceAngle);
206  double getEntranceAngle() const;
210  double getBendRadius() const;
215  void setLength(double length);
217  double getLength() const;
219  double getChordLength() const;
225  void setAperture(double vertAp, double horizAp);
229  std::vector<double> getAperture() const;
234  void setRotation(double rot);
236  double getRotation() const;
238  void setVarRadius();
240  bool getVarRadius() const;
242  double getBoundingBoxLength() const;
246  void setBoundingBoxLength(const double &boundingBoxLength);
247 
248 private:
249  MultipoleT operator=(const MultipoleT& rhs);
250  // End fields
256  std::size_t maxOrder_m = 0;
258  std::size_t maxOrderX_m = 0;
260  std::vector<polynomial::RecursionRelationTwo> recursion_VarRadius_m;
261  std::vector<polynomial::RecursionRelation> recursion_ConstRadius_m;
263  std::size_t transMaxOrder_m = 0;
265  std::vector<double> transProfile_m;
274  Vector_t rotateFrame(const Vector_t &R);
282  double length_m;
283  double angle_m;
285  double rotation_m;
292  double getBx (const Vector_t &R);
293  double getBz (const Vector_t &R);
294  double getBs (const Vector_t &R);
297  double horizApert_m;
304  double getFringeDeriv(int n, double s);
309  double getTransDeriv(std::size_t n, double x);
313  bool insideAperture(const Vector_t &R);
323  double getRadius(double s);
328  double getScaleFactor(double x, double s);
336  double getFnDerivX(std::size_t n, double x, double s);
344  double getFnDerivS(std::size_t n, double x, double s);
351  double getFn(std::size_t n, double x, double s);
352 };
353 
354 inline
356  variableRadius_m = true;
357 }
358 inline
360  return variableRadius_m;
361 }
362 inline
363  void MultipoleT::setEntranceAngle(double entranceAngle) {
364  entranceAngle_m = entranceAngle;
365 }
366 inline
368  return entranceAngle_m;
369 }
370 inline
371  double MultipoleT::getTransProfile(int n) const {
372  return transProfile_m[n];
373 }
374 inline
375  std::vector<double> MultipoleT::getTransProfile() const {
376  return transProfile_m;
377 }
378 inline
380  return transProfile_m[0];
381 }
382 inline
383  std::size_t MultipoleT::getMaxOrder() const {
384  return maxOrder_m;
385 }
386 
387 inline
388  std::size_t MultipoleT::getMaxXOrder() const {
389  return maxOrderX_m;
390 }
391 
392 inline
393  void MultipoleT::setMaxXOrder(std::size_t maxOrderX) {
394  maxOrderX_m = maxOrderX;
395 }
396 inline
397  std::size_t MultipoleT::getTransMaxOrder() const {
398  return transMaxOrder_m;
399 }
400 inline
401  void MultipoleT::setTransMaxOrder(std::size_t transMaxOrder) {
402  transMaxOrder_m = transMaxOrder;
403  transProfile_m.resize(transMaxOrder + 1, 0.);
404 }
405 inline
406  double MultipoleT::getRotation() const {
407  return rotation_m;
408 }
409 inline
410  void MultipoleT::setRotation(double rot) {
411  rotation_m = rot;
412 }
413 inline
414  void MultipoleT::setBendAngle(double angle) {
415  angle_m = angle;
416 }
417 inline
418  double MultipoleT::getBendAngle() const {
419  return angle_m;
420 }
421 inline
422  void MultipoleT::setLength(double length) {
423  length_m = std::abs(length);
424 }
425 inline
426  double MultipoleT::getLength() const {
427  return length_m;
428 }
429 inline
431  return boundingBoxLength_m;
432 }
433 inline
434  void MultipoleT::setBoundingBoxLength(const double &boundingBoxLength) {
435  boundingBoxLength_m = boundingBoxLength;
436 }
437 
438 #endif
double getBx(const Vector_t &R)
Definition: MultipoleT.cpp:286
double boundingBoxLength_m
Definition: MultipoleT.h:289
double getBendRadius() const
double rotation_m
Definition: MultipoleT.h:285
void setDipoleConstant(double B0)
Definition: MultipoleT.cpp:396
std::size_t getTransMaxOrder() const
Definition: MultipoleT.h:397
double verticalApert_m
Definition: MultipoleT.h:296
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
void setVarRadius()
Definition: MultipoleT.h:355
double getScaleFactor(double x, double s)
Definition: MultipoleT.cpp:441
void setTransMaxOrder(std::size_t transMaxOrder)
Definition: MultipoleT.h:401
std::size_t maxOrder_m
Definition: MultipoleT.h:256
std::vector< double > transProfile_m
Definition: MultipoleT.h:265
Interface for basic beam line object.
Definition: ElementBase.h:128
MultipoleT operator=(const MultipoleT &rhs)
double getDipoleConstant() const
Definition: MultipoleT.h:379
PlanarArcGeometry & getGeometry() override
Definition: MultipoleT.cpp:548
A simple arc in the XZ plane.
double getFn(std::size_t n, double x, double s)
Definition: MultipoleT.cpp:477
double horizApert_m
Definition: MultipoleT.h:297
bool setFringeField(double s0, double lambda_left, double lambda_right)
Definition: MultipoleT.cpp:243
double getBs(const Vector_t &R)
Definition: MultipoleT.cpp:319
Vector_t rotateFrameInverse(Vector_t &B)
Definition: MultipoleT.cpp:160
std::size_t getMaxXOrder() const
Definition: MultipoleT.h:388
double entranceAngle_m
Definition: MultipoleT.h:284
std::size_t getMaxOrder() const
Definition: MultipoleT.h:383
void setEntranceAngle(double entranceAngle)
Definition: MultipoleT.h:363
void finalise() override
Definition: MultipoleT.cpp:90
double getRadius(double s)
Definition: MultipoleT.cpp:429
void setBendAngle(double angle)
Definition: MultipoleT.h:414
EMField & getField() override
Definition: MultipoleT.cpp:556
void initialise()
Definition: MultipoleT.cpp:532
PlanarArcGeometry planarArcGeometry_m
Definition: MultipoleT.h:267
MultipoleT(const std::string &name)
Definition: MultipoleT.cpp:40
double getLength() const
Definition: MultipoleT.h:426
BMultipoleField dummy
Definition: MultipoleT.h:299
void setMaxOrder(std::size_t maxOrder)
Definition: MultipoleT.cpp:212
double getFnDerivX(std::size_t n, double x, double s)
Definition: MultipoleT.cpp:449
double getFringeDeriv(int n, double s)
Definition: MultipoleT.cpp:353
bool getVarRadius() const
Definition: MultipoleT.h:359
double angle_m
Definition: MultipoleT.h:283
double getEntranceAngle() const
Definition: MultipoleT.h:367
Vector_t transformCoords(const Vector_t &R)
Definition: MultipoleT.cpp:181
Vector_t rotateFrame(const Vector_t &R)
Definition: MultipoleT.cpp:140
double length_m
Definition: MultipoleT.h:282
void setAperture(double vertAp, double horizAp)
Definition: MultipoleT.cpp:410
std::vector< double > getAperture() const
Definition: MultipoleT.cpp:415
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
bool variableRadius_m
Definition: MultipoleT.h:287
double getBz(const Vector_t &R)
Definition: MultipoleT.cpp:255
std::vector< polynomial::RecursionRelationTwo > recursion_VarRadius_m
Definition: MultipoleT.h:260
double getBoundingBoxLength() const
Definition: MultipoleT.h:430
bool insideAperture(const Vector_t &R)
Definition: MultipoleT.cpp:172
void setTransProfile(std::size_t n, double Bn)
Definition: MultipoleT.cpp:235
The magnetic field of a multipole.
endfieldmodel::Tanh fringeField_r
Definition: MultipoleT.h:252
void setRotation(double rot)
Definition: MultipoleT.h:410
std::size_t maxOrderX_m
Definition: MultipoleT.h:258
bool bends() const override
Definition: MultipoleT.cpp:544
const std::string name
void setLength(double length)
Definition: MultipoleT.h:422
void setMaxXOrder(std::size_t maxXOrder)
Definition: MultipoleT.h:393
double getBendAngle() const
Definition: MultipoleT.h:418
double getChordLength() const
void getDimensions(double &zBegin, double &zEnd) const override
Definition: MultipoleT.cpp:407
void accept(BeamlineVisitor &visitor) const override
Definition: MultipoleT.cpp:403
bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
Definition: MultipoleT.cpp:94
double getFnDerivS(std::size_t n, double x, double s)
Definition: MultipoleT.cpp:463
ElementBase * clone() const override
Definition: MultipoleT.cpp:84
Interface for a single beam element.
Definition: Component.h:51
Abstract algorithm.
std::vector< double > getTransProfile() const
Definition: MultipoleT.h:375
void setBoundingBoxLength(const double &boundingBoxLength)
Definition: MultipoleT.h:434
double getRotation() const
Definition: MultipoleT.h:406
std::vector< double > getFringeLength() const
Definition: MultipoleT.cpp:422
double getTransDeriv(std::size_t n, double x)
Definition: MultipoleT.cpp:366
endfieldmodel::Tanh fringeField_l
Definition: MultipoleT.h:251
std::vector< polynomial::RecursionRelation > recursion_ConstRadius_m
Definition: MultipoleT.h:261
std::size_t transMaxOrder_m
Definition: MultipoleT.h:263