OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_key_dx_iterator_sub_bc.hpp
1 /*
2  * grid_key_dx_iterator_sub_p.hpp
3  *
4  * Created on: Dec 15, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SUB_BC_HPP_
9 #define OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SUB_BC_HPP_
10 
11 
12 
18 template<unsigned int dim, typename warn=print_warning_on_adjustment<dim>>
20 {
21  // Boundary condition
22  size_t bc[dim];
23 
24  // actual iterator box
25  size_t act;
26 
28  std::vector<Box<dim,size_t>> boxes;
29 
35  bool inline check_invalid(const grid_key_dx<dim> & key, const size_t (& bc)[dim])
36  {
37  for (size_t i = 0 ; i < dim ; i++)
38  {
39  if (bc[i] == NON_PERIODIC && key.get(i) != 1)
40  {
41  return true;
42  }
43  }
44 
45  return false;
46  }
47 
48 public:
49 
56  template<typename T> grid_key_dx_iterator_sub_bc(const grid_sm<dim,T> & g, const grid_key_dx<dim> & start , const grid_key_dx<dim> & stop, const size_t (& bc)[dim])
57  :act(0)
58  {
59  // copy the boundary conditions
60 
61  for (size_t i = 0 ; i < dim ; i++)
62  this->bc[i] = bc[i];
63 
64  // compile-time array {0,0,0,....} {2,2,2,...} {1,1,1,...}
65 
66  typedef typename generate_array<size_t,dim, Fill_zero>::result NNzero;
67  typedef typename generate_array<size_t,dim, Fill_two>::result NNtwo;
68  typedef typename generate_array<size_t,dim, Fill_three>::result NNthree;
69 
70  // Generate the sub-grid iterator
71 
72  grid_sm<dim,void> nn(NNthree::data);
73  grid_key_dx_iterator_sub<dim> it(nn,NNzero::data,NNtwo::data);
74 
75  // Box base
76  Box<dim,long int> base_b(start,stop);
77 
78  // intersect with all the boxes
79  while (it.isNext())
80  {
81  auto key = it.get();
82 
83  if (check_invalid(key,bc) == true)
84  {
85  ++it;
86  continue;
87  }
88 
89  bool intersect;
90 
91  // intersection box
92  Box<dim,long int> b_int;
93  Box<dim,long int> b_out;
94 
95  for (size_t i = 0 ; i < dim ; i++)
96  {
97  b_int.setLow(i,(key.get(i)-1)*g.getSize()[i]);
98  b_int.setHigh(i,key.get(i)*g.getSize()[i]-1);
99  }
100 
101  intersect = base_b.Intersect(b_int,b_out);
102 
103  // Bring to 0 and size[i]
104  for (size_t i = 0 ; i < dim ; i++)
105  {
106  if (bc[i] == PERIODIC)
107  {
108  b_out.setLow(i,openfpm::math::positive_modulo(b_out.getLow(i),g.size(i)));
109  b_out.setHigh(i,openfpm::math::positive_modulo(b_out.getHigh(i),g.size(i)));
110  }
111  }
112 
113  // if intersect add in the box list
114  if (intersect == true)
115  boxes.push_back(b_out);
116 
117  ++it;
118  }
119 
120  // initialize the first iterator
121  if (boxes.size() > 0)
123  }
124 
125 
135  {
138  {
139  return *this;
140  }
141  else
142  {
143  act++;
144  if (act < boxes.size())
146  }
147 
148  return *this;
149  }
150 
159  inline bool isNext()
160  {
161  return act < boxes.size();
162  }
163 
167  inline grid_key_dx<dim> get()
168  {
170  }
171 
175  inline void reset()
176  {
177  act = 0;
178  // initialize the first iterator
179  reinitialize(boxes.get(0).getKP1,boxes.get(0).getKP2);
180  }
181 };
182 
183 
184 #endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_GRID_KEY_DX_ITERATOR_SUB_BC_HPP_ */
void reinitialize(const grid_key_dx_iterator_sub< dim, warn > &g_s_it)
Reinitialize the iterator.
bool isNext()
Check if there is the next element.
bool check_invalid(const grid_key_dx< dim > &key, const size_t(&bc)[dim])
Check if the position is valid with the actual boundary conditions.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:484
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:552
grid_key_dx_iterator< dim > & operator++()
Get the next element.
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:495
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:472
bool isNext()
Check if there is the next element.
const grid_sm< dim, void > & getGridInfo()
Return the grid information related to this grid.
grid_key_dx_iterator_sub_bc< dim, warn > & operator++()
Get the next element.
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:302
bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
Definition: Box.hpp:93
The same as grid_key_dx_iterator_sub_p but with periodic boundary.
grid_key_dx< dim > get()
Return the actual grid key iterator.
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Definition: grid_sm.hpp:674
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:461
This class represent an N-dimensional box.
Definition: Box.hpp:56
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
std::vector< Box< dim, size_t > > boxes
Here we have all the boxes that this iterator produce.
void reset()
Reset the iterator (it restart from the beginning)
grid_key_dx_iterator_sub_bc(const grid_sm< dim, T > &g, const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop, const size_t(&bc)[dim])
Constructor.