OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
TrackCmd.cpp
Go to the documentation of this file.
1//
2// Class TrackCmd
3// The class for the OPAL TRACK command.
4//
5// Copyright (c) 200x - 2022, Paul Scherrer Institut, Villigen PSI, Switzerland
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#include "Track/TrackCmd.h"
19
23#include "Structure/Beam.h"
24#include "Track/Track.h"
25#include "Track/TrackParser.h"
27
28
29namespace {
30 // The attributes of class TrackCmd
31 enum {
32 LINE, // The name of lattice to be tracked.
33 BEAM, // The name of beam to be used.
34 DT, // The integration timestep in second.
35 // In case of the adaptive integrator, time step guideline for
36 // external field integration.
37 DTSCINIT, // Only for adaptive integrator: Initial time step for space charge integration.
38 DTAU, // Only for adaptive integrator: Alternative way to set accuracy of space
39 // charge integration. Has no direct interpretation like DTSCINIT, but lower
40 // means smaller steps and more accurate. If given, DTSCINIT is not used. Useful
41 // for continuing with same step size in follow-up tracks.
42 T0, // The elapsed time (sec) of the bunch
43 MAXSTEPS, // The maximum timesteps we integrate
44 ZSTART, // Defines a z-location [m] where the reference particle starts
45 ZSTOP, // Defines a z-location [m], after which the simulation stops when the last particles passes
46 STEPSPERTURN, // Return the timsteps per revolution period. ONLY available for OPAL-cycl.
47 TIMEINTEGRATOR, // the name of time integrator
48 MAP_ORDER, // Truncation order of maps for ThickTracker (default: 1 (linear))
49 SIZE
50 };
51}
52
53const std::map<std::string, Steppers::TimeIntegrator> TrackCmd::stringTimeIntegrator_s = {
59};
60
61
63 Action(SIZE, "TRACK",
64 "The \"TRACK\" command initiates tracking.") {
66 ("LINE", "Name of lattice to be tracked.");
67
69 ("BEAM", "Name of beam to be used.", "UNNAMED_BEAM");
70
72 ("DT", "The integration timestep in [s].");
73
75 ("DTSCINIT", "Only for adaptive integrator: Initial time step for space charge integration.", 1e-12);
76
78 ("DTAU", "Only for adaptive integrator: Alternative way to set accuracy of space integration.", -1.0);
79
81 ("T0", "The elapsed time of the bunch in seconds", 0.0);
82
84 ("MAXSTEPS", "The maximum number of integration steps dt, should be larger ZSTOP/(beta*c average).");
85
87 ("ZSTART", "Defines a z-location [m] where the reference particle starts.", 0.0);
88
90 ("ZSTOP", "Defines a z-location [m], after which the simulation stops when the last particles passes.");
91
92 itsAttr[STEPSPERTURN] = Attributes::makeReal
93 ("STEPSPERTURN", "The time steps per revolution period, only for opal-cycl.", 720);
94
96 ("TIMEINTEGRATOR", "Name of time integrator to be used.",
97 {"RK-4", "RK4", "LF-2", "LF2", "MTS"}, "RK4");
98
99 itsAttr[MAP_ORDER] = Attributes::makeReal
100 ("MAP_ORDER", "Truncation order of maps for ThickTracker (default: 1, i.e. linear).", 1);
101
105}
106
107TrackCmd::TrackCmd(const std::string& name, TrackCmd* parent):
108 Action(name, parent)
109{}
110
111
113{}
114
115
116TrackCmd* TrackCmd::clone(const std::string& name) {
117 return new TrackCmd(name, this);
118}
119
120std::vector<double> TrackCmd::getDT() const {
121 std::vector<double> dTs = Attributes::getRealArray(itsAttr[DT]);
122 if (dTs.size() == 0) {
123 dTs.push_back(1e-12);
124 }
125 for (double dt : dTs) {
126 if (dt < 0.0) {
127 throw OpalException("TrackCmd::getDT",
128 "The time steps provided with DT have to be positive");
129 }
130 }
131 return dTs;
132}
133
134double TrackCmd::getDTSCINIT() const {
135 return Attributes::getReal(itsAttr[DTSCINIT]);
136}
137
138double TrackCmd::getDTAU() const {
139 return Attributes::getReal(itsAttr[DTAU]);
140}
141
142double TrackCmd::getT0() const {
143 return Attributes::getReal(itsAttr[T0]);
144}
145
146double TrackCmd::getZStart() const {
147 return Attributes::getReal(itsAttr[ZSTART]);
148}
149
150std::vector<double> TrackCmd::getZStop() const {
151 std::vector<double> zstop = Attributes::getRealArray(itsAttr[ZSTOP]);
152 if (zstop.size() == 0) {
153 zstop.push_back(1000000.0);
154 }
155 return zstop;
156}
157
158std::vector<unsigned long long> TrackCmd::getMaxSteps() const {
159 std::vector<double> maxsteps_d = Attributes::getRealArray(itsAttr[MAXSTEPS]);
160 std::vector<unsigned long long> maxsteps_i;
161 if (maxsteps_d.size() == 0) {
162 maxsteps_i.push_back(10ul);
163 }
164 for (double numSteps : maxsteps_d) {
165 if (numSteps < 0) {
166 throw OpalException("TrackCmd::getMAXSTEPS",
167 "The number of steps provided with MAXSTEPS has to be positive");
168 } else {
169 unsigned long long value = numSteps;
170 maxsteps_i.push_back(value);
171 }
172 }
173
174 return maxsteps_i;
175}
176
178 return (int) Attributes::getReal(itsAttr[STEPSPERTURN]);
179}
180
182 std::string name = Attributes::getString(itsAttr[TIMEINTEGRATOR]);
183 return stringTimeIntegrator_s.at(name);
184}
185
186void TrackCmd::setIsParseable(bool isParseable) {
187 isParseable_m = isParseable;
188}
189
190
192 // Find BeamSequence and Beam definitions.
195
196 std::vector<double> dt = getDT();
197 double t0 = getT0();
198 double dtScInit = getDTSCINIT();
199 double deltaTau = getDTAU();
200 std::vector<unsigned long long> maxsteps = getMaxSteps();
201 int stepsperturn = getStepsPerTurn();
202 double zstart = getZStart();
203 std::vector<double> zstop = getZStop();
205
206 size_t numTracks = dt.size();
207 numTracks = std::max(numTracks, maxsteps.size());
208 numTracks = std::max(numTracks, zstop.size());
209 for (size_t i = dt.size(); i < numTracks; ++ i) {
210 dt.push_back(dt.back());
211 }
212 for (size_t i = maxsteps.size(); i < numTracks; ++i) {
213 maxsteps.push_back(maxsteps.back());
214 }
215 for (size_t i = zstop.size(); i < numTracks; ++i) {
216 zstop.push_back(zstop.back());
217 }
218
219 // Execute track block.
220 if (Track::block != nullptr) {
221 delete Track::block;
222 Track::block = nullptr;
223 }
224 Track::block = new Track(use, beam->getReference(), dt, maxsteps,
225 stepsperturn, zstart, zstop,
226 timeintegrator, t0, dtScInit, deltaTau);
227
229 if (isParseable_m) {
231 // Clean up.
232 delete Track::block;
233 Track::block = 0;
234 }
235}
@ SIZE
Definition: IndexMap.cpp:174
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
const std::string name
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Definition: Attributes.cpp:409
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
constexpr double e
The value of.
Definition: Physics.h:39
TimeIntegrator
Definition: Steppers.h:25
The base class for all OPAL actions.
Definition: Action.h:30
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
The base class for all OPAL beam lines and sequences.
Definition: BeamSequence.h:32
static BeamSequence * find(const std::string &name)
Find a BeamSequence by name.
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:602
Definition: Beam.h:31
static Beam * find(const std::string &name)
Find named BEAM.
Definition: Beam.cpp:156
const PartData & getReference() const
Return the embedded CLASSIC PartData.
Definition: Beam.cpp:175
Definition: Track.h:36
static Track * block
The block of track data.
Definition: Track.h:59
TrackParser parser
The parser used during tracking.
Definition: Track.h:56
int truncOrder
Trunction order for map tracking.
Definition: Track.h:90
double getDTSCINIT() const
Definition: TrackCmd.cpp:134
virtual TrackCmd * clone(const std::string &name)
Return a clone.
Definition: TrackCmd.cpp:116
std::vector< double > getDT() const
Return the timestep in seconds.
Definition: TrackCmd.cpp:120
int getStepsPerTurn() const
Definition: TrackCmd.cpp:177
std::vector< double > getZStop() const
location at which the simulation stops
Definition: TrackCmd.cpp:150
virtual void execute()
Execute the command.
Definition: TrackCmd.cpp:191
virtual ~TrackCmd()
Definition: TrackCmd.cpp:112
TrackCmd()
Definition: TrackCmd.cpp:62
double getT0() const
Return the elapsed time (sec) of the bunch.
Definition: TrackCmd.cpp:142
bool isParseable_m
Definition: TrackCmd.h:76
double getDTAU() const
Definition: TrackCmd.cpp:138
Steppers::TimeIntegrator getTimeIntegrator()
return the name of time integrator
Definition: TrackCmd.cpp:181
double getZStart() const
location at which the simulation starts
Definition: TrackCmd.cpp:146
static const std::map< std::string, Steppers::TimeIntegrator > stringTimeIntegrator_s
Definition: TrackCmd.h:77
std::vector< unsigned long long > getMaxSteps() const
Return the maximum timsteps we integrate the system.
Definition: TrackCmd.cpp:158
void setIsParseable(bool isParseable)
set the IsParseable flag
Definition: TrackCmd.cpp:186
The base class for all OPAL exceptions.
Definition: OpalException.h:28