OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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"
26 
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");
79  itsAttr[TIMEINTEGRATOR] = Attributes::makeString
80  ("TIMEINTEGRATOR", "Name of time integrator to be used", "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 
90 }
91 
92 TrackCmd::TrackCmd(const std::string &name, TrackCmd *parent):
93  Action(name, parent)
94 {}
95 
96 
98 {}
99 
100 
101 TrackCmd *TrackCmd::clone(const std::string &name) {
102  return new TrackCmd(name, this);
103 }
104 
105 std::vector<double> TrackCmd::getDT() const {
106  std::vector<double> dt = Attributes::getRealArray(itsAttr[DT]);
107  if (dt.size() == 0) {
108  dt.push_back(1e-12);
109  }
110  return dt;
111 }
112 
113 double TrackCmd::getDTSCINIT() const {
114  return Attributes::getReal(itsAttr[DTSCINIT]);
115 }
116 
117 double TrackCmd::getDTAU() const {
118  return Attributes::getReal(itsAttr[DTAU]);
119 }
120 
121 double TrackCmd::getT0() const {
122  return Attributes::getReal(itsAttr[T0]);
123 }
124 
125 double TrackCmd::getZSTART() const {
126  double zstart = Attributes::getReal(itsAttr[ZSTART]);
127  return zstart;
128 }
129 
130 std::vector<double> TrackCmd::getZSTOP() const {
131  std::vector<double> zstop = Attributes::getRealArray(itsAttr[ZSTOP]);
132  if (zstop.size() == 0) {
133  zstop.push_back(1000000.0);
134  }
135  return zstop;
136 }
137 
138 std::vector<unsigned long long> TrackCmd::getMAXSTEPS() const {
139  std::vector<double> maxsteps_d = Attributes::getRealArray(itsAttr[MAXSTEPS]);
140  std::vector<unsigned long long> maxsteps_i;
141  if (maxsteps_d.size() == 0) {
142  maxsteps_i.push_back(10ul);
143  }
144  for (auto it = maxsteps_d.begin(); it != maxsteps_d.end(); ++ it) {
145  if (*it < 0) {
146  maxsteps_i.push_back(10);
147  } else {
148  unsigned long long value = *it;
149  maxsteps_i.push_back(value);
150  }
151  }
152 
153  return maxsteps_i;
154 }
155 
157  return (int) Attributes::getReal(itsAttr[STEPSPERTURN]);
158 }
159 
160 // return int type rathor than string to improve the speed
162  std::string name = Attributes::getString(itsAttr[TIMEINTEGRATOR]);
163  int nameID;
164  if(name == std::string("RK-4"))
165  nameID = 0;
166  else if(name == std::string("LF-2"))
167  nameID = 1;
168  else if(name == std::string("MTS"))
169  nameID = 2;
170  else if(name == std::string("AMTS"))
171  nameID = 3;
172  else
173  nameID = -1;
174 
175  return nameID;
176 }
177 
179  // Find BeamSequence and Beam definitions.
182 
183  std::vector<double> dt = getDT();
184  double t0 = getT0();
185  std::vector<unsigned long long> maxsteps = getMAXSTEPS();
186  int stepsperturn = getSTEPSPERTURN();
187  double zstart = getZSTART();
188  std::vector<double> zstop = getZSTOP();
189  int timeintegrator = getTIMEINTEGRATOR();
190  int nslices = beam->getNumberOfSlices();
191 
192  size_t numTracks = dt.size();
193  numTracks = std::max(numTracks, maxsteps.size());
194  numTracks = std::max(numTracks, zstop.size());
195  for (size_t i = dt.size(); i < numTracks; ++ i) {
196  dt.push_back(dt.back());
197  }
198  for (size_t i = maxsteps.size(); i < numTracks; ++ i) {
199  maxsteps.push_back(maxsteps.back());
200  }
201  for (size_t i = zstop.size(); i < numTracks; ++ i) {
202  zstop.push_back(zstop.back());
203  }
204 
205  // Execute track block.
206  Track::block = new Track(use, beam->getReference(), dt, maxsteps,
207  stepsperturn, zstart, zstop,
208  timeintegrator, nslices, t0, getDTSCINIT(), getDTAU());
209 
211 
213 
214  // Clean up.
215  delete Track::block;
216  Track::block = 0;
217 }
constexpr double e
The value of .
Definition: Physics.h:40
double getDTAU() const
Definition: TrackCmd.cpp:117
The base class for all OPAL actions.
Definition: Action.h:30
size_t getNumberOfSlices()
Return the number of slices.
Definition: Beam.cpp:164
std::vector< double > getZSTOP() const
location at which the simulation stops
Definition: TrackCmd.cpp:130
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:123
TrackCmd()
Exemplar constructor.
Definition: TrackCmd.cpp:56
int getTIMEINTEGRATOR() const
return the name of time integrator
Definition: TrackCmd.cpp:161
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
static void addAttributeOwner(const std::string &owner, const OwnerType &type, const std::string &name)
double getDTSCINIT() const
Definition: TrackCmd.cpp:113
virtual ~TrackCmd()
Definition: TrackCmd.cpp:97
static BeamSequence * find(const std::string &name)
Find a BeamSequence by name.
TrackParser parser
The parser used during tracking.
Definition: Track.h:60
static Beam * find(const std::string &name)
Find named BEAM.
Definition: Beam.cpp:150
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
static Track * block
The block of track data.
Definition: Track.h:63
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:258
The TRACK command.
Definition: TrackCmd.h:28
std::vector< double > getDT() const
Return the timestep in seconds.
Definition: TrackCmd.cpp:105
virtual void execute()
Execute the command.
Definition: TrackCmd.cpp:178
int getSTEPSPERTURN() const
Definition: TrackCmd.cpp:156
int truncOrder
Trunction order for map tracking.
Definition: Track.h:98
virtual void run() const
Read current stream.
Definition: OpalParser.cpp:601
The base class for all OPAL beam lines and sequences.
Definition: BeamSequence.h:32
double getT0() const
Return the elapsed time (sec) of the bunch.
Definition: TrackCmd.cpp:121
const PartData & getReference() const
Return the embedded CLASSIC PartData.
Definition: Beam.cpp:183
The BEAM definition.
Definition: Beam.h:35
const std::string name
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:253
double getZSTART() const
location at which the simulation starts
Definition: TrackCmd.cpp:125
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:296
Hold data for tracking.
Definition: Track.h:38
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
std::vector< unsigned long long > getMAXSTEPS() const
Return the maximum timsteps we integrate the system.
Definition: TrackCmd.cpp:138
virtual TrackCmd * clone(const std::string &name)
Make clone.
Definition: TrackCmd.cpp:101
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:307