1/*
2 * grid_amr_dist_key_iterator.hpp
3 *
4 * Created on: Sep 22, 2017
5 * Author: i-bird
6 */
7
8#ifndef SRC_AMR_GRID_DIST_AMR_KEY_ITERATOR_HPP_
9#define SRC_AMR_GRID_DIST_AMR_KEY_ITERATOR_HPP_
10
11#include "Vector/map_vector.hpp"
12#include "Grid/Iterators/grid_dist_id_iterator.hpp"
13#include "grid_dist_amr_key.hpp"
14
15template<unsigned int dim, typename device_grid, typename device_sub_it, typename it_type = grid_dist_iterator<dim,device_grid,device_sub_it,FREE>>
16class grid_dist_amr_key_iterator
17{
18 //! Array of grid iterators
19 openfpm::vector<it_type> & git;
20
21 //! actual it type
22 struct actual_it
23 {
24 it_type & it;
25 };
26
27 //! Actual distributed grid iterator
28 it_type * a_it;
29
30 //! iterator pointer
31 size_t g_c;
32
33
34
35 /*! \brief from g_c increment g_c until you find a valid grid
36 *
37 */
38 void selectValidGrid()
39 {
40 // When the grid has size 0 potentially all the other informations are garbage
41 while (g_c < git.size() && git.get(g_c).isNext() == false ) g_c++;
42
43 // get the next grid iterator
44 if (g_c < git.size())
45 {
46 a_it = &git.get(g_c);
47 }
48 }
49
50public:
51
52 /*! \brief Constructor
53 *
54 * \param git vector of iterator
55 *
56 */
57 grid_dist_amr_key_iterator(openfpm::vector<it_type> & git)
58 :git(git),g_c(0)
59 {
60 a_it = &git.get(0);
61
62 selectValidGrid();
63 }
64
65
66 //! Destructor
67 ~grid_dist_amr_key_iterator()
68 {
69 }
70
71
72 /*! \brief Get the next element
73 *
74 * \return the next grid_key
75 *
76 */
77 inline grid_dist_amr_key_iterator<dim,device_grid,device_sub_it,it_type> & operator++()
78 {
79 ++(*a_it);
80
81 // check if a_it is at the end
82
83 if (a_it->isNext() == true)
84 {return *this;}
85 else
86 {
87 // switch to the new iterator
88 g_c++;
89
90 selectValidGrid();
91 }
92
93 return *this;
94 }
95
96 /*! \brief Is there a next point
97 *
98 * \return true is there is a next point
99 *
100 */
101 inline bool isNext()
102 {
103 return g_c < git.size();
104 }
105
106 /*! \brief Return the actual AMR grid iterator point
107 *
108 *
109 */
110 inline grid_dist_amr_key<dim> get()
111 {
112 return grid_dist_amr_key<dim>(g_c,a_it->get());
113 }
114
115 /*! \brief Return the actual global grid position in the AMR struct in global
116 * coordinates
117 *
118 *
119 */
120 inline grid_key_dx<dim> getGKey()
121 {
122 return git.get(g_c).getGKey(a_it->get());
123 }
124
125 /*! \brief Return the level at which we are
126 *
127 *
128 */
129 inline size_t getLvl() const
130 {
131 return g_c;
132 }
133};
134
135
136#endif /* SRC_AMR_GRID_DIST_AMR_KEY_ITERATOR_HPP_ */
137