OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
StepSizeConfig.cpp
Go to the documentation of this file.
1 //
2 // Class StepSizeConfig
3 //
4 // This class stores tuples of time step sizes, path length range limits and limit of number of step sizes.
5 //
6 // Copyright (c) 2019 - 2021, Christof Metzger-Kraus
7 //
8 // All rights reserved
9 //
10 // This file is part of OPAL.
11 //
12 // OPAL is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
19 //
22 
23 #include <algorithm>
24 #include <numeric>
25 #include <iterator>
26 #include <cmath>
27 
29  configurations_m.sort([] (const entry_t &a,
30  const entry_t &b) -> bool
31  {
32  return std::get<1>(a) < std::get<1>(b);
33  });
34 }
35 
37  unsigned int posIterator = std::distance(it_m, configurations_m.end()) - 1;
38  configurations_m.reverse();
39  it_m = configurations_m.begin();
40  std::advance(it_m, posIterator);
41 }
42 
44  while (getZStop() < spos && std::next(it_m) != configurations_m.end()) {
45  ++ it_m;
46  }
47 
48  return *this;
49 }
50 
52  if (reachedEnd()) {
53  throw OpalException("StepSizeConfig::operator++",
54  "iterator is at end of list of configurations");
55  }
56 
57  ++ it_m;
58 
59  return *this;
60 }
61 
63  if (reachedStart()) {
64  throw OpalException("StepSizeConfig::operator--",
65  "iterator is at begin of list of configurations");
66  }
67 
68  -- it_m;
69 
70  return *this;
71 }
72 
73 void StepSizeConfig::shiftZStopRight(double front) {
74  auto it = configurations_m.begin();
75  while (std::get<1>(*it) < front &&
76  std::next(it) != configurations_m.end()) {
77  ++ it;
78  }
79 
80  double zstop = std::get<1>(*it);
81  if (zstop < front) return;
82 
83  std::get<1>(*it) = front;
84  for (++ it ;
85  it != configurations_m.end();
86  ++ it) {
87  std::swap(zstop, std::get<1>(*it));
88  }
89 }
90 
91 void StepSizeConfig::shiftZStopLeft(double back) {
92  auto it = configurations_m.rbegin();
93  while (std::get<1>(*it) > back &&
94  std::next(it) != configurations_m.rend()) {
95  ++ it;
96  }
97 
98  double zstop = std::get<1>(*it);
99  if (zstop > back) return;
100 
101  std::get<1>(*it) = back;
102  for (++ it ;
103  it != configurations_m.rend();
104  ++ it) {
105  std::swap(zstop, std::get<1>(*it));
106  }
107 }
108 
109 double StepSizeConfig::getdT() const {
110  if (reachedEnd()) {
111  throw OpalException("StepSizeConfig::getdT",
112  "iterator is at end of list of configurations");
113  }
114 
115  return std::get<0>(*it_m);
116 }
117 
118 double StepSizeConfig::getZStop() const {
119  if (reachedEnd()) {
120  throw OpalException("StepSizeConfig::getZStop",
121  "iterator is at end of list of configurations");
122  }
123 
124  return std::get<1>(*it_m);
125 }
126 
127 unsigned long StepSizeConfig::getNumSteps() const {
128  if (reachedEnd()) {
129  throw OpalException("StepSizeConfig::getNumSteps",
130  "iterator is at end of list of configurations");
131  }
132 
133  return std::get<2>(*it_m);
134 }
135 
136 unsigned long long StepSizeConfig::getMaxSteps() const {
137  unsigned long long maxSteps = 0;
138  for (const auto& config: configurations_m) {
139  maxSteps += std::get<2>(config);
140  }
141 
142  return maxSteps;
143 }
144 
146  double minTimeStep = std::get<0>(configurations_m.front());
147  unsigned long long totalNumSteps = 0;
148 
149  for (const auto& config: configurations_m) {
150  const double &dt = std::get<0>(config);
151  const unsigned long &numSteps = std::get<2>(config);
152 
153  if (minTimeStep > dt) {
154  totalNumSteps = std::ceil(totalNumSteps * minTimeStep / dt);
155  minTimeStep = dt;
156  }
157 
158  totalNumSteps += std::ceil(numSteps * dt / minTimeStep);
159  }
160 
161  return totalNumSteps;
162 }
163 
165  double minTimeStep = std::get<0>(configurations_m.front());
166  for (const auto& config: configurations_m) {
167  if (minTimeStep > std::get<0>(config)) {
168  minTimeStep = std::get<0>(config);
169  }
170  }
171 
172  return minTimeStep;
173 }
174 
176  return std::get<1>(configurations_m.back());
177 }
178 
179 void StepSizeConfig::print(Inform &out) const {
180  out << std::scientific << " "
181  << std::setw(20) << "dt [ns] "
182  << std::setw(20) << "zStop [m] "
183  << std::setw(20) << "num Steps [1]"
184  << endl;
185 
186  for (auto it = configurations_m.begin();
187  it != configurations_m.end();
188  ++ it) {
189  if (it_m == it) {
190  out << "-> ";
191  } else {
192  out << " ";
193  }
194 
195  out << std::setw(20) << std::get<0>(*it)
196  << std::setw(20) << std::get<1>(*it)
197  << std::setw(20) << std::get<2>(*it)
198  << endl;
199  }
200 }
201 
204  for (const entry_t& entry : configurations_m) {
205  result.enlargeIfOutside(std::get<1>(entry));
206  }
207  return result;
208 }
double getZStop() const
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition: LICENSE:43
double getFinalZStop() const
void sortAscendingZStop()
bool reachedEnd() const
ValueRange< double > getPathLengthRange() const
container_t configurations_m
container_t::iterator it_m
void print(Inform &out) const
StepSizeConfig & advanceToPos(double spos)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
StepSizeConfig & operator++()
StepSizeConfig & operator--()
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Definition: Inform.h:42
unsigned long long getMaxSteps() const
unsigned long long getNumStepsFinestResolution() const
double getdT() const
double getMinTimeStep() const
float result
Definition: test.py:2
void shiftZStopLeft(double back)
unsigned long getNumSteps() const
bool reachedStart() const
std::tuple< double, double, unsigned long > entry_t
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
Definition: PETE.h:728
void shiftZStopRight(double front)
void enlargeIfOutside(T value)
Definition: ValueRange.h:36