OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
32 SBend3D::SBend3D(const std::string &name)
33  : Component(name), map_m(NULL),
34  planarArcGeometry_m(1., 1.), fieldUnits_m(1.), lengthUnits_m(1.),
35  polyOrder_m(1), smoothOrder_m(1), dummy() {
37 }
38 
40  : Component(right), map_m(NULL),
41  planarArcGeometry_m(right.planarArcGeometry_m),
42  fieldUnits_m(right.fieldUnits_m), lengthUnits_m(right.lengthUnits_m),
43  polyOrder_m(right.polyOrder_m), smoothOrder_m(right.smoothOrder_m),
44  dummy() {
46  if (right.map_m != NULL)
47  map_m = new SectorMagneticFieldMap(*right.map_m);
49 }
50 
52  delete map_m;
53 }
54 
56  return new SBend3D(*this);
57 }
58 
59 
61  return dummy;
62 }
63 
64 const EMField &SBend3D::getField() const {
65  return dummy;
66 }
67 
68 bool SBend3D::apply(const size_t &i, const double &t,
69  Vector_t &E, Vector_t &B) {
70  return apply(RefPartBunch_m->R[i], RefPartBunch_m->P[i], t, E, B);
71 }
72 
73 bool SBend3D::apply(const Vector_t &R, const Vector_t &P,
74  const double &t, Vector_t &E, Vector_t &B) {
75  //std::cerr << "ROGERS SBend3D::apply " << R << " " << B << std::endl;
76  return map_m->getFieldstrength(R, E, B);
77 }
78 
79 void SBend3D::initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) {
80  RefPartBunch_m = bunch;
81 }
82 
84  RefPartBunch_m = NULL;
85 }
86 
87 bool SBend3D::bends() const {
88  return true;
89 }
90 
92  return planarArcGeometry_m;
93 }
94 
96  return planarArcGeometry_m;
97 }
98 
100  delete map_m;
101  map_m = NULL;
102 
103  if (name != "") {
105  name,
106  "Dipole",
108  fieldUnits_m,
109  polyOrder_m,
110  smoothOrder_m);
111  double r_curv = (map_m->getPolarBoundingBoxMax()[0]+
112  map_m->getPolarBoundingBoxMin()[0])/2.;
113  double delta_phi = map_m->getDeltaPhi();
114  planarArcGeometry_m.setElementLength(r_curv*delta_phi);
116  }
117 }
118 
119 void SBend3D::accept(BeamlineVisitor& visitor) const {
120  visitor.visitSBend3D(*this);
121 }
ParticleAttrib< Vector_t > P
EMField & getField() override
Definition: SBend3D.cpp:60
handles field map grids with sector geometry
Interface for basic beam line object.
Definition: ElementBase.h:128
bool getFieldstrength(const Vector_t &R_c, Vector_t &E_c, Vector_t &B_c) const
void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: SBend3D.cpp:79
void setCurvature(double)
Set curvature.
int polyOrder_m
Definition: SBend3D.h:168
void accept(BeamlineVisitor &visitor) const override
Definition: SBend3D.cpp:119
SBend3D(const std::string &name)
Definition: SBend3D.cpp:32
bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Definition: SBend3D.cpp:68
PlanarArcGeometry planarArcGeometry_m
Definition: SBend3D.h:163
double lengthUnits_m
Definition: SBend3D.h:166
double fieldUnits_m
Definition: SBend3D.h:165
Abstract base class for accelerator geometry classes.
Definition: Geometry.h:43
void setElType(ElemType elt)
set the element type as enumeration needed in the envelope tracker
Definition: ElementBase.h:591
void finalise() override
Definition: SBend3D.cpp:83
double smoothOrder_m
Definition: SBend3D.h:169
SectorMagneticFieldMap * map_m
Definition: SBend3D.h:161
~SBend3D()
Definition: SBend3D.cpp:51
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:200
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
BMultipoleField dummy
Definition: SBend3D.h:171
virtual std::vector< double > getPolarBoundingBoxMax() const
const std::string name
BGeometryBase & getGeometry() override
Definition: SBend3D.cpp:91
ParticlePos_t & R
Interface for a single beam element.
Definition: Component.h:51
ElementBase * clone() const override
Definition: SBend3D.cpp:55
virtual void setElementLength(double)
Set length.
virtual std::vector< double > getPolarBoundingBoxMin() const
Abstract algorithm.
bool bends() const override
Definition: SBend3D.cpp:87
virtual void visitSBend3D(const SBend3D &)=0
Apply the algorithm to a Sector Bend with 3D field map.
void setFieldMapFileName(std::string name)
Definition: SBend3D.cpp:99