OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
5// sizes.
6//
7// Copyright (c) 2019 - 2021, Christof Metzger-Kraus
8//
9// All rights reserved
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
23
24#include <algorithm>
25#include <cmath>
26#include <iterator>
27#include <numeric>
28
30 configurations_m.sort([](const entry_t& a, const entry_t& b) -> bool {
31 return std::get<1>(a) < std::get<1>(b);
32 });
33}
34
36 unsigned int posIterator = std::distance(it_m, configurations_m.end()) - 1;
37 configurations_m.reverse();
38 it_m = configurations_m.begin();
39 std::advance(it_m, posIterator);
40}
41
43 while (getZStop() < spos && std::next(it_m) != configurations_m.end()) {
44 ++it_m;
45 }
46
47 return *this;
48}
49
51 if (reachedEnd()) {
52 throw OpalException(
53 "StepSizeConfig::operator++", "iterator is at end of list of configurations");
54 }
55
56 ++it_m;
57
58 return *this;
59}
60
62 if (reachedStart()) {
63 throw OpalException(
64 "StepSizeConfig::operator--", "iterator is at begin of list of configurations");
65 }
66
67 --it_m;
68
69 return *this;
70}
71
73 auto it = configurations_m.begin();
74 while (std::get<1>(*it) < front && std::next(it) != configurations_m.end()) {
75 ++it;
76 }
77
78 double zstop = std::get<1>(*it);
79 if (zstop < front) return;
80
81 std::get<1>(*it) = front;
82 for (++it; it != configurations_m.end(); ++it) {
83 std::swap(zstop, std::get<1>(*it));
84 }
85}
86
87double StepSizeConfig::getdT() const {
88 if (reachedEnd()) {
89 throw OpalException(
90 "StepSizeConfig::getdT", "iterator is at end of list of configurations");
91 }
92
93 return std::get<0>(*it_m);
94}
95
97 if (reachedEnd()) {
98 throw OpalException(
99 "StepSizeConfig::getZStop", "iterator is at end of list of configurations");
100 }
101
102 return std::get<1>(*it_m);
103}
104
105unsigned long StepSizeConfig::getNumSteps() const {
106 if (reachedEnd()) {
107 throw OpalException(
108 "StepSizeConfig::getNumSteps", "iterator is at end of list of configurations");
109 }
110
111 return std::get<2>(*it_m);
112}
113
114unsigned long long StepSizeConfig::getMaxSteps() const {
115 unsigned long long maxSteps = 0;
116 for (const auto& config : configurations_m) {
117 maxSteps += std::get<2>(config);
118 }
119
120 return maxSteps;
121}
122
124 double minTimeStep = std::get<0>(configurations_m.front());
125 unsigned long long totalNumSteps = 0;
126
127 for (const auto& config : configurations_m) {
128 const double& dt = std::get<0>(config);
129 const unsigned long& numSteps = std::get<2>(config);
130
131 if (minTimeStep > dt) {
132 totalNumSteps = std::ceil(totalNumSteps * minTimeStep / dt);
133 minTimeStep = dt;
134 }
135
136 totalNumSteps += std::ceil(numSteps * dt / minTimeStep);
137 }
138
139 return totalNumSteps;
140}
141
143 double minTimeStep = std::get<0>(configurations_m.front());
144 for (const auto& config : configurations_m) {
145 if (minTimeStep > std::get<0>(config)) {
146 minTimeStep = std::get<0>(config);
147 }
148 }
149
150 return minTimeStep;
151}
152
153double StepSizeConfig::getFinalZStop() const { return std::get<1>(configurations_m.back()); }
154
155Inform& StepSizeConfig::print(Inform& out) const {
156 out << std::scientific << " " << std::setw(20) << "dt [ns] " << std::setw(20) << "zStop [m] "
157 << std::setw(20) << "num Steps [1]" << endl;
158
159 for (auto it = configurations_m.begin(); it != configurations_m.end(); ++it) {
160 if (it_m == it) {
161 out << "-> ";
162 } else {
163 out << " ";
164 }
165
166 out << std::setw(20) << std::get<0>(*it) << std::setw(20) << std::get<1>(*it)
167 << std::setw(20) << std::get<2>(*it) << endl;
168 }
169 return out;
170}
171
172void StepSizeConfig::printDirect(Inform& out) const {
173 out << std::scientific << " " << std::setw(20) << "dt [ns] " << std::setw(20) << "zStop [m] "
174 << std::setw(20) << "num Steps [1]" << endl;
175
176 for (auto it = configurations_m.begin(); it != configurations_m.end(); ++it) {
177 if (it_m == it) {
178 out << "-> ";
179 } else {
180 out << " ";
181 }
182
183 out << std::setw(20) << std::get<0>(*it) << std::setw(20) << std::get<1>(*it)
184 << std::setw(20) << std::get<2>(*it) << endl;
185 }
186}
187
189 ValueRange<double> result;
190 for (const entry_t& entry : configurations_m) {
191 result.enlargeIfOutside(std::get<1>(entry));
192 }
193 return result;
194}
double getMinTimeStep() const
StepSizeConfig & advanceToPos(double spos)
bool reachedStart() const
StepSizeConfig & operator++()
Inform & print(Inform &out) const
double getdT() const
unsigned long long getNumStepsFinestResolution() const
void printDirect(Inform &out) const
container_t::iterator it_m
void shiftZStopRight(double front)
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
ValueRange< double > getPathLengthRange() const
double getFinalZStop() const
void enlargeIfOutside(T value)
Definition ValueRange.h:34