OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
IndexMap.h
Go to the documentation of this file.
1//
2// Class IndexMap
3//
4// This class stores and prints the sequence of elements that the referenc particle passes.
5// Each time the reference particle enters or leaves an element an entry is added to the map.
6// With help of this map one can determine which element can be found at a given position.
7//
8// Copyright (c) 2016, Christof Metzger-Kraus, Helmholtz-Zentrum Berlin, Germany
9// 2017 - 2020 Christof Metzger-Kraus
10//
11// All rights reserved
12//
13// This file is part of OPAL.
14//
15// OPAL is free software: you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation, either version 3 of the License, or
18// (at your option) any later version.
19//
20// You should have received a copy of the GNU General Public License
21// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
22//
23#ifndef OPAL_INDEXMAP_H
24#define OPAL_INDEXMAP_H
25
27
28#include <map>
29#include <ostream>
30
33
34#include <set>
35#include <utility>
36
37class IndexMap {
38public:
39 struct Range {
40 typedef double first_type;
41 typedef double second_type;
44 };
45 typedef Range key_t;
46 typedef std::set<std::shared_ptr<Component> > value_t;
47
48 IndexMap();
49
50 void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t& val);
51
53
54 void tidyUp(double zstop);
55
56 void print(std::ostream&) const;
57 void saveSDDS(double startS) const;
58 size_t size() const;
60
61 size_t numElements() const;
62 key_t getRange(const IndexMap::value_t::value_type& element, double position) const;
63 value_t getTouchingElements(const key_t& range) const;
64
65 class OutOfBounds : public OpalException {
66 public:
67 OutOfBounds(const std::string& meth, const std::string& msg) : OpalException(meth, msg) {}
68
70
71 virtual ~OutOfBounds() {}
72
73 private:
75 };
76
77private:
78 class myCompare {
79 public:
80 bool operator()(const key_t x, const key_t y) const {
81 if (x.begin < y.begin) return true;
82
83 if (x.begin == y.begin) {
84 if (x.end < y.end) return true;
85 }
86
87 return false;
88 }
89 };
90
91 typedef std::map<key_t, value_t, myCompare> map_t;
92 typedef std::multimap<value_t::value_type, key_t> invertedMap_t;
97
99
100 void rebuildReferencePathModel() const;
101 static bool almostEqual(double, double);
102 static const double oneMinusEpsilon_m;
103};
104
105inline size_t IndexMap::size() const { return mapRange2Element_m.size(); }
106
113
114inline std::ostream& operator<<(std::ostream& out, const IndexMap& im) {
115 im.print(out);
116 return out;
117}
118
119inline Inform& operator<<(Inform& out, const IndexMap& im) {
120 im.print(out.getStream());
121 return out;
122}
123
124#endif
Defines the abstract interface for a single beamline component in the accelerator model.
std::ostream & operator<<(std::ostream &out, const IndexMap &im)
Definition IndexMap.h:114
virtual ~OutOfBounds()
Definition IndexMap.h:71
OutOfBounds(const std::string &meth, const std::string &msg)
Definition IndexMap.h:67
OutOfBounds(const OutOfBounds &rhs)
Definition IndexMap.h:69
bool operator()(const key_t x, const key_t y) const
Definition IndexMap.h:80
std::map< key_t, value_t, myCompare > map_t
Definition IndexMap.h:91
static const double oneMinusEpsilon_m
Definition IndexMap.h:102
double totalPathLength_m
Definition IndexMap.h:98
size_t size() const
Definition IndexMap.h:105
first_type begin
Definition IndexMap.h:42
bool referencePathModelDirty_m
Definition IndexMap.h:96
void add(key_t::first_type initialStep, key_t::second_type finalStep, const value_t &val)
Definition IndexMap.cpp:111
size_t numElements() const
void tidyUp(double zstop)
Definition IndexMap.cpp:147
ReferencePathModel referencePathModel_m
Definition IndexMap.h:95
std::set< std::shared_ptr< Component > > value_t
Definition IndexMap.h:46
value_t getTouchingElements(const key_t &range) const
Definition IndexMap.cpp:376
void rebuildReferencePathModel() const
Definition IndexMap.cpp:160
invertedMap_t mapElement2Range_m
Definition IndexMap.h:94
Range key_t
Definition IndexMap.h:45
key_t getRange(const IndexMap::value_t::value_type &element, double position) const
Definition IndexMap.cpp:354
map_t mapRange2Element_m
Definition IndexMap.h:93
double first_type
Definition IndexMap.h:40
const ReferencePathModel & getReferencePathModel() const
Definition IndexMap.h:107
std::multimap< value_t::value_type, key_t > invertedMap_t
Definition IndexMap.h:92
second_type end
Definition IndexMap.h:43
double second_type
Definition IndexMap.h:41
static bool almostEqual(double, double)
Definition IndexMap.cpp:389
void saveSDDS(double startS) const
Definition IndexMap.cpp:182
void print(std::ostream &) const
Definition IndexMap.cpp:50
value_t query(key_t::first_type s, key_t::second_type ds)
Definition IndexMap.cpp:74
Ordered collection of reference-path segments.