| 1 | /* |
| 2 | * ProcKeys.hpp |
| 3 | * |
| 4 | * Created on: Mar 14, 2017 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_PROCKEYS_HPP_ |
| 9 | #define OPENFPM_DATA_SRC_NN_CELLLIST_PROCKEYS_HPP_ |
| 10 | |
| 11 | extern "C" |
| 12 | { |
| 13 | #include "hilbertKey.h" |
| 14 | } |
| 15 | |
| 16 | /* !Brief Class for a linear (1D-like) order processing of cell keys for CellList_gen implementation |
| 17 | * |
| 18 | * \tparam dim Dimansionality of the space |
| 19 | */ |
| 20 | template<unsigned int dim, typename CellList> |
| 21 | class Process_keys_lin |
| 22 | { |
| 23 | //! stub object |
| 24 | openfpm::vector<size_t> keys; |
| 25 | |
| 26 | public: |
| 27 | |
| 28 | //! Particle Iterator produced by this key generator |
| 29 | typedef ParticleIt_CellP<CellList> Pit; |
| 30 | |
| 31 | /*! \brief Return cellkeys vector |
| 32 | * |
| 33 | * \return vector of cell keys |
| 34 | * |
| 35 | */ |
| 36 | inline const openfpm::vector<size_t> & getKeys() const |
| 37 | { |
| 38 | return keys; |
| 39 | } |
| 40 | |
| 41 | /*! \brief Get a linear (1D-like) key from the coordinates and add to the getKeys vector |
| 42 | * |
| 43 | * \tparam S Cell list type |
| 44 | * |
| 45 | * \param obj Cell list object |
| 46 | * \param gk grid key |
| 47 | * \param m order of a curve |
| 48 | */ |
| 49 | template<typename S> void get_hkey(S & obj, grid_key_dx<dim> gk, size_t m) |
| 50 | { |
| 51 | size_t point[dim]; |
| 52 | |
| 53 | for (size_t i = 0; i < dim; i++) |
| 54 | { |
| 55 | point[i] = gk.get(i) + obj.getPadding(i); |
| 56 | } |
| 57 | |
| 58 | keys.add(obj.getGrid().LinIdPtr(static_cast<size_t *>(point))); |
| 59 | } |
| 60 | |
| 61 | template<typename S> void linearize_hkeys(S & obj, size_t m) |
| 62 | { |
| 63 | return; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | /*! \brief Class for an hilbert order processing of cell keys for CellList_gen implementation |
| 68 | * |
| 69 | * \tparam dim Dimansionality of the space |
| 70 | */ |
| 71 | template<unsigned int dim, typename CellList> |
| 72 | class Process_keys_hilb |
| 73 | { |
| 74 | //! vector for storing the cell keys |
| 75 | openfpm::vector<size_t> keys; |
| 76 | |
| 77 | //! vector for storing the particle keys |
| 78 | openfpm::vector<size_t> p_keys; |
| 79 | |
| 80 | //! Order of an hilbert curve |
| 81 | size_t m = 0; |
| 82 | |
| 83 | public: |
| 84 | |
| 85 | //! Particle Iterator produced by this key generator |
| 86 | typedef ParticleIt_CellP<CellList> Pit; |
| 87 | |
| 88 | /*! \brief Return cellkeys vector |
| 89 | * |
| 90 | * \return vector of cell keys |
| 91 | * |
| 92 | */ |
| 93 | inline const openfpm::vector<size_t> & getKeys() const |
| 94 | { |
| 95 | return keys; |
| 96 | } |
| 97 | |
| 98 | /*! \brief Get an hilbert key from the coordinates and add to the getKeys vector |
| 99 | * |
| 100 | * \tparam S Cell list type |
| 101 | * |
| 102 | * \param obj Cell list object |
| 103 | * \param gk grid key |
| 104 | * \param m order of a curve |
| 105 | */ |
| 106 | template<typename S> inline void get_hkey(S & obj, grid_key_dx<dim> gk, size_t m) |
| 107 | { |
| 108 | //An integer to handle errors |
| 109 | int err; |
| 110 | |
| 111 | uint64_t point[dim]; |
| 112 | |
| 113 | for (size_t i = 0; i < dim; i++) |
| 114 | { |
| 115 | point[i] = gk.get(i); |
| 116 | } |
| 117 | |
| 118 | size_t hkey = getHKeyFromIntCoord(m, dim, point, &err); |
| 119 | |
| 120 | keys.add(hkey); |
| 121 | } |
| 122 | |
| 123 | /*! \brief Get get the coordinates from hilbert key, linearize and add to the getKeys vector |
| 124 | * |
| 125 | * \tparam S Cell list type |
| 126 | * |
| 127 | * \param obj Cell list object |
| 128 | * \param m order of a curve |
| 129 | */ |
| 130 | template<typename S> inline void linearize_hkeys(S & obj, size_t m) |
| 131 | { |
| 132 | //An integer to handle errors |
| 133 | int err; |
| 134 | |
| 135 | //Array to handle output |
| 136 | uint64_t coord[dim]; |
| 137 | size_t coord2[dim]; |
| 138 | |
| 139 | keys.sort(); |
| 140 | |
| 141 | openfpm::vector<size_t> keys_new; |
| 142 | |
| 143 | for(size_t i = 0; i < obj.getKeys().size(); i++) |
| 144 | { |
| 145 | getIntCoordFromHKey(coord, m, dim, obj.getKeys().get(i), &err); |
| 146 | |
| 147 | for (size_t j = 0 ; j < dim ; j++) {coord2[j] = coord[j] + obj.getPadding(j);} |
| 148 | |
| 149 | keys_new.add(obj.getGrid().LinIdPtr(static_cast<size_t *>(coord2))); |
| 150 | } |
| 151 | |
| 152 | keys.swap(keys_new); |
| 153 | } |
| 154 | }; |
| 155 | |
| 156 | /*! \brief Class for an hilbert order processing of cell keys for CellList_gen implementation |
| 157 | * |
| 158 | * \tparam dim Dimansionality of the space |
| 159 | */ |
| 160 | template<unsigned int dim, typename CellList> |
| 161 | class Process_keys_grid |
| 162 | { |
| 163 | //! vector for storing the cell keys |
| 164 | openfpm::vector<size_t> keys; |
| 165 | |
| 166 | //! vector for storing the particle keys |
| 167 | openfpm::vector<size_t> p_keys; |
| 168 | |
| 169 | //! Order of an hilbert curve |
| 170 | size_t m = 0; |
| 171 | |
| 172 | public: |
| 173 | |
| 174 | //! Particle Iterator produced by this key generator |
| 175 | typedef ParticleIt_CellP<CellList> Pit; |
| 176 | |
| 177 | /*! \brief Return cellkeys vector |
| 178 | * |
| 179 | * \return vector of cell keys |
| 180 | * |
| 181 | */ |
| 182 | inline const openfpm::vector<size_t> & getKeys() const |
| 183 | { |
| 184 | return keys; |
| 185 | } |
| 186 | |
| 187 | /*! \brief Get an hilbert key from the coordinates and add to the getKeys vector |
| 188 | * |
| 189 | * \tparam S Cell list type |
| 190 | * |
| 191 | * \param obj Cell list object |
| 192 | * \param gk grid key |
| 193 | * \param m order of a curve |
| 194 | */ |
| 195 | template<typename S> inline void get_hkey(S & obj, grid_key_dx<dim> gk, size_t m) |
| 196 | { |
| 197 | uint64_t point[dim]; |
| 198 | |
| 199 | for (size_t i = 0; i < dim; i++) |
| 200 | { |
| 201 | point[i] = gk.get(i); |
| 202 | } |
| 203 | |
| 204 | size_t hkey = obj.getGrid().LinId(gk); |
| 205 | |
| 206 | keys.add(hkey); |
| 207 | } |
| 208 | |
| 209 | /*! \brief Get get the coordinates from hilbert key, linearize and add to the getKeys vector |
| 210 | * |
| 211 | * \tparam S Cell list type |
| 212 | * |
| 213 | * \param obj Cell list object |
| 214 | * \param m order of a curve |
| 215 | */ |
| 216 | template<typename S> inline void linearize_hkeys(S & obj, size_t m) |
| 217 | { |
| 218 | } |
| 219 | }; |
| 220 | |
| 221 | #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_PROCKEYS_HPP_ */ |
| 222 | |