OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Offset.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, 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 
29 #ifndef CLASSIC_ABSBEAMLINE_Offset_HH
30 #define CLASSIC_ABSBEAMLINE_Offset_HH
31 
32 #include "Fields/EMField.h"
34 #include "AbsBeamline/Component.h"
35 
36 #include <string>
37 
66 class Offset : public Component {
67  public:
71  explicit Offset(const std::string &name);
72 
76  Offset();
77 
81  Offset(std::string name, const Offset &);
82 
86  Offset(const Offset &);
87 
91  Offset& operator=(const Offset &);
92 
102  static Offset localCylindricalOffset(std::string name,
103  double theta_in,
104  double theta_out,
105  double displacement);
106 
116  static Offset globalCylindricalOffset(std::string name,
117  double radius_out,
118  double phi_out,
119  double theta_out);
120 
127  static Offset localCartesianOffset(std::string name,
128  Vector_t end_position,
129  Vector_t end_direction);
130 
139  static Offset globalCartesianOffset(std::string name,
140  Vector_t end_position,
141  Vector_t end_direction);
142 
144  ~Offset();
145 
150  void accept(BeamlineVisitor &) const override;
151 
153  ElementBase* clone() const override;
154 
158  bool bends() const override;
159 
160  void initialise(PartBunchBase<double, 3> *bunch, double &startField,
161  double &endField) override;
162  void finalise() override;
163  void getDimensions(double &zBegin, double &zEnd) const override {}
164 
165  void setEndPosition(Vector_t position);
166  Vector_t getEndPosition() const;
167 
168  void setEndDirection(Vector_t direction);
169  Vector_t getEndDirection() const;
170 
174  void setIsLocal(bool isLocal);
175 
179  bool getIsLocal() const;
180 
181  Euclid3DGeometry& getGeometry() override;
182  const Euclid3DGeometry& getGeometry() const override;
183  void updateGeometry(Vector_t startPosition, Vector_t startDirection);
184  void updateGeometry();
185  bool isGeometryAllocated() const;
186 
188  EMField &getField() override;
190  const EMField &getField() const override;
199  static double getTheta(Vector_t vec1, Vector_t vec2);
200 
204  static Vector_t rotate(Vector_t vec, double theta);
205 
206  static double float_tolerance;
207  private:
210  bool _is_local;
211  // The offset's geometry.
213  static const double lengthUnits_m;
214 };
215 
218 bool operator==(const Offset& off1, const Offset& off2);
219 
221 bool operator!=(const Offset& off1, const Offset& off2);
222 
224 std::ostream& operator<<(std::ostream& out, const Offset& off1);
225 
226 #endif // CLASSIC_ABSBEAMLINE_Offset_HH
void finalise() override
Definition: Offset.cpp:104
std::ostream & operator<<(std::ostream &os, const Attribute &attr)
Definition: Attribute.cpp:167
Interface for basic beam line object.
Definition: ElementBase.h:128
static double float_tolerance
Definition: Offset.h:206
Definition: Offset.h:66
static Offset localCylindricalOffset(std::string name, double theta_in, double theta_out, double displacement)
Definition: Offset.cpp:254
Vector_t getEndPosition() const
Definition: Offset.cpp:116
static Offset globalCylindricalOffset(std::string name, double radius_out, double phi_out, double theta_out)
Definition: Offset.cpp:269
void setEndDirection(Vector_t direction)
Definition: Offset.cpp:120
void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: Offset.cpp:100
Euclid3DGeometry & getGeometry() override
Get geometry.
Definition: Offset.cpp:136
~Offset()
Definition: Offset.cpp:61
void updateGeometry()
Definition: Offset.cpp:168
ElementBase * clone() const override
Definition: Offset.cpp:108
static Offset globalCartesianOffset(std::string name, Vector_t end_position, Vector_t end_direction)
Definition: Offset.cpp:297
Offset & operator=(const Offset &)
Definition: Offset.cpp:65
Vector_t _end_position
Definition: Offset.h:208
bool _is_local
Definition: Offset.h:210
static Offset localCartesianOffset(std::string name, Vector_t end_position, Vector_t end_direction)
Definition: Offset.cpp:285
bool bends() const override
Definition: Offset.cpp:236
Abstract base class for electromagnetic fields.
Definition: EMField.h:188
Offset()
Definition: Offset.cpp:46
bool operator!=(const Offset &off1, const Offset &off2)
Definition: Offset.cpp:225
Definition: Vec.h:21
void getDimensions(double &zBegin, double &zEnd) const override
Definition: Offset.h:163
bool getIsLocal() const
Definition: Offset.cpp:132
const std::string name
Vector_t _end_direction
Definition: Offset.h:209
Euclid3DGeometry * geometry_m
Definition: Offset.h:212
static const double lengthUnits_m
Definition: Offset.h:213
Vector_t getEndDirection() const
Definition: Offset.cpp:124
void accept(BeamlineVisitor &) const override
Definition: Offset.cpp:86
Interface for a single beam element.
Definition: Component.h:51
Abstract algorithm.
void setIsLocal(bool isLocal)
Definition: Offset.cpp:128
static double getTheta(Vector_t vec1, Vector_t vec2)
Definition: Offset.cpp:149
EMField & getField() override
Not implemented - throws GeneralClassicException.
Definition: Offset.cpp:90
void setEndPosition(Vector_t position)
Definition: Offset.cpp:112
bool isGeometryAllocated() const
Definition: Offset.cpp:196
bool operator==(const TwoPolynomial &left, const TwoPolynomial &right)
static Vector_t rotate(Vector_t vec, double theta)
Definition: Offset.cpp:160