OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
grid_dist_id_iterator_util.hpp
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
23template<typename Decomposition>
24static inline bool compute_subset_domain(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext,
25 size_t g_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
69template<typename Decomposition>
70static inline bool compute_subset_ghost(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext,
71 size_t g_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
101template<typename Decomposition, bool ghost_or_domain>
102static inline bool compute_subset(const openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext,
103 size_t g_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_ */
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition grid_key.hpp:516
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503
Implementation of 1-D std::vector like structure.
This structure store the Box that define the domain inside the Ghost + domain box.
Definition GBoxes.hpp:40