OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Solenoid.cpp
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2// $RCSfile: Solenoid.cpp,v $
3// ------------------------------------------------------------------------
4// $Revision: 1.1.1.1 $
5// ------------------------------------------------------------------------
6// Copyright: see Copyright.readme
7// ------------------------------------------------------------------------
8//
9// Class: Solenoid
10// Defines the abstract interface for a solenoid magnet.
11//
12// ------------------------------------------------------------------------
13// Class category: AbsBeamline
14// ------------------------------------------------------------------------
15//
16// $Date: 2000/03/27 09:32:32 $
17// $Author: fci $
18//
19// ------------------------------------------------------------------------
20
24#include "Fields/Fieldmap.h"
25#include "Physics/Physics.h"
26
27#include <iostream>
28#include <fstream>
29
30extern Inform *gmsg;
31
32// Class Solenoid
33// ------------------------------------------------------------------------
34
36 Solenoid("")
37{}
38
39
41 Component(right),
42 filename_m(right.filename_m),
43 myFieldmap_m(right.myFieldmap_m),
44 scale_m(right.scale_m),
45 scaleError_m(right.scaleError_m),
46 startField_m(right.startField_m),
47 fast_m(right.fast_m) {
48}
49
50
51Solenoid::Solenoid(const std::string &name):
53 filename_m(""),
54 myFieldmap_m(nullptr),
55 scale_m(1.0),
56 scaleError_m(0.0),
57 startField_m(0.0),
58 fast_m(true) {
59}
60
61
63 // Fieldmap::deleteFieldmap(filename_m);
64}
65
66
67void Solenoid::accept(BeamlineVisitor &visitor) const {
68 visitor.visitSolenoid(*this);
69}
70
71void Solenoid::setFieldMapFN(std::string fn) {
72 filename_m = fn;
73}
74
75void Solenoid::setFast(bool fast) {
76 fast_m = fast;
77}
78
79
80bool Solenoid::getFast() const {
81 return fast_m;
82}
83
84bool Solenoid::apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) {
85 return apply(RefPartBunch_m->R[i], RefPartBunch_m->P[i], t, E, B);
86}
87
88bool Solenoid::apply(const Vector_t &R, const Vector_t &/*P*/, const double &/*t*/, Vector_t &/*E*/, Vector_t &B) {
89 if (R(2) >= startField_m
90 && R(2) < startField_m + getElementLength()) {
91 Vector_t tmpE(0.0, 0.0, 0.0), tmpB(0.0, 0.0, 0.0);
92
93 const bool outOfBounds = myFieldmap_m->getFieldstrength(R, tmpE, tmpB);
94 if (outOfBounds) {
96 }
97
98 B += (scale_m + scaleError_m) * tmpB;
99 }
100
101 return false;
102}
103
104bool Solenoid::applyToReferenceParticle(const Vector_t &R, const Vector_t &/*P*/, const double &/*t*/, Vector_t &/*E*/, Vector_t &B) {
105
106 if (R(2) >= startField_m
107 && R(2) < startField_m + getElementLength()) {
108 Vector_t tmpE(0.0, 0.0, 0.0), tmpB(0.0, 0.0, 0.0);
109
110 const bool outOfBounds = myFieldmap_m->getFieldstrength(R, tmpE, tmpB);
111 if (outOfBounds) return true;
112
113 B += scale_m * tmpB;
114 }
115
116 return false;
117}
118
119void Solenoid::initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) {
120 Inform msg("Solenoid ", *gmsg);
121
122 RefPartBunch_m = bunch;
123
125
126 if(myFieldmap_m != nullptr) {
127 msg << level2 << getName() << " using file ";
128 myFieldmap_m->getInfo(&msg);
129
130 double zBegin = 0.0, zEnd = 0.0;
131 myFieldmap_m->getFieldDimensions(zBegin, zEnd);
132
133 startField_m = zBegin;
134 setElementLength(zEnd - zBegin);
135 endField = startField + getElementLength();
136 } else {
137 endField = startField;
138 }
139}
140
142{}
143
144bool Solenoid::bends() const {
145 return false;
146}
147
148
149void Solenoid::goOnline(const double &) {
151 online_m = true;
152}
153
156 online_m = false;
157}
158
159void Solenoid::setKS(double ks) {
160 scale_m = ks;
161}
162
163void Solenoid::setDKS(double ks) {
164 scaleError_m = ks;
165}
166
167void Solenoid::getDimensions(double &zBegin, double &zEnd) const {
168 zBegin = startField_m;
170}
171
172
175}
176
177bool Solenoid::isInside(const Vector_t &r) const {
178 return isInsideTransverse(r)
179 && myFieldmap_m->isInside(r);
180}
181
183 double &end) const {
186}
Inform * gmsg
Definition: Main.cpp:61
ElementType
Definition: ElementBase.h:88
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
Inform & level2(Inform &inf)
Definition: Inform.cpp:46
const std::string name
ParticlePos_t & R
ParticleAttrib< Vector_t > P
virtual void visitSolenoid(const Solenoid &)=0
Apply the algorithm to a solenoid.
Interface for a single beam element.
Definition: Component.h:50
bool online_m
Definition: Component.h:192
PartBunchBase< double, 3 > * RefPartBunch_m
Definition: Component.h:191
virtual const std::string & getName() const
Get element name.
bool getFlagDeleteOnTransverseExit() const
Definition: ElementBase.h:613
virtual double getElementLength() const
Get design length.
Definition: ElementBase.h:414
virtual void setElementLength(double length)
Set design length.
Definition: ElementBase.h:418
bool isInsideTransverse(const Vector_t &r) const
Interface for solenoids.
Definition: Solenoid.h:36
virtual void getDimensions(double &zBegin, double &zEnd) const override
Definition: Solenoid.cpp:167
double scaleError_m
Definition: Solenoid.h:96
void setFast(bool fast)
Definition: Solenoid.cpp:75
virtual void getElementDimensions(double &zBegin, double &zEnd) const override
Definition: Solenoid.cpp:182
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) override
Definition: Solenoid.cpp:84
double startField_m
Definition: Solenoid.h:98
virtual void goOffline() override
Definition: Solenoid.cpp:154
virtual ~Solenoid()
Definition: Solenoid.cpp:62
virtual void goOnline(const double &kineticEnergy) override
Definition: Solenoid.cpp:149
virtual void finalise() override
Definition: Solenoid.cpp:141
bool fast_m
Definition: Solenoid.h:100
Fieldmap * myFieldmap_m
Definition: Solenoid.h:94
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) override
Definition: Solenoid.cpp:104
bool getFast() const
Definition: Solenoid.cpp:80
virtual bool bends() const override
Definition: Solenoid.cpp:144
void setDKS(double ks)
Definition: Solenoid.cpp:163
virtual ElementType getType() const override
Get element type std::string.
Definition: Solenoid.cpp:173
virtual bool isInside(const Vector_t &r) const override
Definition: Solenoid.cpp:177
Solenoid()
Definition: Solenoid.cpp:35
std::string filename_m
Definition: Solenoid.h:93
void setKS(double ks)
Definition: Solenoid.cpp:159
void setFieldMapFN(std::string fn)
Definition: Solenoid.cpp:71
virtual void accept(BeamlineVisitor &) const override
Apply visitor to Solenoid.
Definition: Solenoid.cpp:67
double scale_m
Definition: Solenoid.h:95
virtual void initialise(PartBunchBase< double, 3 > *bunch, double &startField, double &endField) override
Definition: Solenoid.cpp:119
virtual void getInfo(Inform *msg)=0
virtual void getFieldDimensions(double &zBegin, double &zEnd) const =0
static Fieldmap * getFieldmap(std::string Filename, bool fast=false)
Definition: Fieldmap.cpp:50
virtual bool isInside(const Vector_t &) const
Definition: Fieldmap.h:101
virtual void freeMap()=0
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const =0
virtual void readMap()=0
Definition: Inform.h:42