OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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* Copyright (c) 2025, Jon Thompson
5* All rights reserved.
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* 1. Redistributions of source code must retain the above copyright notice,
9* this list of conditions and the following disclaimer.
10* 2. Redistributions in binary form must reproduce the above copyright notice,
11* this list of conditions and the following disclaimer in the documentation
12* and/or other materials provided with the distribution.
13* 3. Neither the name of STFC nor the names of its contributors may be used to
14* endorse or promote products derived from this software without specific
15* prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27* POSSIBILITY OF SUCH DAMAGE.
28*/
29
30
31#ifndef CLASSIC_MULTIPOLET_H
32#define CLASSIC_MULTIPOLET_H
33
78
82#include "Algorithms/Vektor.h"
84#include <vector>
85#include "MultipoleTBase.h"
87
88class MultipoleT final: public Component {
89public:
93 explicit MultipoleT(const std::string &name);
95 MultipoleT(const MultipoleT &right);
97 ~MultipoleT() override = default;
99 ElementBase* clone() const override;
101 void accept(BeamlineVisitor &visitor) const override;
103 BGeometryBase& getGeometry() override;
105 const BGeometryBase& getGeometry() const override;
107 EMField &getField() override { return dummy; }
109 const EMField &getField() const override { return dummy; }
119 bool apply(const Vector_t &R, const Vector_t &P, const double &t,
120 Vector_t &E, Vector_t &B) override;
130 bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override;
136 void initialise(PartBunchBase<double, 3>* bunch, double& startField,
137 double& endField) override;
139 void finalise() override;
141 bool bends() const override;
143 size_t getMaxFOrder() const { return maxFOrder_m; }
144 size_t getMaxXOrder() const { return maxXOrder_m; }
149 void setMaxOrder(size_t orderZ, size_t orderX);
151 std::size_t getTransMaxOrder() const { return transMaxOrder_m; }
155 void setTransProfile(const std::vector<double>& profile);
157 const std::vector<double>& getTransProfile() const { return transProfile_m; }
166 void setFringeField(const double& s0, const double& lambda_left,
167 const double& lambda_right);
171 std::tuple<double, double, double> getFringeField() const;
175 void setEntranceAngle(double entranceAngle);
179 void setEntryOffset(double offset);
181 double getEntryOffset() const { return entryOffset_m; }
183 bool getVariableRadius() const { return variableRadius_m; }
185 void setBendAngle(double angle, bool variableRadius);
187 double getBendAngle() const { return bendAngle_m; }
189 double getEntranceAngle() const { return entranceAngle_m; }
194 void setElementLength(double length) override;
196 double getLength() const { return length_m; }
202 void setAperture(const double& vertAp, const double& horizAp);
206 std::tuple<double, double> getAperture() { return {verticalApert_m, horizontalApert_m}; }
211 void setRotation(double rot);
213 double getRotation() const { return rotation_m; }
215 double getBoundingBoxLength() const { return boundingBoxLength_m; }
219 void setBoundingBoxLength(double boundingBoxLength);
221 void getDimensions(double &/*zBegin*/, double &/*zEnd*/) const override {}
226 double getFringeDeriv(const std::size_t& n, const double& s);
234 double getFnDerivX(const std::size_t& n,
235 const double& x,
236 const double& s);
244 double getFnDerivS(const std::size_t& n,
245 const double& x,
246 const double& s);
253 double getTransDeriv(const std::size_t& n, const double& x) const;
254
256 Vector_t getField(const Vector_t& magnetCoords);
258 double localCartesianRotation();
259
260 void setScalingName(const std::string& name);
261 void setScalingModel(const std::shared_ptr<AbstractTimeDependence>& td) {scalingTD_m = td; }
262 std::string getScalingName() const { return scalingName_m; }
263 void initialiseTimeDepencencies() const;
264
265protected:
270 Vector_t rotateFrame(const Vector_t& R) const;
271 bool insideAperture(const Vector_t& R) const;
272 bool insideBoundingBox(const Vector_t& R) const;
274
275 // End fields
279 std::size_t maxFOrder_m{3};
281 std::size_t maxXOrder_m{20};
283 std::vector<double> transProfile_m{0.0};
286 double length_m{1.0};
287 double entranceAngle_m{0.0};
288 double rotation_m{0.0};
289 double bendAngle_m{0.0};
290 bool variableRadius_m{false};
292 double entryOffset_m{0.0};
294 double verticalApert_m{0.5};
295 double horizontalApert_m{0.5};
298 // Time dependence
299 std::string scalingName_m;
300 mutable std::shared_ptr<AbstractTimeDependence> scalingTD_m;
301
302 std::unique_ptr<MultipoleTBase> implementation_{};
303};
304
305#endif
const std::string name
Component(const std::string &name)
Constructor with given name.
Definition Component.cpp:53
ElementBase(const std::string &name)
Constructor with given name.
Vector_t toMagnetCoords(const Vector_t &R)
void setRotation(double rot)
std::size_t getTransMaxOrder() const
Definition MultipoleT.h:151
std::vector< double > transProfile_m
Definition MultipoleT.h:283
double getBoundingBoxLength() const
Definition MultipoleT.h:215
double entryOffset_m
Definition MultipoleT.h:292
void setScalingName(const std::string &name)
Vector_t localCartesianToOpalCartesian(const Vector_t &r)
std::size_t maxFOrder_m
Definition MultipoleT.h:279
BMultipoleField dummy
Definition MultipoleT.h:297
size_t getMaxFOrder() const
Definition MultipoleT.h:143
const EMField & getField() const override
Definition MultipoleT.h:109
bool getVariableRadius() const
Definition MultipoleT.h:183
void setBendAngle(double angle, bool variableRadius)
std::size_t maxXOrder_m
Definition MultipoleT.h:281
double entranceAngle_m
Definition MultipoleT.h:287
double getFringeDeriv(const std::size_t &n, const double &s)
size_t transMaxOrder_m
Definition MultipoleT.h:284
void setElementLength(double length) override
endfieldmodel::Tanh fringeField_r
Definition MultipoleT.h:277
endfieldmodel::Tanh fringeField_l
Definition MultipoleT.h:276
void setEntranceAngle(double entranceAngle)
void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
ElementBase * clone() const override
std::tuple< double, double > getAperture()
Definition MultipoleT.h:206
std::string scalingName_m
Definition MultipoleT.h:299
double getLength() const
Definition MultipoleT.h:196
EMField & getField() override
Definition MultipoleT.h:107
void accept(BeamlineVisitor &visitor) const override
double verticalApert_m
Definition MultipoleT.h:294
void setAperture(const double &vertAp, const double &horizAp)
double rotation_m
Definition MultipoleT.h:288
void setMaxOrder(size_t orderZ, size_t orderX)
double length_m
Definition MultipoleT.h:286
const std::vector< double > & getTransProfile() const
Definition MultipoleT.h:157
double localCartesianRotation()
bool apply(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
void finalise() override
Vector_t rotateFrame(const Vector_t &R) const
double bendAngle_m
Definition MultipoleT.h:289
~MultipoleT() override=default
bool insideAperture(const Vector_t &R) const
double getTransDeriv(const std::size_t &n, const double &x) const
size_t getMaxXOrder() const
Definition MultipoleT.h:144
BGeometryBase & getGeometry() override
void setScalingModel(const std::shared_ptr< AbstractTimeDependence > &td)
Definition MultipoleT.h:261
bool bends() const override
double getRotation() const
Definition MultipoleT.h:213
void initialiseTimeDepencencies() const
std::shared_ptr< AbstractTimeDependence > scalingTD_m
Definition MultipoleT.h:300
double getFnDerivS(const std::size_t &n, const double &x, const double &s)
double getFnDerivX(const std::size_t &n, const double &x, const double &s)
void chooseImplementation()
bool variableRadius_m
Definition MultipoleT.h:290
bool insideBoundingBox(const Vector_t &R) const
double boundingBoxLength_m
Definition MultipoleT.h:291
MultipoleT(const std::string &name)
std::string getScalingName() const
Definition MultipoleT.h:262
double getEntranceAngle() const
Definition MultipoleT.h:189
void setFringeField(const double &s0, const double &lambda_left, const double &lambda_right)
std::tuple< double, double, double > getFringeField() const
double getBendAngle() const
Definition MultipoleT.h:187
void setEntryOffset(double offset)
double horizontalApert_m
Definition MultipoleT.h:295
void setBoundingBoxLength(double boundingBoxLength)
double getEntryOffset() const
Definition MultipoleT.h:181
void setTransProfile(const std::vector< double > &profile)
void getDimensions(double &, double &) const override
Definition MultipoleT.h:221
std::unique_ptr< MultipoleTBase > implementation_
Definition MultipoleT.h:302
Abstract base class for accelerator geometry classes.
Definition Geometry.h:43
The magnetic field of a multipole.
Abstract base class for electromagnetic fields.
Definition EMField.h:188
Vektor< double, 3 > Vector_t