OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
DefaultVisitor.cpp
Go to the documentation of this file.
1 //
2 // Class DefaultVisitor
3 // The default interface for a BeamlineVisitor.
4 // A default implementation for all visitors that can iterate over a
5 // beam line representation.
6 // This abstract base class implements the default behaviour for the
7 // structural classes Beamline and FlaggedElmPtr.
8 // It also holds the data required for all visitors in a protected area.
9 //
10 // Copyright (c) 200x - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
11 // All rights reserved
12 //
13 // This file is part of OPAL.
14 //
15 // OPAL is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
22 //
24 
26 #include "AbsBeamline/Corrector.h"
27 #include "AbsBeamline/Cyclotron.h"
28 #include "AbsBeamline/Degrader.h"
29 #include "AbsBeamline/Drift.h"
32 #include "AbsBeamline/Marker.h"
33 #include "AbsBeamline/Monitor.h"
34 #include "AbsBeamline/Multipole.h"
35 #include "AbsBeamline/MultipoleT.h"
39 #include "AbsBeamline/Offset.h"
40 #include "AbsBeamline/Probe.h"
41 #include "AbsBeamline/RBend.h"
42 #include "AbsBeamline/RBend3D.h"
43 #include "AbsBeamline/RFCavity.h"
44 #include "AbsBeamline/Ring.h"
45 #include "AbsBeamline/SBend.h"
46 #include "AbsBeamline/SBend3D.h"
48 #include "AbsBeamline/Septum.h"
49 #include "AbsBeamline/Solenoid.h"
50 #include "AbsBeamline/Source.h"
51 #include "AbsBeamline/Stripper.h"
53 #include "AbsBeamline/Vacuum.h"
57 
58 #ifdef ENABLE_OPAL_FEL
59 #include "AbsBeamline/Undulator.h"
60 #endif
61 
62 #include "Beamlines/Beamline.h"
64 
65 
66 
68  bool backBeam, bool backTrack):
69  itsLine(beamline), back_beam(backBeam), back_track(backTrack) {
71  ( back_beam && ! back_track ) || ( back_track && ! back_beam );
72  flip_B = back_beam ? -1.0 : 1.0;
73  flip_s = back_path ? -1.0 : 1.0;
74 }
75 
76 
78 {}
79 
80 
82  local_flip = ( back_beam && ! back_track ) || ( back_track && ! back_beam );
83  itsLine.accept(*this);
84 }
85 
86 
88  applyDefault(coll);
89 }
90 
92  applyDefault(comp);
93 }
94 
96  applyDefault(corr);
97 }
98 
100  applyDefault(cyc);
101 }
102 
104  applyDefault(deg);
105 }
106 
108  applyDefault(drf);
109 }
110 
112  applyDefault(coll);
113 }
114 
116  applyDefault(mark);
117 }
118 
120  applyDefault(mon);
121 }
122 
124  applyDefault(mult);
125 }
126 
128  applyDefault(multT);
129 }
130 
132  applyDefault(multTstraight);
133 }
134 
136  applyDefault(multTccurv);
137 }
138 
140  applyDefault(multTvcurv);
141 }
142 
144  applyDefault(off);
145 }
146 
147 void DefaultVisitor::visitProbe(const Probe &probe) {
148  applyDefault(probe);
149 }
150 
152  applyDefault(bend);
153 }
154 
156  applyDefault(bend);
157 }
158 
160  applyDefault(cav);
161 }
162 
163 void DefaultVisitor::visitRing(const Ring &ring) {
164  applyDefault(ring);
165 }
166 
168  applyDefault(bend);
169 }
170 
172  applyDefault(bend);
173 }
174 
176  applyDefault(spiral);
177 }
178 
180  applyDefault(sept);
181 }
182 
184  applyDefault(sol);
185 }
186 
188  applyDefault(sou);
189 }
190 
192  applyDefault(stripper);
193 }
194 
196  applyDefault(trw);
197 }
198 
199 #ifdef ENABLE_OPAL_FEL
200 void DefaultVisitor::visitUndulator(const Undulator &u) {
201  applyDefault(u);
202 }
203 #endif
204 
206  applyDefault(vac);
207 }
208 
210  applyDefault(vcav);
211 }
212 
214  (const VariableRFCavityFringeField &vcav) {
215  applyDefault(vcav);
216 }
217 
219  applyDefault(mag);
220 }
221 
222 
224  // Default behaviour: Apply algorithm to all beamline members.
225  // If flip_local is true, track from right to left.
226  bl.iterate(*this, local_flip);
227 }
228 
229 
231  if(fep.getReflectionFlag()) {
233  fep.getElement()->accept(*this);
235  } else {
236  fep.getElement()->accept(*this);
237  }
238 }
239 
240 
242 {}
T deg(T x)
Convert radians to degrees.
Definition: matheval.hpp:74
Interface for a single beam element.
Definition: Component.h:50
Interface for general corrector.
Definition: Corrector.h:35
Interface for drift space.
Definition: Drift.h:33
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
Interface for a marker.
Definition: Marker.h:32
Interface for general multipole.
Definition: Multipole.h:47
Definition: Offset.h:66
Definition: Probe.h:28
Definition: RBend.h:58
Interface for solenoids.
Definition: RBend3D.h:39
Interface for RF cavity.
Definition: RFCavity.h:37
Ring describes a ring type geometry for tracking.
Definition: Ring.h:64
Definition: SBend.h:68
Definition: Septum.h:23
Interface for solenoids.
Definition: Solenoid.h:36
Definition: Source.h:30
Interface for Traveling Wave.
Definition: TravelingWave.h:37
Definition: Vacuum.h:67
virtual void visitProbe(const Probe &prob)
Apply the algorithm to a probe.
virtual ~DefaultVisitor()=0
virtual void visitDegrader(const Degrader &)
Apply the algorithm to a degrader.
virtual void visitOffset(const Offset &)
Apply the algorithm to an offset (placement).
virtual void visitDrift(const Drift &)
Apply the algorithm to a drift space.
virtual void visitRBend3D(const RBend3D &)
Apply the algorithm to a rectangular bend.
virtual void visitComponent(const Component &)
Apply the algorithm to an arbitrary component.
virtual void visitVariableRFCavity(const VariableRFCavity &vcav)
Apply the algorithm to a a variable RF cavity.
virtual void visitVacuum(const Vacuum &)
Apply the algorithm to a vacuum space.
virtual void visitFlexibleCollimator(const FlexibleCollimator &)
Apply the algorithm to a flexible collimator.
virtual void visitRFCavity(const RFCavity &)
Apply the algorithm to a RF cavity.
virtual void visitSBend3D(const SBend3D &)
Apply the algorithm to a sector bend with 3D field map.
virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &)
Apply the algorithm to a scaling FFA magnet.
virtual void visitMarker(const Marker &)
Apply the algorithm to a marker.
virtual void visitVariableRFCavityFringeField(const VariableRFCavityFringeField &vcav)
Apply the algorithm to a a variable RF cavity with Fringe Field.
virtual void visitMultipoleTCurvedVarRadius(const MultipoleTCurvedVarRadius &)
Apply the algorithm to an arbitrary curved multipole of variable radius.
virtual void visitTravelingWave(const TravelingWave &)
Apply the algorithm to a traveling wave.
virtual void visitMultipoleTCurvedConstRadius(const MultipoleTCurvedConstRadius &)
Apply the algorithm to an arbitrary curved multipole of constant radius.
virtual void visitSeptum(const Septum &)
Apply the algorithm to a septum.
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a closed orbit corrector.
virtual void visitMonitor(const Monitor &)
Apply the algorithm to a beam position monitor.
virtual void visitFlaggedElmPtr(const FlaggedElmPtr &)
Apply the algorithm to a FlaggedElmPtr.
virtual void visitSBend(const SBend &)
Apply the algorithm to a sector bend.
virtual void applyDefault(const ElementBase &)
virtual void visitCCollimator(const CCollimator &)
Apply the algorithm to a collimator.
virtual void visitSolenoid(const Solenoid &)
Apply the algorithm to a solenoid.
const Beamline & itsLine
virtual void visitSource(const Source &)
Apply the algorithm to a source.
virtual void visitBeamline(const Beamline &)
Apply the algorithm to a beam line.
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
virtual void visitMultipoleT(const MultipoleT &)
Apply the algorithm to to an arbitrary multipole.
virtual void visitVerticalFFAMagnet(const VerticalFFAMagnet &)
Apply the algorithm to a vertical FFA magnet.
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a multipole.
virtual void visitCyclotron(const Cyclotron &)
Apply the algorithm to an cyclotron.
virtual void execute()
Apply the algorithm to the top-level beamline.
virtual void visitRing(const Ring &)
Apply the algorithm to a ring.
virtual void visitMultipoleTStraight(const MultipoleTStraight &)
Apply the algorithm to an arbitrary straight multipole.
virtual void visitStripper(const Stripper &)
Apply the algorithm to a particle stripper.
An abstract sequence of beam line components.
Definition: Beamline.h:34
virtual void iterate(BeamlineVisitor &, bool reverse) const =0
Apply visitor to all elements of the line.
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
A section of a beam line.
Definition: FlaggedElmPtr.h:36
bool getReflectionFlag() const
Get reflection flag.