OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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"
41 #include "AbsBeamline/Probe.h"
42 #include "AbsBeamline/RBend.h"
43 #include "AbsBeamline/RBend3D.h"
44 #include "AbsBeamline/RFCavity.h"
45 #include "AbsBeamline/Ring.h"
46 #include "AbsBeamline/SBend.h"
47 #include "AbsBeamline/SBend3D.h"
49 #include "AbsBeamline/Septum.h"
50 #include "AbsBeamline/Solenoid.h"
51 #include "AbsBeamline/Source.h"
52 #include "AbsBeamline/Stripper.h"
54 #include "AbsBeamline/Vacuum.h"
58 
59 #ifdef ENABLE_OPAL_FEL
60 #include "AbsBeamline/Undulator.h"
61 #endif
62 
63 #include "Beamlines/Beamline.h"
65 
66 
67 
69  bool backBeam, bool backTrack):
70  itsLine(beamline), back_beam(backBeam), back_track(backTrack) {
72  ( back_beam && ! back_track ) || ( back_track && ! back_beam );
73  flip_B = back_beam ? -1.0 : 1.0;
74  flip_s = back_path ? -1.0 : 1.0;
75 }
76 
77 
79 {}
80 
81 
83  local_flip = ( back_beam && ! back_track ) || ( back_track && ! back_beam );
84  itsLine.accept(*this);
85 }
86 
87 
89  applyDefault(coll);
90 }
91 
93  applyDefault(comp);
94 }
95 
97  applyDefault(corr);
98 }
99 
101  applyDefault(cyc);
102 }
103 
105  applyDefault(deg);
106 }
107 
109  applyDefault(drf);
110 }
111 
113  applyDefault(coll);
114 }
115 
117  applyDefault(mark);
118 }
119 
121  applyDefault(mon);
122 }
123 
125  applyDefault(mult);
126 }
127 
129  applyDefault(multT);
130 }
131 
133  applyDefault(multTstraight);
134 }
135 
137  applyDefault(multTccurv);
138 }
139 
141  applyDefault(multTvcurv);
142 }
143 
145  applyDefault(off);
146 }
147 
149  applyDefault(out);
150 }
151 
152 void DefaultVisitor::visitProbe(const Probe &probe) {
153  applyDefault(probe);
154 }
155 
157  applyDefault(bend);
158 }
159 
161  applyDefault(bend);
162 }
163 
165  applyDefault(cav);
166 }
167 
168 void DefaultVisitor::visitRing(const Ring &ring) {
169  applyDefault(ring);
170 }
171 
173  applyDefault(bend);
174 }
175 
177  applyDefault(bend);
178 }
179 
181  applyDefault(spiral);
182 }
183 
185  applyDefault(sept);
186 }
187 
189  applyDefault(sol);
190 }
191 
193  applyDefault(sou);
194 }
195 
197  applyDefault(stripper);
198 }
199 
201  applyDefault(trw);
202 }
203 
204 #ifdef ENABLE_OPAL_FEL
205 void DefaultVisitor::visitUndulator(const Undulator &u) {
206  applyDefault(u);
207 }
208 #endif
209 
211  applyDefault(vac);
212 }
213 
215  applyDefault(vcav);
216 }
217 
220  applyDefault(vcav);
221 }
222 
224  applyDefault(mag);
225 }
226 
227 
229  // Default behaviour: Apply algorithm to all beamline members.
230  // If flip_local is true, track from right to left.
231  bl.iterate(*this, local_flip);
232 }
233 
234 
236  if(fep.getReflectionFlag()) {
238  fep.getElement()->accept(*this);
240  } else {
241  fep.getElement()->accept(*this);
242  }
243 }
244 
245 
247 {}
virtual void visitVariableRFCavity(const VariableRFCavity &vcav)
Apply the algorithm to a a variable RF cavity.
virtual void visitDrift(const Drift &)
Apply the algorithm to a drift space.
virtual void visitVariableRFCavityFringeField(const VariableRFCavityFringeField &vcav)
Apply the algorithm to a a variable RF cavity with Fringe Field.
virtual void execute()
Apply the algorithm to the top-level beamline.
virtual void visitCyclotron(const Cyclotron &)
Apply the algorithm to an cyclotron.
Interface for a marker.
Definition: Marker.h:32
virtual void visitDegrader(const Degrader &)
Apply the algorithm to a degrader.
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
Interface for solenoids.
Definition: Solenoid.h:36
virtual void visitVerticalFFAMagnet(const VerticalFFAMagnet &)
Apply the algorithm to a vertical FFA magnet.
virtual void visitSource(const Source &)
Apply the algorithm to a source.
virtual ~DefaultVisitor()=0
Definition: Offset.h:53
Interface for solenoids.
Definition: RBend3D.h:39
ElementBase * getElement() const
Get the element pointer.
Definition: ElmPtr.h:58
An abstract sequence of beam line components.
Definition: Beamline.h:34
Interface for general multipole.
Definition: Multipole.h:47
Interface for drift space.
Definition: Drift.h:33
virtual void visitBeamline(const Beamline &)
Apply the algorithm to a beam line.
Definition: SBend.h:68
Interface for general corrector.
Definition: Corrector.h:35
Definition: Vacuum.h:61
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a multipole.
virtual void iterate(BeamlineVisitor &, bool reverse) const =0
Apply visitor to all elements of the line.
virtual void visitFlaggedElmPtr(const FlaggedElmPtr &)
Apply the algorithm to a FlaggedElmPtr.
virtual void visitTravelingWave(const TravelingWave &)
Apply the algorithm to a traveling wave.
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
virtual void applyDefault(const ElementBase &)
virtual void visitSBend3D(const SBend3D &)
Apply the algorithm to a sector bend with 3D field map.
virtual void visitStripper(const Stripper &)
Apply the algorithm to a particle stripper.
virtual void visitMultipoleTCurvedVarRadius(const MultipoleTCurvedVarRadius &)
Apply the algorithm to an arbitrary curved multipole of variable radius.
virtual void visitScalingFFAMagnet(const ScalingFFAMagnet &)
Apply the algorithm to a scaling FFA magnet.
virtual void visitRing(const Ring &)
Apply the algorithm to a ring.
const Beamline & itsLine
virtual void visitMultipoleT(const MultipoleT &)
Apply the algorithm to to an arbitrary multipole.
virtual void visitMarker(const Marker &)
Apply the algorithm to a marker.
virtual void visitFlexibleCollimator(const FlexibleCollimator &)
Apply the algorithm to a flexible collimator.
virtual void visitMonitor(const Monitor &)
Apply the algorithm to a beam position monitor.
virtual void visitSeptum(const Septum &)
Apply the algorithm to a septum.
virtual void visitRBend3D(const RBend3D &)
Apply the algorithm to a rectangular bend.
Definition: RBend.h:58
virtual void visitSolenoid(const Solenoid &)
Apply the algorithm to a solenoid.
Definition: Source.h:30
T deg(T x)
Convert radians to degrees.
Definition: matheval.hpp:75
virtual void visitOutputPlane(const OutputPlane &)
Apply the algorithm to an output plane.
virtual void visitSBend(const SBend &)
Apply the algorithm to a sector bend.
Definition: Probe.h:28
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a closed orbit corrector.
virtual void visitOffset(const Offset &)
Apply the algorithm to an offset (placement).
virtual void visitMultipoleTCurvedConstRadius(const MultipoleTCurvedConstRadius &)
Apply the algorithm to an arbitrary curved multipole of constant radius.
virtual void visitVacuum(const Vacuum &)
Apply the algorithm to a vacuum space.
A section of a beam line.
Definition: FlaggedElmPtr.h:36
Ring describes a ring type geometry for tracking.
Definition: Ring.h:53
Definition: Septum.h:23
Interface for a single beam element.
Definition: Component.h:50
virtual void visitMultipoleTStraight(const MultipoleTStraight &)
Apply the algorithm to an arbitrary straight multipole.
virtual void visitProbe(const Probe &prob)
Apply the algorithm to a probe.
virtual void visitCCollimator(const CCollimator &)
Apply the algorithm to a collimator.
virtual void visitComponent(const Component &)
Apply the algorithm to an arbitrary component.
bool getReflectionFlag() const
Get reflection flag.
virtual void visitRFCavity(const RFCavity &)
Apply the algorithm to a RF cavity.