OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
StepSizeConfig.cpp
Go to the documentation of this file.
3 
4 #include <algorithm>
5 #include <numeric>
6 #include <iterator>
7 #include <cmath>
8 
10  configurations_m.sort([] (const entry_t &a,
11  const entry_t &b) -> bool
12  {
13  return std::get<1>(a) < std::get<1>(b);
14  });
15 }
16 
18  unsigned int posIterator = std::distance(it_m, configurations_m.end()) - 1;
19  configurations_m.reverse();
20  it_m = configurations_m.begin();
21  std::advance(it_m, posIterator);
22 }
23 
25  while (getZStop() < spos && std::next(it_m) != configurations_m.end()) {
26  ++ it_m;
27  }
28 
29  return *this;
30 }
31 
33  if (reachedEnd()) {
34  throw OpalException("StepSizeConfig::operator++",
35  "iterator is at end of list of configurations");
36  }
37 
38  ++ it_m;
39 
40  return *this;
41 }
42 
44  if (reachedStart()) {
45  throw OpalException("StepSizeConfig::operator--",
46  "iterator is at begin of list of configurations");
47  }
48 
49  -- it_m;
50 
51  return *this;
52 }
53 
54 void StepSizeConfig::shiftZStopRight(double front) {
55  auto it = configurations_m.begin();
56  while (std::get<1>(*it) < front &&
57  std::next(it) != configurations_m.end()) {
58  ++ it;
59  }
60 
61  double zstop = std::get<1>(*it);
62  if (zstop < front) return;
63 
64  std::get<1>(*it) = front;
65  for (++ it ;
66  it != configurations_m.end();
67  ++ it) {
68  std::swap(zstop, std::get<1>(*it));
69  }
70 }
71 
72 void StepSizeConfig::shiftZStopLeft(double back) {
73  auto it = configurations_m.rbegin();
74  while (std::get<1>(*it) > back &&
75  std::next(it) != configurations_m.rend()) {
76  ++ it;
77  }
78 
79  double zstop = std::get<1>(*it);
80  if (zstop > back) return;
81 
82  std::get<1>(*it) = back;
83  for (++ it ;
84  it != configurations_m.rend();
85  ++ it) {
86  std::swap(zstop, std::get<1>(*it));
87  }
88 }
89 
90 double StepSizeConfig::getdT() const {
91  if (reachedEnd()) {
92  throw OpalException("StepSizeConfig::getdT",
93  "iterator is at end of list of configurations");
94  }
95 
96  return std::get<0>(*it_m);
97 }
98 
99 double StepSizeConfig::getZStop() const {
100  if (reachedEnd()) {
101  throw OpalException("StepSizeConfig::getZStop",
102  "iterator is at end of list of configurations");
103  }
104 
105  return std::get<1>(*it_m);
106 }
107 
108 unsigned long StepSizeConfig::getNumSteps() const {
109  if (reachedEnd()) {
110  throw OpalException("StepSizeConfig::getNumSteps",
111  "iterator is at end of list of configurations");
112  }
113 
114  return std::get<2>(*it_m);
115 }
116 
117 unsigned long long StepSizeConfig::getMaxSteps() const {
118  unsigned long long maxSteps = 0;
119  for (const auto config: configurations_m) {
120  maxSteps += std::get<2>(config);
121  }
122 
123  return maxSteps;
124 }
125 
127  double minTimeStep = std::get<0>(configurations_m.front());
128  unsigned long long totalNumSteps = 0;
129 
130  for (const auto config: configurations_m) {
131  const double &dt = std::get<0>(config);
132  const unsigned long &numSteps = std::get<2>(config);
133 
134  if (minTimeStep > dt) {
135  totalNumSteps = std::ceil(totalNumSteps * minTimeStep / dt);
136  minTimeStep = dt;
137  }
138 
139  totalNumSteps += std::ceil(numSteps * dt / minTimeStep);
140  }
141 
142  return totalNumSteps;
143 }
144 
146  double minTimeStep = std::get<0>(configurations_m.front());
147  for (const auto config: configurations_m) {
148  if (minTimeStep > std::get<0>(config)) {
149  minTimeStep = std::get<0>(config);
150  }
151  }
152 
153  return minTimeStep;
154 }
155 
157  return std::get<1>(configurations_m.back());
158 }
159 
160 void StepSizeConfig::print(Inform &out) const {
161  out << std::scientific << " "
162  << std::setw(20) << "dt [ns] "
163  << std::setw(20) << "zStop [m] "
164  << std::setw(20) << "num Steps [1]"
165  << endl;
166 
167  for (auto it = configurations_m.begin();
168  it != configurations_m.end();
169  ++ it) {
170  if (it_m == it) {
171  out << "-> ";
172  } else {
173  out << " ";
174  }
175 
176  out << std::setw(20) << std::get<0>(*it)
177  << std::setw(20) << std::get<1>(*it)
178  << std::setw(20) << std::get<2>(*it)
179  << endl;
180  }
181 }
double getMinTimeStep() const
bool reachedEnd() const
The base class for all OPAL exceptions.
Definition: OpalException.h:28
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
Definition: PETE.h:811
void sortAscendingZStop()
unsigned long long getNumStepsFinestResolution() const
bool reachedStart() const
unsigned long long getMaxSteps() const
double getFinalZStop() const
StepSizeConfig & operator--()
std::tuple< double, double, unsigned long > entry_t
double getdT() const
void shiftZStopRight(double front)
void shiftZStopLeft(double back)
void print(Inform &out) const
double getZStop() const
unsigned long getNumSteps() const
StepSizeConfig & advanceToPos(double spos)
Definition: Inform.h:41
StepSizeConfig & operator++()
container_t configurations_m
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
container_t::iterator it_m