OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
81#include "Algorithms/Vektor.h"
84#include <vector>
85
87public:
93 explicit MultipoleTBase(const std::string &name);
95 MultipoleTBase(const MultipoleTBase &right);
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;
221protected:
226 double getFringeDeriv(const std::size_t &n, const double &s);
233 double getTransDeriv(const std::size_t &n, const double &x);
234private:
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;
257 virtual void transformCoords(Vector_t &R) = 0;
259 virtual void transformBField(Vector_t &B, const Vector_t &R) = 0;
261 double length_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
330inline
332 RefPartBunch_m = nullptr;
333}
334inline
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}
339inline
340void MultipoleTBase::setBendAngle(const double &/*angle*/) {}
341inline
343 return 0.0;
344}
345inline
346 void MultipoleTBase::setEntranceAngle(const double &entranceAngle) {
347 entranceAngle_m = entranceAngle;
348}
349inline
351 return (std::abs(R[1]) <= (verticalApert_m / 2.0) &&
352 std::abs(R[0]) <= (horizontalApert_m / 2.0));
353}
354inline
356 return entranceAngle_m;
357}
358inline
359 double MultipoleTBase::getTransProfile(const std::size_t &n) const {
360 return transProfile_m[n];
361}
362inline
363 std::vector<double> MultipoleTBase::getTransProfile() const {
364 return transProfile_m;
365}
366inline
368 return transProfile_m[0];
369}
370inline
371 void MultipoleTBase::setMaxOrder(const std::size_t &maxOrder) {
372 maxOrder_m = maxOrder;
373}
374inline
375 std::size_t MultipoleTBase::getMaxOrder() const {
376 return maxOrder_m;
377}
378inline
380 return transMaxOrder_m;
381}
382inline
383 void MultipoleTBase::setTransMaxOrder(const std::size_t &transMaxOrder) {
384 transMaxOrder_m = transMaxOrder;
385 transProfile_m.resize(transMaxOrder + 1, 0.);
386}
387inline
389 return rotation_m;
390}
391inline
392 void MultipoleTBase::setRotation(const double &rot) {
393 rotation_m = rot;
394}
395inline
396 void MultipoleTBase::setLength(const double &length) {
397 length_m = std::abs(length);
398}
399inline
401 return length_m;
402}
403inline
405 return boundingBoxLength_m;
406}
407inline
408 void MultipoleTBase::setBoundingBoxLength(const double &boundingBoxLength) {
409 boundingBoxLength_m = boundingBoxLength;
410}
411inline
412 void MultipoleTBase::setTransProfile(const std::size_t &n,
413 const double &dTn) {
414 if (n > transMaxOrder_m) {
416 transProfile_m.resize(n + 1, 0.0);
417 }
418 transProfile_m[n] = dTn;
419}
420inline
421 void MultipoleTBase::setDipoleConstant(const double &B0) {
422 if (transMaxOrder_m < 1) {
423 transProfile_m.resize(1, 0.);
424 }
425 transProfile_m[0] = B0;
426}
427inline
428 void MultipoleTBase::setAperture(const double &vertAp,
429 const double &horizAp) {
430 verticalApert_m = vertAp;
431 horizontalApert_m = horizAp;
432}
433inline
434 std::vector<double> MultipoleTBase::getAperture() const {
435 std::vector<double> temp(2, 0.0);
436 temp[0] = verticalApert_m;
437 temp[1] = horizontalApert_m;
438 return temp;
439}
440inline
441 std::vector<double> MultipoleTBase::getFringeLength() const {
442 std::vector<double> temp(2, 0.0);
443 temp[0] = fringeField_l.getLambda();
444 temp[1] = fringeField_r.getLambda();
445 return temp;
446}
447inline
449 double &/*startField*/,
450 double &/*endField*/) {
451}
452inline
454 return transProfile_m[0] != 0;
455}
456inline
458 return dummy;
459}
460inline
462 return dummy;
463}
464inline
465 void MultipoleTBase::getDimensions(double &/*zBegin*/, double &/*zEnd*/) const {
466}
467
468#endif
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
const std::string name
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
double getLambda() const
Definition: Tanh.h:101
virtual double getRadius(const double &s)=0
BMultipoleField dummy
double getBoundingBoxLength() const
std::size_t getTransMaxOrder() const
virtual void setBendAngle(const double &angle)
virtual double getFn(const std::size_t &n, const double &x, const double &s)=0
void initialise(PartBunchBase< double, 3 > *, double &startField, double &endField)
double boundingBoxLength_m
std::vector< double > getFringeLength() const
void setRotation(const double &rot)
void setLength(const double &length)
double getDipoleConstant() const
endfieldmodel::Tanh fringeField_l
virtual void setMaxOrder(const std::size_t &maxOrder)
double verticalApert_m
double getRotation() const
std::vector< double > getAperture() const
double getLength() const
bool bends() const
virtual void transformCoords(Vector_t &R)=0
std::vector< double > transProfile_m
std::size_t maxOrder_m
Vector_t rotateFrameInverse(Vector_t &B)
bool insideAperture(const Vector_t &R)
double getEntranceAngle() const
std::size_t getMaxOrder() const
endfieldmodel::Tanh fringeField_r
std::vector< double > getTransProfile() const
double getTransDeriv(const std::size_t &n, const double &x)
double getBz(const Vector_t &R)
double entranceAngle_m
virtual double getScaleFactor(const double &x, const double &s)=0
bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B)
virtual void transformBField(Vector_t &B, const Vector_t &R)=0
void setEntranceAngle(const double &entranceAngle)
std::size_t transMaxOrder_m
double horizontalApert_m
void setTransProfile(const std::size_t &n, const double &Bn)
double getFnDerivX(const std::size_t &n, const double &x, const double &s)
EMField & getField()
Vector_t rotateFrame(const Vector_t &R)
bool setFringeField(const double &s0, const double &lambda_left, const double &lambda_right)
virtual double getBx(const Vector_t &R)
void setDipoleConstant(const double &B0)
double getFringeDeriv(const std::size_t &n, const double &s)
virtual void getDimensions(double &zBegin, double &zEnd) const
virtual double getBs(const Vector_t &R)
void setBoundingBoxLength(const double &boundingBoxLength)
double getFnDerivS(const std::size_t &n, const double &x, const double &s)
void setAperture(const double &vertAp, const double &horizAp)
void setTransMaxOrder(const std::size_t &transMaxOrder)
virtual double getBendAngle() const
The magnetic field of a multipole.
Abstract base class for electromagnetic fields.
Definition: EMField.h:188