OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
grid_skin_iterator.hpp
1 /*
2  * grid_skin_iterator.hpp
3  *
4  * Created on: Jun 24, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_GRID_SKIN_ITERATOR_HPP_
9 #define OPENFPM_DATA_SRC_GRID_GRID_SKIN_ITERATOR_HPP_
10 
11 #include "grid_key_dx_iterator_sub_bc.hpp"
12 
53 template<unsigned int dim>
55 {
56 protected:
59 
60 private:
61 
63  size_t act;
64 
65 public:
66 
75  template <typename T> grid_skin_iterator_bc(const grid_sm<dim,T> & g_sm, const Box<dim,size_t> & A, const Box<dim,size_t> & B, const size_t (& bc)[dim])
76  :act(0)
77  {
78  for (size_t i = 0 ; i < dim ; i++)
79  {
82 
83  for (size_t j = 0 ; j < dim ; j++)
84  {
85  if (j == i)
86  {
87  k1.set_d(j,A.getHigh(j));
88  k2.set_d(j,B.getHigh(j));
89  }
90  else
91  {
92  if ( j < i )
93  {
94  k1.set_d(j,A.getLow(j)+1);
95  k2.set_d(j,A.getHigh(j)-1);
96  }
97  else
98  {
99  k1.set_d(j,B.getLow(j));
100  k2.set_d(j,B.getHigh(j));
101  }
102  }
103  }
104 
105  // Initialize a box from the keys and check if it is a valid box
106  Box<dim,long int> br(k1,k2);
107  if (br.isValid() == true)
108  sub_it[2*i].Initialize(g_sm,k1,k2,bc);
109 
110  for (size_t j = 0 ; j < dim ; j++)
111  {
112  if (j == i)
113  {
114  k1.set_d(j,B.getLow(j));
115  k2.set_d(j,A.getLow(j));
116  }
117  else
118  {
119  /* coverity[dead_error_line] */
120  if ( j < i )
121  {
122  k1.set_d(j,A.getLow(j)+1);
123  k2.set_d(j,A.getHigh(j)-1);
124  }
125  else
126  {
127  k1.set_d(j,B.getLow(j));
128  k2.set_d(j,B.getHigh(j));
129  }
130  }
131  }
132 
133  // Initialize a box from the keys and check if it is a valid box
134  Box<dim,long int> bl(k1,k2);
135  if (bl.isValid() == true && bl != br)
136  sub_it[2*i+1].Initialize(g_sm,k1,k2,bc);
137  }
138 
139  while (sub_it[act].isNext() == false)
140  act++;
141  }
142 
150  {
151  ++sub_it[act];
152 
153  while (act < 2*dim && sub_it[act].isNext() == false)
154  act++;
155 
156  return *this;
157  }
158 
166  bool isNext()
167  {
168  if (act < 2*dim)
169  {
171 
172  return true;
173  }
174 
176  return false;
177  }
178 
186  inline grid_key_dx<dim> get() const
187  {
188  return sub_it[act].get();
189  }
190 
194  void reset()
195  {
196  act = 0;
198 
199  for (size_t i = 0 ; i < 2*dim ; i++)
200  {sub_it[i].reset();}
201  }
202 };
203 
204 
205 #endif /* OPENFPM_DATA_SRC_GRID_GRID_SKIN_ITERATOR_HPP_ */
grid_skin_iterator_bc< dim > & operator++()
Get the next element.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:479
bool isValid() const
Check if the Box is a valid box P2 >= P1.
Definition: Box.hpp:997
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:490
size_t act
Actual iterator.
grid_skin_iterator_bc(const grid_sm< dim, T > &g_sm, const Box< dim, size_t > &A, const Box< dim, size_t > &B, const size_t(&bc)[dim])
Constructor require a grid_sm<dim,T>
void reset()
Reset the iterator (it restart from the beginning)
grid_key_dx_iterator_sub_bc< dim > sub_it[2 *dim]
Internal iterator for each faces.
void reset()
Reset the iterator (it restart from the beginning)
const grid_key_dx< dim > get() const
Return the actual grid key iterator.
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_key.hpp:407
bool isNext()
Check if there is the next element.