| [2112b1] | 1 | /**
|
|---|
| 2 | * @file key.hpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Nov 21 13:27:22 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief Class to distinguish the different entities in maps.
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifndef KEY_HPP_
|
|---|
| 11 | #define KEY_HPP_
|
|---|
| 12 |
|
|---|
| 13 | #ifndef HAVE_MPI
|
|---|
| 14 | #error MPI is needed to compile this class
|
|---|
| 15 | #endif /* HAVE_MPI */
|
|---|
| 16 |
|
|---|
| [894a5f] | 17 | #include <iostream>
|
|---|
| 18 | #include <list>
|
|---|
| 19 |
|
|---|
| 20 | #include "grid/grid.hpp"
|
|---|
| [2112b1] | 21 |
|
|---|
| 22 | namespace VMG
|
|---|
| 23 | {
|
|---|
| 24 |
|
|---|
| 25 | class Grid;
|
|---|
| 26 | class Index;
|
|---|
| 27 |
|
|---|
| 28 | namespace MPI
|
|---|
| 29 | {
|
|---|
| 30 |
|
|---|
| [894a5f] | 31 | class KeyStorage
|
|---|
| 32 | {
|
|---|
| 33 | public:
|
|---|
| 34 | KeyStorage(const Grid& grid) :
|
|---|
| [ac6d04] | 35 | begin(grid.Global().LocalBegin()),
|
|---|
| 36 | end(grid.Global().LocalEnd()),
|
|---|
| [894a5f] | 37 | size_local(grid.Local().SizeTotal()),
|
|---|
| [ac6d04] | 38 | size_global(grid.Global().GlobalSize()),
|
|---|
| 39 | level(grid.Level())
|
|---|
| [894a5f] | 40 | {}
|
|---|
| 41 |
|
|---|
| [ac6d04] | 42 | KeyStorage(const Index& begin, const Index& end,
|
|---|
| 43 | const Index& size_local, const Index& size_global,
|
|---|
| 44 | const int& level) :
|
|---|
| [894a5f] | 45 | begin(begin),
|
|---|
| 46 | end(end),
|
|---|
| 47 | size_local(size_local),
|
|---|
| [ac6d04] | 48 | size_global(size_global),
|
|---|
| 49 | level(level)
|
|---|
| [894a5f] | 50 | {}
|
|---|
| 51 |
|
|---|
| 52 | KeyStorage(const KeyStorage& other) :
|
|---|
| 53 | begin(other.begin),
|
|---|
| 54 | end(other.end),
|
|---|
| 55 | size_local(other.size_local),
|
|---|
| [ac6d04] | 56 | size_global(other.size_global),
|
|---|
| 57 | level(other.level)
|
|---|
| [894a5f] | 58 | {}
|
|---|
| 59 |
|
|---|
| 60 | ~KeyStorage() {}
|
|---|
| 61 |
|
|---|
| 62 | bool operator==(const KeyStorage& other) const
|
|---|
| 63 | {
|
|---|
| 64 | return this->begin == other.begin &&
|
|---|
| 65 | this->end == other.end &&
|
|---|
| 66 | this->size_local == other.size_local &&
|
|---|
| [ac6d04] | 67 | this->size_global == other.size_global &&
|
|---|
| 68 | this->level == other.level;
|
|---|
| [894a5f] | 69 | }
|
|---|
| 70 |
|
|---|
| 71 | bool operator!=(const KeyStorage& other) const
|
|---|
| 72 | {
|
|---|
| 73 | return !(*this==other);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | bool operator<(const KeyStorage& other) const
|
|---|
| 77 | {
|
|---|
| 78 | if (this->begin < other.begin) return true;
|
|---|
| [ac6d04] | 79 | if (this->begin != other.begin) return false;
|
|---|
| 80 | if (this->end < other.end) return true;
|
|---|
| 81 | if (this->end != other.end) return false;
|
|---|
| 82 | if (this->size_local < other.size_local) return true;
|
|---|
| 83 | if (this->size_local != other.size_local) return false;
|
|---|
| 84 | if (this->size_global < other.size_global) return true;
|
|---|
| 85 | if (this->size_global != other.size_global) return false;
|
|---|
| 86 | if (this->level < other.level) return true;
|
|---|
| 87 | return false;
|
|---|
| [894a5f] | 88 | }
|
|---|
| 89 |
|
|---|
| 90 | private:
|
|---|
| 91 | const Index begin, end, size_local, size_global;
|
|---|
| [ac6d04] | 92 | const int level;
|
|---|
| [894a5f] | 93 | };
|
|---|
| 94 |
|
|---|
| 95 | class KeySorted {
|
|---|
| 96 | public:
|
|---|
| 97 | KeySorted(const KeySorted& other)
|
|---|
| 98 | {
|
|---|
| 99 | std::list<KeyStorage>::const_iterator i;
|
|---|
| 100 | this->keys.clear();
|
|---|
| 101 | for (i=other.keys.begin(); i!=other.keys.end(); ++i)
|
|---|
| 102 | this->keys.push_back(*i);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | KeySorted(const Grid& grid)
|
|---|
| 106 | {
|
|---|
| 107 | keys.push_back(KeyStorage(grid));
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | KeySorted(const Grid& grid_1, const Grid& grid_2)
|
|---|
| 111 | {
|
|---|
| 112 | keys.push_back(KeyStorage(grid_1));
|
|---|
| 113 | keys.push_back(KeyStorage(grid_2));
|
|---|
| 114 | keys.sort();
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| [ac6d04] | 117 | KeySorted(const Index& begin, const Index& end,
|
|---|
| 118 | const Index& size_local, const Index& size_global,
|
|---|
| 119 | const int& level)
|
|---|
| [894a5f] | 120 | {
|
|---|
| [ac6d04] | 121 | keys.push_back(KeyStorage(begin, end, size_local, size_global, level));
|
|---|
| [894a5f] | 122 | }
|
|---|
| 123 |
|
|---|
| 124 | ~KeySorted() {}
|
|---|
| 125 |
|
|---|
| 126 | bool operator<(const KeySorted& other) const
|
|---|
| 127 | {
|
|---|
| 128 | if (this->keys.size() < other.keys.size()) return true;
|
|---|
| 129 | if (this->keys.size() > other.keys.size()) return false;
|
|---|
| 130 |
|
|---|
| 131 | std::list<KeyStorage>::const_iterator i1, i2;
|
|---|
| 132 | for (i1=this->keys.begin(), i2=other.keys.begin();
|
|---|
| 133 | i1!=this->keys.end(), i2!=other.keys.end();
|
|---|
| 134 | ++i1, ++i2) {
|
|---|
| 135 | if (*i1 < *i2) return true;
|
|---|
| 136 | if (*i1 != *i2) return false;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | return false;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | private:
|
|---|
| 143 | std::list<KeyStorage> keys;
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| [ac6d04] | 146 |
|
|---|
| 147 | /*
|
|---|
| 148 | * direction: 0 - from multigrid to temporary grid
|
|---|
| 149 | * 1 - from temporary grid to multigrid
|
|---|
| 150 | * for single grid datatypes always 0
|
|---|
| 151 | */
|
|---|
| [894a5f] | 152 | class KeyUnsorted {
|
|---|
| [2112b1] | 153 | public:
|
|---|
| [894a5f] | 154 | KeyUnsorted(const KeyUnsorted& other)
|
|---|
| 155 | {
|
|---|
| 156 | std::list<KeyStorage>::const_iterator i;
|
|---|
| 157 | this->keys.clear();
|
|---|
| 158 | for (i=other.keys.begin(); i!=other.keys.end(); ++i)
|
|---|
| 159 | this->keys.push_back(*i);
|
|---|
| [ac6d04] | 160 | this->direction = other.direction;
|
|---|
| [894a5f] | 161 | }
|
|---|
| 162 |
|
|---|
| [ac6d04] | 163 | KeyUnsorted(const Grid& grid, const int& direction)
|
|---|
| [894a5f] | 164 | {
|
|---|
| 165 | keys.push_back(KeyStorage(grid));
|
|---|
| [ac6d04] | 166 | this->direction = direction;
|
|---|
| [894a5f] | 167 | }
|
|---|
| 168 |
|
|---|
| [ac6d04] | 169 | KeyUnsorted(const Grid& grid_1, const Grid& grid_2, const int& direction)
|
|---|
| [894a5f] | 170 | {
|
|---|
| 171 | keys.push_back(KeyStorage(grid_1));
|
|---|
| 172 | keys.push_back(KeyStorage(grid_2));
|
|---|
| [ac6d04] | 173 | this->direction = direction;
|
|---|
| [894a5f] | 174 | }
|
|---|
| 175 |
|
|---|
| [ac6d04] | 176 | KeyUnsorted(const Index& begin, const Index& end,
|
|---|
| 177 | const Index& size_local, const Index& size_global,
|
|---|
| 178 | const int& level, const int& direction)
|
|---|
| [894a5f] | 179 | {
|
|---|
| [ac6d04] | 180 | keys.push_back(KeyStorage(begin, end, size_local, size_global, level));
|
|---|
| 181 | this->direction = direction;
|
|---|
| [894a5f] | 182 | }
|
|---|
| 183 |
|
|---|
| 184 | ~KeyUnsorted() {}
|
|---|
| 185 |
|
|---|
| 186 | bool operator<(const KeyUnsorted& other) const
|
|---|
| 187 | {
|
|---|
| 188 | if (this->keys.size() < other.keys.size()) return true;
|
|---|
| 189 | if (this->keys.size() > other.keys.size()) return false;
|
|---|
| [2112b1] | 190 |
|
|---|
| [894a5f] | 191 | std::list<KeyStorage>::const_iterator i1, i2;
|
|---|
| 192 | for (i1=this->keys.begin(), i2=other.keys.begin();
|
|---|
| 193 | i1!=this->keys.end(), i2!=other.keys.end();
|
|---|
| 194 | ++i1, ++i2) {
|
|---|
| 195 | if (*i1 < *i2) return true;
|
|---|
| 196 | if (*i1 != *i2) return false;
|
|---|
| 197 | }
|
|---|
| [2112b1] | 198 |
|
|---|
| [ac6d04] | 199 | if (this->direction < other.direction) return true;
|
|---|
| 200 |
|
|---|
| [894a5f] | 201 | return false;
|
|---|
| 202 | }
|
|---|
| [2112b1] | 203 |
|
|---|
| 204 | private:
|
|---|
| [894a5f] | 205 | std::list<KeyStorage> keys;
|
|---|
| [ac6d04] | 206 | int direction;
|
|---|
| [2112b1] | 207 | };
|
|---|
| 208 |
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | #endif /* KEY_HPP_ */
|
|---|