| 1 | /* |
| 2 | * basic.hpp |
| 3 | * |
| 4 | * Created on: Aug 8, 2015 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef SRC_DECOMPOSITION_COMMON_HPP_ |
| 9 | #define SRC_DECOMPOSITION_COMMON_HPP_ |
| 10 | |
| 11 | #define UNIQUE 1 |
| 12 | #define MULTIPLE 2 |
| 13 | |
| 14 | #include "Vector/map_vector.hpp" |
| 15 | |
| 16 | |
| 17 | /*! \brief Boundary conditions |
| 18 | * |
| 19 | * |
| 20 | */ |
| 21 | template<unsigned int dim> struct periodicity |
| 22 | { |
| 23 | size_t bc[dim]; |
| 24 | }; |
| 25 | |
| 26 | /*! \brief Boundary conditions |
| 27 | * |
| 28 | * |
| 29 | */ |
| 30 | template<unsigned int dim> struct periodicity_int |
| 31 | { |
| 32 | int bc[dim]; |
| 33 | }; |
| 34 | |
| 35 | /*! \brief for each sub-domain box sub contain the real the sub-domain id |
| 36 | * |
| 37 | * When we apply boundary conditions real sub-domains are copied along the border |
| 38 | * sub, contain the id of the real sub_domain |
| 39 | * |
| 40 | * \tparam dim Dimensionality of the box |
| 41 | * \tparam T in witch space this box live |
| 42 | * |
| 43 | */ |
| 44 | template<unsigned int dim, typename T> |
| 45 | struct Box_loc_sub |
| 46 | { |
| 47 | //! Box defining the sub-domain (copied) |
| 48 | Box<dim,T> bx; |
| 49 | |
| 50 | //! The id of the real domain |
| 51 | size_t sub; |
| 52 | |
| 53 | //! in witch sector this sub-domain live |
| 54 | comb<dim> cmb; |
| 55 | |
| 56 | //! Constructor |
| 57 | Box_loc_sub() |
| 58 | :sub(0) |
| 59 | { |
| 60 | cmb.zero(); |
| 61 | }; |
| 62 | |
| 63 | //! Constructor from box, domain id and sector where it live |
| 64 | Box_loc_sub(const Box<dim,T> & bx, size_t sub, const comb<dim> & cmb) |
| 65 | :bx(bx),sub(sub),cmb(cmb) |
| 66 | {}; |
| 67 | |
| 68 | //! Set the sub-domain box coordinates |
| 69 | Box_loc_sub operator=(const Box<dim,T> & box) |
| 70 | { |
| 71 | ::Box<dim,T>::operator=(box); |
| 72 | |
| 73 | return *this; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | }; |
| 78 | |
| 79 | /*! It contain a box definition and from witch sub-domain it come from (in the local processor list) |
| 80 | * and an unique if across adjacent processors (for communication) |
| 81 | * |
| 82 | * If the box come from the intersection of an expanded sub-domain and a sub-domain |
| 83 | * |
| 84 | * Assuming we are considering the near processors i (0 to getNNProcessors()) |
| 85 | * |
| 86 | * |
| 87 | */ |
| 88 | template<unsigned int dim, typename T> |
| 89 | struct Box_sub |
| 90 | { |
| 91 | //! Internal ghost box definition |
| 92 | Box<dim,T> bx; |
| 93 | |
| 94 | //! Domain id |
| 95 | size_t sub; |
| 96 | |
| 97 | //! see ebx_ibx_form in ie_ghost for the meaning |
| 98 | size_t id; |
| 99 | |
| 100 | //! see getNearSubdomainsRealId in nn_prcs |
| 101 | size_t r_sub; |
| 102 | |
| 103 | //! see ie_ghost follow sector explanation |
| 104 | comb<dim> cmb; |
| 105 | |
| 106 | //! Constructor reset cmb |
| 107 | Box_sub() |
| 108 | { |
| 109 | r_sub = (size_t)-1; |
| 110 | cmb.zero(); |
| 111 | |
| 112 | sub = (size_t)-1; |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | //! Particular case for local internal ghost boxes |
| 117 | template<unsigned int dim, typename T> |
| 118 | struct Box_sub_k |
| 119 | { |
| 120 | //! extension of this local internal ghost box |
| 121 | Box<dim,T> bx; |
| 122 | |
| 123 | //! Domain id |
| 124 | size_t sub; |
| 125 | |
| 126 | //! Where this sub_domain live |
| 127 | comb<dim> cmb; |
| 128 | |
| 129 | //! k \see getLocalGhostIBoxE |
| 130 | long int k; |
| 131 | |
| 132 | Box_sub_k() |
| 133 | :sub(0),k(-1) |
| 134 | { |
| 135 | cmb.zero(); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | template<unsigned int dim,typename T> using Box_map = aggregate<Box<dim,T>,long int>; |
| 140 | |
| 141 | /*template<unsigned int dim,typename T> |
| 142 | struct Box_map |
| 143 | { |
| 144 | typedef boost::fusion::vector<Box<dim,T>,long int> type; |
| 145 | |
| 146 | type data; |
| 147 | |
| 148 | static bool noPointers() |
| 149 | { |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | static const unsigned int max_prop = 2; |
| 154 | };*/ |
| 155 | |
| 156 | //! Case for local ghost box |
| 157 | template<unsigned int dim, typename T> |
| 158 | struct lBox_dom |
| 159 | { |
| 160 | //! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor |
| 161 | //! sub-domains (External ghost) |
| 162 | openfpm::vector_std< Box_sub_k<dim,T> > ebx; |
| 163 | |
| 164 | //! Intersection between the contiguous processor sub-domain enlarged by the ghost with the |
| 165 | //! local sub-domain (Internal ghost) |
| 166 | openfpm::vector_std< Box_sub_k<dim,T>> ibx; |
| 167 | }; |
| 168 | |
| 169 | //! Case for local external ghost box |
| 170 | template<unsigned int dim, typename T> |
| 171 | struct Box_proc |
| 172 | { |
| 173 | //! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor |
| 174 | //! sub-domains (External ghost) |
| 175 | openfpm::vector<::Box<dim,T>> bx; |
| 176 | |
| 177 | //! Intersection between the contiguous processor sub-domain enlarged by the ghost with the |
| 178 | //! local sub-domain (Internal ghost) |
| 179 | openfpm::vector<::Box<dim,T>> nbx; |
| 180 | |
| 181 | |
| 182 | //! processor |
| 183 | size_t proc; |
| 184 | }; |
| 185 | |
| 186 | //! Case for external ghost box |
| 187 | template<unsigned int dim, typename T> |
| 188 | struct Box_dom |
| 189 | { |
| 190 | //! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor |
| 191 | //! sub-domains (External ghost) |
| 192 | openfpm::vector_std< Box_sub<dim,T> > ebx; |
| 193 | |
| 194 | //! Intersection between the contiguous processor sub-domain enlarged by the ghost with the |
| 195 | //! local sub-domain (Internal ghost) |
| 196 | openfpm::vector_std< Box_sub<dim,T> > ibx; |
| 197 | }; |
| 198 | |
| 199 | // It store the sub-domain sent by the near processors |
| 200 | template<unsigned int dim, typename T> |
| 201 | struct N_box |
| 202 | { |
| 203 | //! id of the processor in the nn_processor list (local processor id) |
| 204 | size_t id; |
| 205 | |
| 206 | //! near processor sub-domains |
| 207 | typename openfpm::vector<::Box<dim,T>> bx; |
| 208 | |
| 209 | //! near processor sector position (or where they live outside the domain) |
| 210 | openfpm::vector<comb<dim>> pos; |
| 211 | |
| 212 | //! Number of real sub-domains or sub-domain in the central sector |
| 213 | size_t n_real_sub; |
| 214 | |
| 215 | //! When a sub-domain is not in the central sector, it mean that has been created |
| 216 | //! because of periodicity in a non central sector. Any sub-domain not in the central |
| 217 | //! sector is linked to one sub-domain in the central sector |
| 218 | openfpm::vector<size_t> r_sub; |
| 219 | |
| 220 | //! Default constructor |
| 221 | N_box() |
| 222 | :id((size_t)-1),n_real_sub(0) |
| 223 | {}; |
| 224 | |
| 225 | //! Copy constructor |
| 226 | N_box(const N_box<dim,T> & b) |
| 227 | :id((size_t)-1),n_real_sub(0) |
| 228 | { |
| 229 | this->operator=(b); |
| 230 | } |
| 231 | |
| 232 | //! Copy constructor |
| 233 | N_box(N_box<dim,T> && b) |
| 234 | :id((size_t)-1),n_real_sub(0) |
| 235 | { |
| 236 | this->operator=(b); |
| 237 | } |
| 238 | |
| 239 | /*! \brief Copy the element |
| 240 | * |
| 241 | * \param ele element to copy |
| 242 | * |
| 243 | * \return itself |
| 244 | * |
| 245 | */ |
| 246 | N_box<dim,T> & operator=(const N_box<dim,T> & ele) |
| 247 | { |
| 248 | id = ele.id; |
| 249 | bx = ele.bx; |
| 250 | pos = ele.pos; |
| 251 | n_real_sub = ele.n_real_sub; |
| 252 | r_sub = ele.r_sub; |
| 253 | |
| 254 | return * this; |
| 255 | } |
| 256 | |
| 257 | /*! \brief Copy the element |
| 258 | * |
| 259 | * \param ele element to copy |
| 260 | * |
| 261 | * \return itself |
| 262 | * |
| 263 | */ |
| 264 | N_box<dim,T> & operator=(N_box<dim,T> && ele) |
| 265 | { |
| 266 | id = ele.id; |
| 267 | bx.swap(ele.bx); |
| 268 | pos.swap(ele.pos); |
| 269 | n_real_sub = ele.n_real_sub; |
| 270 | r_sub.swap(ele.r_sub); |
| 271 | |
| 272 | return * this; |
| 273 | } |
| 274 | |
| 275 | /*! \brief Compare two N_box object |
| 276 | * |
| 277 | * \param ele element to compare with |
| 278 | * |
| 279 | * \return true if they match |
| 280 | * |
| 281 | */ |
| 282 | bool operator==(const N_box<dim,T> & ele) const |
| 283 | { |
| 284 | if (id != ele.id) |
| 285 | return false; |
| 286 | |
| 287 | if (pos != ele.pos) |
| 288 | return false; |
| 289 | |
| 290 | if (r_sub != ele.r_sub) |
| 291 | return false; |
| 292 | |
| 293 | if (n_real_sub != ele.n_real_sub) |
| 294 | return false; |
| 295 | |
| 296 | return bx == ele.bx; |
| 297 | } |
| 298 | |
| 299 | /*! \brief Compare two N_box object |
| 300 | * |
| 301 | * \param ele element to compare with |
| 302 | * |
| 303 | * \return true if they match |
| 304 | * |
| 305 | */ |
| 306 | bool operator!=(const N_box<dim,T> & ele) const |
| 307 | { |
| 308 | return ! this->operator==(ele); |
| 309 | } |
| 310 | }; |
| 311 | |
| 312 | //! It store all the boxes of the near processors in a linear array |
| 313 | template<unsigned int dim, typename T> |
| 314 | struct p_box |
| 315 | { |
| 316 | //! Box that identify the intersection of the ghost of the near processor with the |
| 317 | //! processor sub-domain |
| 318 | ::Box<dim,T> box; |
| 319 | //! local processor id |
| 320 | size_t lc_proc; |
| 321 | //! processor rank |
| 322 | size_t proc; |
| 323 | |
| 324 | //! shift vector id |
| 325 | size_t shift_id; |
| 326 | |
| 327 | /*! \brief Check if two p_box are the same |
| 328 | * |
| 329 | * \param pb box to check |
| 330 | * |
| 331 | * \return true if they match |
| 332 | * |
| 333 | */ |
| 334 | bool operator==(const p_box & pb) |
| 335 | { |
| 336 | return pb.lc_proc == lc_proc; |
| 337 | } |
| 338 | }; |
| 339 | |
| 340 | #endif /* SRC_DECOMPOSITION_COMMON_HPP_ */ |
| 341 | |