OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
MultipoleTBase.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_MULTIPOLETBASE_H
31 #define CLASSIC_MULTIPOLETBASE_H
32 
78 #include "Algorithms/PartBunch.h"
80 #include "Fields/BMultipoleField.h"
81 #include "Algorithms/Vektor.h"
82 #include "AbsBeamline/Component.h"
84 #include <vector>
85 
86 class MultipoleTBase: public Component {
87 public:
93  explicit MultipoleTBase(const std::string &name);
95  MultipoleTBase(const MultipoleTBase &right);
99  EMField &getField();
101  const EMField &getField() const;
111  bool apply(const Vector_t &R, const Vector_t &P, const double &t,
112  Vector_t &E, Vector_t &B);
122  bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B);
129  double &startField,
130  double &endField);
132  void finalise();
134  bool bends() const;
136  double getDipoleConstant() const;
138  void setDipoleConstant(const double &B0);
140  std::size_t getMaxOrder() const;
145  virtual void setMaxOrder(const std::size_t &maxOrder);
147  std::size_t getTransMaxOrder() const;
151  void setTransMaxOrder(const std::size_t &transMaxOrder);
157  void setTransProfile(const std::size_t &n, const double &Bn);
161  double getTransProfile(const std::size_t &n) const;
163  std::vector<double> getTransProfile() const;
172  bool setFringeField(const double &s0,
173  const double &lambda_left,
174  const double &lambda_right);
178  std::vector<double> getFringeLength() const;
182  void setEntranceAngle(const double &entranceAngle);
184  virtual void setBendAngle(const double &angle);
186  virtual double getBendAngle() const;
188  double getEntranceAngle() const;
193  void setLength(const double &length);
195  double getLength() const;
201  void setAperture(const double &vertAp, const double &horizAp);
205  std::vector<double> getAperture() const;
210  void setRotation(const double &rot);
212  double getRotation() const;
214  double getBoundingBoxLength() const;
218  void setBoundingBoxLength(const double &boundingBoxLength);
220  virtual void getDimensions(double &zBegin, double &zEnd) const;
221 protected:
226  double getFringeDeriv(const std::size_t &n, const double &s);
233  double getTransDeriv(const std::size_t &n, const double &x);
234 private:
235  //MultipoleTBase operator=(const MultipoleTBase &rhs);
236  // End fields
240  std::size_t maxOrder_m;
242  std::size_t transMaxOrder_m = 0;
244  std::vector<double> transProfile_m;
251  Vector_t rotateFrame(const Vector_t &R);
257  virtual void transformCoords(Vector_t &R) = 0;
259  virtual void transformBField(Vector_t &B, const Vector_t &R) = 0;
261  double length_m;
263  double rotation_m;
270  virtual double getBx (const Vector_t &R);
275  double getBz (const Vector_t &R);
280  virtual double getBs (const Vector_t &R);
289  bool insideAperture(const Vector_t &R);
293  virtual double getRadius(const double &s) = 0;
298  virtual double getScaleFactor(const double &x, const double &s) = 0;
306  double getFnDerivX(const std::size_t &n,
307  const double &x,
308  const double &s);
316  double getFnDerivS(const std::size_t &n,
317  const double &x,
318  const double &s);
325  virtual double getFn(const std::size_t &n,
326  const double &x,
327  const double &s) = 0;
328 };
329 
330 inline
332  RefPartBunch_m = NULL;
333 }
334 inline
335  bool MultipoleTBase::apply(const size_t &i, const double &t,
336  Vector_t &E, Vector_t &B) {
337  return apply(RefPartBunch_m->R[i], RefPartBunch_m->P[i], t, E, B);
338 }
339 inline
340  void MultipoleTBase::setBendAngle(const double &angle) {
341 }
342 inline
344  return 0.0;
345 }
346 inline
347  void MultipoleTBase::setEntranceAngle(const double &entranceAngle) {
348  entranceAngle_m = entranceAngle;
349 }
350 inline
352  return (fabs(R[1]) <= (verticalApert_m / 2.0) &&
353  fabs(R[0]) <= (horizontalApert_m / 2.0));
354 }
355 inline
357  return entranceAngle_m;
358 }
359 inline
360  double MultipoleTBase::getTransProfile(const std::size_t &n) const {
361  return transProfile_m[n];
362 }
363 inline
364  std::vector<double> MultipoleTBase::getTransProfile() const {
365  return transProfile_m;
366 }
367 inline
369  return transProfile_m[0];
370 }
371 inline
372  void MultipoleTBase::setMaxOrder(const std::size_t &maxOrder) {
373  maxOrder_m = maxOrder;
374 }
375 inline
376  std::size_t MultipoleTBase::getMaxOrder() const {
377  return maxOrder_m;
378 }
379 inline
380  std::size_t MultipoleTBase::getTransMaxOrder() const {
381  return transMaxOrder_m;
382 }
383 inline
384  void MultipoleTBase::setTransMaxOrder(const std::size_t &transMaxOrder) {
385  transMaxOrder_m = transMaxOrder;
386  transProfile_m.resize(transMaxOrder + 1, 0.);
387 }
388 inline
390  return rotation_m;
391 }
392 inline
393  void MultipoleTBase::setRotation(const double &rot) {
394  rotation_m = rot;
395 }
396 inline
397  void MultipoleTBase::setLength(const double &length) {
398  length_m = std::abs(length);
399 }
400 inline
401  double MultipoleTBase::getLength() const {
402  return length_m;
403 }
404 inline
406  return boundingBoxLength_m;
407 }
408 inline
409  void MultipoleTBase::setBoundingBoxLength(const double &boundingBoxLength) {
410  boundingBoxLength_m = boundingBoxLength;
411 }
412 inline
413  void MultipoleTBase::setTransProfile(const std::size_t &n,
414  const double &dTn) {
415  if (n > transMaxOrder_m) {
416  transMaxOrder_m = n;
417  transProfile_m.resize(n + 1, 0.0);
418  }
419  transProfile_m[n] = dTn;
420 }
421 inline
422  void MultipoleTBase::setDipoleConstant(const double &B0) {
423  if (transMaxOrder_m < 1) {
424  transProfile_m.resize(1, 0.);
425  }
426  transProfile_m[0] = B0;
427 }
428 inline
429  void MultipoleTBase::setAperture(const double &vertAp,
430  const double &horizAp) {
431  verticalApert_m = vertAp;
432  horizontalApert_m = horizAp;
433 }
434 inline
435  std::vector<double> MultipoleTBase::getAperture() const {
436  std::vector<double> temp(2, 0.0);
437  temp[0] = verticalApert_m;
438  temp[1] = horizontalApert_m;
439  return temp;
440 }
441 inline
442  std::vector<double> MultipoleTBase::getFringeLength() const {
443  std::vector<double> temp(2, 0.0);
444  temp[0] = fringeField_l.getLambda();
445  temp[1] = fringeField_r.getLambda();
446  return temp;
447 }
448 inline
450  double &startField,
451  double &endField) {
452 }
453 inline
454  bool MultipoleTBase::bends() const {
455  return transProfile_m[0] != 0;
456 }
457 inline
459  return dummy;
460 }
461 inline
463  return dummy;
464 }
465 inline
466  void MultipoleTBase::getDimensions(double &zBegin, double &zEnd) const {
467 }
468 
469 #endif
ParticleAttrib< Vector_t > P
virtual double getFn(const std::size_t &n, const double &x, const double &s)=0
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double getEntranceAngle() const
std::vector< double > getFringeLength() const
bool setFringeField(const double &s0, const double &lambda_left, const double &lambda_right)
double getFnDerivX(const std::size_t &n, const double &x, const double &s)
virtual void getDimensions(double &zBegin, double &zEnd) const
void setDipoleConstant(const double &B0)
void setAperture(const double &vertAp, const double &horizAp)
double verticalApert_m
virtual double getRadius(const double &s)=0
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
Definition: PETE.h:815
std::size_t maxOrder_m
double entranceAngle_m
virtual void setBendAngle(const double &angle)
virtual void transformCoords(Vector_t &R)=0
std::size_t getTransMaxOrder() const
double horizontalApert_m
std::size_t transMaxOrder_m
void setTransProfile(const std::size_t &n, const double &Bn)
BMultipoleField dummy
std::vector< double > getTransProfile() const
EMField & getField()
endfieldmodel::Tanh fringeField_l
double getRotation() const
double getLength() const
void setTransMaxOrder(const std::size_t &transMaxOrder)
void setEntranceAngle(const double &entranceAngle)
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:200
double boundingBoxLength_m
virtual double getBx(const Vector_t &R)
void setLength(const double &length)
void setBoundingBoxLength(const double &boundingBoxLength)
bool insideAperture(const Vector_t &R)
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B)
double getTransDeriv(const std::size_t &n, const double &x)
The magnetic field of a multipole.
virtual void transformBField(Vector_t &B, const Vector_t &R)=0
endfieldmodel::Tanh fringeField_r
double getFnDerivS(const std::size_t &n, const double &x, const double &s)
virtual double getScaleFactor(const double &x, const double &s)=0
void initialise(PartBunchBase< double, 3 > *, double &startField, double &endField)
const std::string name
double getFringeDeriv(const std::size_t &n, const double &s)
std::size_t getMaxOrder() const
virtual double getBs(const Vector_t &R)
virtual double getBendAngle() const
ParticlePos_t & R
void setRotation(const double &rot)
bool bends() const
double getBoundingBoxLength() const
Interface for a single beam element.
Definition: Component.h:51
double getLambda() const
Definition: Tanh.h:92
virtual void setMaxOrder(const std::size_t &maxOrder)
double getDipoleConstant() const
std::vector< double > transProfile_m
Vector_t rotateFrameInverse(Vector_t &B)
std::vector< double > getAperture() const
Vector_t rotateFrame(const Vector_t &R)
double getBz(const Vector_t &R)