OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SBend3D.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012, Chris Rogers
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "AbsBeamline/SBend3D.h"
31
32SBend3D::SBend3D(const std::string &name)
33 : Component(name), map_m(nullptr),
34 planarArcGeometry_m(1., 1.), fieldUnits_m(1.), lengthUnits_m(1.),
35 polyOrder_m(1), smoothOrder_m(1), dummy() {
36}
37
39 : Component(right), map_m(nullptr),
40 planarArcGeometry_m(right.planarArcGeometry_m),
41 fieldUnits_m(right.fieldUnits_m), lengthUnits_m(right.lengthUnits_m),
42 polyOrder_m(right.polyOrder_m), smoothOrder_m(right.smoothOrder_m),
43 dummy() {
45 if (right.map_m != nullptr)
47}
48
50 delete map_m;
51}
52
54 return new SBend3D(*this);
55}
56
57
59 return dummy;
60}
61
62const EMField &SBend3D::getField() const {
63 return dummy;
64}
65
66bool SBend3D::apply(const size_t &i, const double &t,
67 Vector_t &E, Vector_t &B) {
68 return apply(RefPartBunch_m->R[i], RefPartBunch_m->P[i], t, E, B);
69}
70
71bool SBend3D::apply(const Vector_t &R, const Vector_t &/*P*/,
72 const double &/*t*/, Vector_t &E, Vector_t &B) {
73 //std::cerr << "ROGERS SBend3D::apply " << R << " " << B << std::endl;
74 return map_m->getFieldstrength(R, E, B);
75}
76
77void SBend3D::initialise(PartBunchBase<double, 3> *bunch, double &/*startField*/, double &/*endField*/) {
78 RefPartBunch_m = bunch;
79}
80
82 RefPartBunch_m = nullptr;
83}
84
85bool SBend3D::bends() const {
86 return true;
87}
88
91}
92
95}
96
97void SBend3D::setFieldMapFileName(const std::string& name) {
98 delete map_m;
99 map_m = nullptr;
100
101 if (!name.empty()) {
103 name,
104 "Dipole",
109 double r_curv = (map_m->getPolarBoundingBoxMax()[0]+
111 double delta_phi = map_m->getDeltaPhi();
112 planarArcGeometry_m.setElementLength(r_curv*delta_phi);
114 }
115}
116
117void SBend3D::accept(BeamlineVisitor& visitor) const {
118 visitor.visitSBend3D(*this);
119}
const std::string name
ParticlePos_t & R
ParticleAttrib< Vector_t > P
virtual void visitSBend3D(const SBend3D &)=0
Apply the algorithm to a sector bend with 3D field map.
Interface for a single beam element.
Definition: Component.h:50
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
BMultipoleField dummy
Definition: SBend3D.h:171
void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: SBend3D.cpp:77
int polyOrder_m
Definition: SBend3D.h:168
double lengthUnits_m
Definition: SBend3D.h:166
ElementBase * clone() const override
Definition: SBend3D.cpp:53
double smoothOrder_m
Definition: SBend3D.h:169
void accept(BeamlineVisitor &visitor) const override
Definition: SBend3D.cpp:117
EMField & getField() override
Definition: SBend3D.cpp:58
bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Definition: SBend3D.cpp:66
void setFieldMapFileName(const std::string &name)
Definition: SBend3D.cpp:97
SBend3D(const std::string &name)
Definition: SBend3D.cpp:32
double fieldUnits_m
Definition: SBend3D.h:165
PlanarArcGeometry planarArcGeometry_m
Definition: SBend3D.h:163
void finalise() override
Definition: SBend3D.cpp:81
SectorMagneticFieldMap * map_m
Definition: SBend3D.h:161
BGeometryBase & getGeometry() override
Definition: SBend3D.cpp:89
~SBend3D()
Definition: SBend3D.cpp:49
bool bends() const override
Definition: SBend3D.cpp:85
Abstract base class for accelerator geometry classes.
Definition: Geometry.h:43
void setCurvature(double)
Set curvature.
virtual void setElementLength(double)
Set length.
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
virtual std::vector< double > getPolarBoundingBoxMin() const
virtual std::vector< double > getPolarBoundingBoxMax() const
handles field map grids with sector geometry
bool getFieldstrength(const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const