41 void insertFlags(std::vector<double> &flags, std::shared_ptr<Component> element);
47 totalPathLength_m(0.0)
54 out << std::fixed << std::setprecision(6);
61 for (; mapIti != mapItf; mapIti++) {
62 const key_t key = (*mapIti).first;
63 const value_t val = (*mapIti).second;
65 << std::setw(numDigits + 7) << std::right << key.
begin
67 << std::setw(numDigits + 7) << std::right << key.
end
68 <<
") number of overlapping elements " << val.size() <<
"\n";
70 for (
auto element: val) {
71 out <<
"* " << std::setw(25 + 2 * numDigits) <<
" " << element->getName() <<
"\n";
77 const double lowerLimit = s - ds;
83 throw OutOfBounds(
"IndexMap::query",
"out of bounds");
89 for (; it !=
end; ++ it) {
90 const double low = (*it).first.begin;
91 const double high = (*it).first.end;
93 if (lowerLimit < high && upperLimit >= low)
break;
96 if (it ==
end)
return elementSet;
99 for (; last !=
end; ++ last) {
100 const double low = (*last).first.begin;
102 if (upperLimit < low)
break;
105 for (; it != last; ++ it) {
107 elementSet.insert(
a.cbegin(),
a.cend());
114 if (initialS > finalS) {
115 std::swap(initialS, finalS);
125 for (; setIt != setEnd; ++ setIt) {
131 bool extendedExisting =
false;
132 for (
auto it = itpair.first; it != itpair.second; ++ it) {
133 key_t ¤tRange = it->second;
136 currentRange.
end = key.end;
137 extendedExisting =
true;
141 if (!extendedExisting) {
152 (*rit).second.empty() &&
153 zstop > (*rit).first.begin) {
180 std::vector<std::tuple<double, std::vector<double>, std::string> > sectors;
192 for (; mapIti != mapItf; mapIti++) {
193 const auto §orElements = (*mapIti).second;
194 if (sectorElements.empty())
197 const auto §orRange = (*mapIti).first;
199 double sectorBegin = sectorRange.begin;
200 double sectorEnd = sectorRange.end;
202 std::vector<std::tuple<double, std::vector<double>, std::string> > currentSector(4);
203 std::get<0>(currentSector[0]) = sectorBegin;
204 std::get<0>(currentSector[1]) = sectorBegin;
205 std::get<0>(currentSector[2]) = sectorEnd;
206 std::get<0>(currentSector[3]) = sectorEnd;
208 for (
unsigned short i = 0; i < 4; ++ i) {
209 auto &flags = std::get<1>(currentSector[i]);
210 flags.resize(
SIZE, 0);
213 for (
auto element: sectorElements) {
215 auto passage = elementPassages.first;
216 auto end = elementPassages.second;
217 for (; passage !=
end; ++ passage) {
218 const auto &elementRange = (*passage).second;
219 double elementBegin = elementRange.begin;
220 double elementEnd = elementRange.end;
222 if (elementBegin <= sectorBegin &&
223 elementEnd >= sectorEnd) {
228 const auto &elementRange = (*passage).second;
229 if (elementRange.begin < sectorBegin) {
230 ::insertFlags(std::get<1>(currentSector[0]), element);
231 std::get<2>(currentSector[0]) += element->getName() +
", ";
234 ::insertFlags(std::get<1>(currentSector[1]), element);
235 std::get<2>(currentSector[1]) += element->getName() +
", ";
237 ::insertFlags(std::get<1>(currentSector[2]), element);
238 std::get<2>(currentSector[2]) += element->getName() +
", ";
240 if (elementRange.end > sectorEnd) {
241 ::insertFlags(std::get<1>(currentSector[3]), element);
242 std::get<2>(currentSector[3]) += element->getName() +
", ";
246 for (
unsigned short i = 0; i < 4; ++ i) {
247 sectors.push_back(currentSector[i]);
252 const unsigned int numEntries = sectors.size();
255 for (; it !=
end; ++ it) {
256 auto element = (*it).first;
257 auto name = element->getName();
258 auto type = element->getType();
264 auto range = (*it).second;
267 for (; i < numEntries; ++ i) {
268 if (std::get<0>(sectors[i]) >= range.begin) {
273 if (i == numEntries)
continue;
275 unsigned int j = ++ i;
276 while (std::get<0>(sectors[j]) < range.end) {
280 double length = range.end - range.begin;
281 for (; i <= j; ++ i) {
282 double pos = std::get<0>(sectors[i]);
283 auto &items = std::get<1>(sectors[i]);
285 items[
RFCAVITY] = 1.0 - 2 * (pos - range.begin) / length;
290 if (!sectors.empty() &&
291 std::get<0>(sectors[0]) > initialPathLength) {
293 sectors = std::vector<std::tuple<double, std::vector<double>, std::string> >(1);
294 std::get<0>(sectors[0]) = initialPathLength;
295 std::get<1>(sectors[0]).resize(
SIZE, 0.0);
297 sectors.insert(sectors.end(), tmp.begin(), tmp.end());
306 for (
auto sector: sectors) {
307 std::string names = std::get<2>(sector);
308 if (!names.empty()) {
309 names = names.substr(0, names.length() - 2);
311 names =
"\"" + names +
"\"";
312 writer.addRow(std::get<0>(sector),
319 void insertFlags(std::vector<double> &flags, std::shared_ptr<Component> element) {
320 switch (element->getType()) {
324 const Bend2D* bend =
static_cast<const Bend2D*
>(element.get());
376 double position)
const {
378 key_t range{0.0, 0.0};
379 const std::pair<invertedMap_t::const_iterator, invertedMap_t::const_iterator> its =
mapElement2Range_m.equal_range(element);
380 if (std::distance(its.first, its.second) == 0)
382 "Element \"" + element->getName() +
"\" not registered");
384 for (invertedMap_t::const_iterator it = its.first; it != its.second; ++ it) {
386 std::abs((*it).second.end - position));
387 if (distance < minDistance) {
388 minDistance = distance;
389 range = (*it).second;
401 for (; it !=
end; ++ it) {
404 touchingElements.insert((it->second).begin(), (it->second).end());
407 return touchingElements;
411 return (
std::abs(x - y) < std::numeric_limits<double>::epsilon() *
std::abs(x + y) * 2 ||
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Tps< T > log(const Tps< T > &x)
Natural logarithm.
T * value_type(const SliceIterator< T > &)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
constexpr double pi
The value of.
std::string::iterator iterator
std::string combineFilePath(std::initializer_list< std::string > ilist)
boost::function< boost::tuple< double, bool >(arguments_t)> type
std::string getInputBasename()
get input file name without extension
static OpalData * getInstance()
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
static const double oneMinusEpsilon_m
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
void tidyUp(double zstop)
std::set< std::shared_ptr< Component > > value_t
value_t getTouchingElements(const key_t &range) const
invertedMap_t mapElement2Range_m
key_t getRange(const IndexMap::value_t::value_type &element, double position) const
static bool almostEqual(double, double)
void saveSDDS(double startS) const
void print(std::ostream &) const
value_t query(key_t::first_type s, key_t::second_type ds)
double getRotationAboutZ() const
Interface for general multipole.
size_t getMaxNormalComponentIndex() const
bool isFocusing(unsigned int component) const
The base class for all OPAL exceptions.