1 | /* |
2 | * grid_dist_id_iterator_util.hpp |
3 | * |
4 | * Created on: Jan 6, 2017 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_UTIL_HPP_ |
9 | #define SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_UTIL_HPP_ |
10 | |
11 | |
12 | /*! \brief compute the subset where it has to iterate |
13 | * |
14 | * \param g_c Actual grid |
15 | * \param start iterator start in global coordinate |
16 | * \param stop iterator stop in global coordinate |
17 | * \param start_c adjusted start point for the grid g_c |
18 | * \param stop_c adjusted stop point for the grid g_c |
19 | * |
20 | * \return false if the sub-set does not contain points |
21 | * |
22 | */ |
23 | template<typename Decomposition> |
24 | static inline bool compute_subset_domain(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext, |
25 | size_t g_c, |
26 | grid_key_dx<Decomposition::dims> & start, |
27 | grid_key_dx<Decomposition::dims> & stop, |
28 | grid_key_dx<Decomposition::dims> & start_c, |
29 | grid_key_dx<Decomposition::dims> & stop_c) |
30 | { |
31 | if (gdb_ext.get(g_c).Dbox.isValid() == false) |
32 | {return false;} |
33 | |
34 | // Intersect the grid keys |
35 | |
36 | for (size_t i = 0 ; i < Decomposition::dims ; i++) |
37 | { |
38 | long int start_p = gdb_ext.get(g_c).Dbox.getP1().get(i) + gdb_ext.get(g_c).origin.get(i); |
39 | long int stop_p = gdb_ext.get(g_c).Dbox.getP2().get(i) + gdb_ext.get(g_c).origin.get(i); |
40 | if (start.get(i) <= start_p) |
41 | {start_c.set_d(i,gdb_ext.get(g_c).Dbox.getP1().get(i));} |
42 | else if (start.get(i) <= stop_p) |
43 | {start_c.set_d(i,start.get(i) - gdb_ext.get(g_c).origin.get(i));} |
44 | else |
45 | {return false;} |
46 | |
47 | if (stop.get(i) >= stop_p) |
48 | {stop_c.set_d(i,gdb_ext.get(g_c).Dbox.getP2().get(i));} |
49 | else if (stop.get(i) >= start_p) |
50 | {stop_c.set_d(i,stop.get(i) - gdb_ext.get(g_c).origin.get(i));} |
51 | else |
52 | {return false;} |
53 | } |
54 | |
55 | return true; |
56 | } |
57 | |
58 | /*! \brief compute the subset where it has to iterate |
59 | * |
60 | * \param g_c Actual grid |
61 | * \param start iterator start in global coordinate |
62 | * \param stop iterator stop in global coordinate |
63 | * \param start_c adjusted start point for the grid g_c |
64 | * \param stop_c adjusted stop point for the grid g_c |
65 | * |
66 | * \return false if the sub-set does not contain points |
67 | * |
68 | */ |
69 | template<typename Decomposition> |
70 | static inline bool compute_subset_ghost(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext, |
71 | size_t g_c, |
72 | grid_key_dx<Decomposition::dims> & start, |
73 | grid_key_dx<Decomposition::dims> & stop, |
74 | grid_key_dx<Decomposition::dims> & start_c, |
75 | grid_key_dx<Decomposition::dims> & stop_c) |
76 | { |
77 | // Intersect the grid keys |
78 | |
79 | for (size_t i = 0 ; i < Decomposition::dims ; i++) |
80 | { |
81 | long int start_p = gdb_ext.get(g_c).GDbox.getP1().get(i) + gdb_ext.get(g_c).origin.get(i); |
82 | long int stop_p = gdb_ext.get(g_c).GDbox.getP2().get(i) + gdb_ext.get(g_c).origin.get(i); |
83 | if (start.get(i) < start_p) |
84 | {start_c.set_d(i,gdb_ext.get(g_c).GDbox.getP1().get(i));} |
85 | else if (start.get(i) <= stop_p) |
86 | {start_c.set_d(i,start.get(i) - gdb_ext.get(g_c).origin.get(i));} |
87 | else |
88 | {return false;} |
89 | |
90 | if (stop.get(i) > stop_p) |
91 | {stop_c.set_d(i,gdb_ext.get(g_c).GDbox.getP2().get(i));} |
92 | else if (stop.get(i) >= start_p) |
93 | {stop_c.set_d(i,stop.get(i) - gdb_ext.get(g_c).origin.get(i));} |
94 | else |
95 | {return false;} |
96 | } |
97 | |
98 | return true; |
99 | } |
100 | |
101 | template<typename Decomposition, bool ghost_or_domain> |
102 | static inline bool compute_subset(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext, |
103 | size_t g_c, |
104 | grid_key_dx<Decomposition::dims> & start, |
105 | grid_key_dx<Decomposition::dims> & stop, |
106 | grid_key_dx<Decomposition::dims> & start_c, |
107 | grid_key_dx<Decomposition::dims> & stop_c) |
108 | { |
109 | if (ghost_or_domain == false) |
110 | {return compute_subset_domain<Decomposition>(gdb_ext,g_c,start,stop,start_c,stop_c);} |
111 | |
112 | return compute_subset_ghost<Decomposition>(gdb_ext,g_c,start,stop,start_c,stop_c); |
113 | } |
114 | |
115 | #endif /* SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATOR_UTIL_HPP_ */ |
116 | |