OPAL (Object Oriented Parallel Accelerator Library) 2022.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
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
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
109double 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
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
127unsigned 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
136unsigned 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
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
203 ValueRange<double> result;
204 for (const entry_t& entry : configurations_m) {
205 result.enlargeIfOutside(std::get<1>(entry));
206 }
207 return result;
208}
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
Definition: PETE.h:728
std::complex< double > a
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
double getMinTimeStep() const
StepSizeConfig & advanceToPos(double spos)
bool reachedStart() const
StepSizeConfig & operator++()
double getdT() const
unsigned long long getNumStepsFinestResolution() const
void print(Inform &out) const
container_t::iterator it_m
void shiftZStopRight(double front)
void shiftZStopLeft(double back)
double getZStop() const
bool reachedEnd() const
unsigned long getNumSteps() const
unsigned long long getMaxSteps() const
container_t configurations_m
StepSizeConfig & operator--()
std::tuple< double, double, unsigned long > entry_t
void sortAscendingZStop()
ValueRange< double > getPathLengthRange() const
double getFinalZStop() const
void enlargeIfOutside(T value)
Definition: ValueRange.h:36
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Definition: Inform.h:42