OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
TrackCmd.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: TrackCmd.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: TrackCmd
10 // The class for the OPAL TRACK command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:47 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Track/TrackCmd.h"
22 #include "Attributes/Attributes.h"
23 #include "Structure/Beam.h"
24 #include "Track/Track.h"
25 #include "Track/TrackParser.h"
27 
28 // Class Track
29 // ------------------------------------------------------------------------
30 
31 namespace {
32 
33  // The attributes of class TrackRun.
34  enum {
35  LINE, // The name of lattice to be tracked.
36  BEAM, // The name of beam to be used.
37  DT, // The integration timestep in second.
38  // In case of the adaptive integrator, time step guideline for
39  // external field integration.
40  DTSCINIT, // Only for adaptive integrator: Initial time step for space charge integration.
41  DTAU, // Only for adaptive integrator: Alternative way to set accuracy of space
42  // charge integration. Has no direct interpretation like DTSCINIT, but lower
43  // means smaller steps and more accurate. If given, DTSCINIT is not used. Useful
44  // for continuing with same step size in follow-up tracks.
45  T0, // The elapsed time (sec) of the bunch
46  MAXSTEPS, // The maximum timesteps we integrate
47  ZSTART, // Defines a z-location [m] where the reference particle starts
48  ZSTOP, // Defines a z-location [m], after which the simulation stops when the last particles passes
49  STEPSPERTURN, // Return the timsteps per revolution period. ONLY available for OPAL-cycl.
50  TIMEINTEGRATOR, // the name of time integrator
51  MAP_ORDER, // Truncation order of maps for ThickTracker (default: 1 (linear))
52  SIZE
53  };
54 }
55 
57  Action(SIZE, "TRACK",
58  "The \"TRACK\" command initiates tracking.") {
60  ("LINE", "Name of lattice to be tracked");
62  ("BEAM", "Name of beam to be used", "UNNAMED_BEAM");
64  ("DT", "THE INTEGRATION TIMESTEP IN SECONDS");
65  itsAttr[DTSCINIT] = Attributes::makeReal
66  ("DTSCINIT", "Only for adaptive integrator: Initial time step for space charge integration", 1e-12);
68  ("DTAU", "Only for adaptive integrator: Alternative way to set accuracy of space integration.", -1.0);
70  ("T0", "THE ELAPSED TIME OF THE BUNCH IN SECONDS", 0.0);
72  ("MAXSTEPS", "THE MAXIMUM NUMBER OF INTEGRATION STEPS DT, should be larger ZSTOP/(beta*c average)");
73  itsAttr[STEPSPERTURN] = Attributes::makeReal
74  ("STEPSPERTURN", "THE TIME STEPS PER REVOLUTION PERIOD, ONLY FOR OPAL-CYCL", 720);
76  ("ZSTART", "Defines a z-location [m] where the reference particle starts", 0.0);
78  ("ZSTOP", "Defines a z-location [m], after which the simulation stops when the last particles passes");
80  ("TIMEINTEGRATOR", "Name of time integrator to be used", {"RK-4", "RK_4", "LF-2", "LF_2", "MTS"}, "RK_4");
81 
82  itsAttr[MAP_ORDER] = Attributes::makeReal
83  ("MAP_ORDER", "Truncation order of maps for ThickTracker (default: 1, i.e. linear)", 1);
84 
88 }
89 
90 TrackCmd::TrackCmd(const std::string &name, TrackCmd *parent):
91  Action(name, parent)
92 {}
93 
94 
96 {}
97 
98 
99 TrackCmd *TrackCmd::clone(const std::string &name) {
100  return new TrackCmd(name, this);
101 }
102 
103 std::vector<double> TrackCmd::getDT() const {
104  std::vector<double> dTs = Attributes::getRealArray(itsAttr[DT]);
105  if (dTs.size() == 0) {
106  dTs.push_back(1e-12);
107  }
108  for (double dt : dTs) {
109  if (dt < 0.0) {
110  throw OpalException("TrackCmd::getDT",
111  "The time steps provided with DT have to be positive");
112  }
113  }
114  return dTs;
115 }
116 
117 double TrackCmd::getDTSCINIT() const {
118  return Attributes::getReal(itsAttr[DTSCINIT]);
119 }
120 
121 double TrackCmd::getDTAU() const {
122  return Attributes::getReal(itsAttr[DTAU]);
123 }
124 
125 double TrackCmd::getT0() const {
126  return Attributes::getReal(itsAttr[T0]);
127 }
128 
129 double TrackCmd::getZSTART() const {
130  double zstart = Attributes::getReal(itsAttr[ZSTART]);
131  return zstart;
132 }
133 
134 std::vector<double> TrackCmd::getZSTOP() const {
135  std::vector<double> zstop = Attributes::getRealArray(itsAttr[ZSTOP]);
136  if (zstop.size() == 0) {
137  zstop.push_back(1000000.0);
138  }
139  return zstop;
140 }
141 
142 std::vector<unsigned long long> TrackCmd::getMAXSTEPS() const {
143  std::vector<double> maxsteps_d = Attributes::getRealArray(itsAttr[MAXSTEPS]);
144  std::vector<unsigned long long> maxsteps_i;
145  if (maxsteps_d.size() == 0) {
146  maxsteps_i.push_back(10ul);
147  }
148  for (double numSteps : maxsteps_d) {
149  if (numSteps < 0) {
150  throw OpalException("TrackCmd::getMAXSTEPS",
151  "The number of steps provided with MAXSTEPS has to be positive");
152  } else {
153  unsigned long long value = numSteps;
154  maxsteps_i.push_back(value);
155  }
156  }
157 
158  return maxsteps_i;
159 }
160 
162  return (int) Attributes::getReal(itsAttr[STEPSPERTURN]);
163 }
164 
165 // return int type rathor than string to improve the speed
167  std::string name = Attributes::getString(itsAttr[TIMEINTEGRATOR]);
168  int nameID;
169  if(name == std::string("RK-4") || name == std::string("RK_4"))
170  nameID = 0;
171  else if(name == std::string("LF-2") || name == std::string("LF_2"))
172  nameID = 1;
173  else if(name == std::string("MTS"))
174  nameID = 2;
175  else if(name == std::string("AMTS"))
176  nameID = 3;
177  else
178  nameID = -1;
179 
180  return nameID;
181 }
182 
184  // Find BeamSequence and Beam definitions.
187 
188  std::vector<double> dt = getDT();
189  double t0 = getT0();
190  std::vector<unsigned long long> maxsteps = getMAXSTEPS();
191  int stepsperturn = getSTEPSPERTURN();
192  double zstart = getZSTART();
193  std::vector<double> zstop = getZSTOP();
194  int timeintegrator = getTIMEINTEGRATOR();
195 
196  size_t numTracks = dt.size();
197  numTracks = std::max(numTracks, maxsteps.size());
198  numTracks = std::max(numTracks, zstop.size());
199  for (size_t i = dt.size(); i < numTracks; ++ i) {
200  dt.push_back(dt.back());
201  }
202  for (size_t i = maxsteps.size(); i < numTracks; ++ i) {
203  maxsteps.push_back(maxsteps.back());
204  }
205  for (size_t i = zstop.size(); i < numTracks; ++ i) {
206  zstop.push_back(zstop.back());
207  }
208 
209  // Execute track block.
210  Track::block = new Track(use, beam->getReference(), dt, maxsteps,
211  stepsperturn, zstart, zstop,
212  timeintegrator, t0, getDTSCINIT(), getDTAU());
213 
215 
217 
218  // Clean up.
219  delete Track::block;
220  Track::block = 0;
221 }
@ 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
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:32
static Beam * find(const std::string &name)
Find named BEAM.
Definition: Beam.cpp:145
const PartData & getReference() const
Return the embedded CLASSIC PartData.
Definition: Beam.cpp:159
Definition: Track.h:33
static Track * block
The block of track data.
Definition: Track.h:56
TrackParser parser
The parser used during tracking.
Definition: Track.h:53
int truncOrder
Trunction order for map tracking.
Definition: Track.h:91
The TRACK command.
Definition: TrackCmd.h:28
double getDTSCINIT() const
Definition: TrackCmd.cpp:117
virtual TrackCmd * clone(const std::string &name)
Make clone.
Definition: TrackCmd.cpp:99
std::vector< double > getDT() const
Return the timestep in seconds.
Definition: TrackCmd.cpp:103
std::vector< double > getZSTOP() const
location at which the simulation stops
Definition: TrackCmd.cpp:134
virtual void execute()
Execute the command.
Definition: TrackCmd.cpp:183
virtual ~TrackCmd()
Definition: TrackCmd.cpp:95
TrackCmd()
Exemplar constructor.
Definition: TrackCmd.cpp:56
double getT0() const
Return the elapsed time (sec) of the bunch.
Definition: TrackCmd.cpp:125
int getSTEPSPERTURN() const
Definition: TrackCmd.cpp:161
std::vector< unsigned long long > getMAXSTEPS() const
Return the maximum timsteps we integrate the system.
Definition: TrackCmd.cpp:142
int getTIMEINTEGRATOR() const
return the name of time integrator
Definition: TrackCmd.cpp:166
double getDTAU() const
Definition: TrackCmd.cpp:121
double getZSTART() const
location at which the simulation starts
Definition: TrackCmd.cpp:129
The base class for all OPAL exceptions.
Definition: OpalException.h:28