OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
PointIterator.hpp
1 /*
2  * PointIterator.hpp
3  *
4  * Created on: Jan 3, 2017
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_DRAW_POINTITERATOR_HPP_
9 #define OPENFPM_NUMERICS_SRC_DRAW_POINTITERATOR_HPP_
10 
11 
57 template<unsigned int dim, typename T, typename Decomposition>
58 class PointIterator: protected grid_dist_id_iterator_dec<Decomposition>
59 {
62 
65 
68 
70  T sp[dim];
71 
72  static grid_key_dx<dim> getStart(size_t (& gs)[dim], const Box<dim,T> & dom, Box<dim,T> & sub_dom, T (& sp)[dim])
73  {
74  for (size_t i = 0 ; i < dim ; i++)
75  sp[i] = (dom.getHigh(i) - dom.getLow(i)) / (gs[i] -1);
76 
77  grid_key_dx<dim> pkey;
78 
79  for (size_t i = 0 ; i < dim ; i++)
80  pkey.set_d(i,std::ceil( (sub_dom.getLow(i) - dom.getLow(i)) / sp[i]));
81 
82  return pkey;
83  }
84 
85  static grid_key_dx<dim> getStop(size_t (& gs)[dim], const Box<dim,T> & dom, Box<dim,T> & sub_dom, T (& sp)[dim])
86  {
87  for (size_t i = 0 ; i < dim ; i++)
88  sp[i] = (dom.getHigh(i) - dom.getLow(i)) / (gs[i] - 1);
89 
90  grid_key_dx<dim> pkey;
91 
92  for (size_t i = 0 ; i < dim ; i++)
93  pkey.set_d(i,std::floor( (sub_dom.getHigh(i) - dom.getLow(i)) / sp[i]));
94 
95  return pkey;
96  }
97 
98  void calculateAp()
99  {
101  return;
102 
104 
105  for (size_t i = 0 ; i < dim ; i++)
106  ap.get(i) = key.get(i) * sp[i] + domain.getLow(i);
107  }
108 
109 public:
110 
116  PointIterator( Decomposition & dec, size_t (& sz)[dim], const Box<dim,T> & domain, Box<dim,T> & sub_domain)
118  {
119  calculateAp();
120  }
121 
127  {
128  return ap;
129  }
130 
137  {
139 
140  calculateAp();
141 
142  return *this;
143  }
144 
145  bool isNext()
146  {
148  }
149 
160  {
161  Box<dim,T> box;
162 
165 
166  for (size_t i = 0 ; i < dim ; i++)
167  {
168  box.setLow(i, start.get(i)*sp[i] + domain.getLow(i));
169  box.setHigh(i, stop.get(i)*sp[i] + domain.getLow(i));
170  }
171 
172  return box;
173  }
174 };
175 
176 
177 #endif /* OPENFPM_NUMERICS_SRC_DRAW_POINTITERATOR_HPP_ */
bool isNext()
Check if there is the next element.
grid_key_dx< Decomposition::dims > start
start key
Box< dim, T > getBoxMargins()
Return the real Margin of the box.
PointIterator & operator++()
Next point.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:556
Box< dim, T > sub_domain
sub_domain
T sp[dim]
Spacing.
Given the decomposition it create an iterator.
grid_key_dx< Decomposition::dims > stop
stop key
this class draw particles on subset of grid-like position
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition: grid_key.hpp:503
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
PointIterator(Decomposition &dec, size_t(&sz)[dim], const Box< dim, T > &domain, Box< dim, T > &sub_domain)
Draw Particles.
Point< dim, T > ap
Actual point.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:544
This class define the domain decomposition interface.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:533
grid_key_dx< Decomposition::dims > getStart()
Get the starting point of the sub-grid we are iterating.
This class represent an N-dimensional box.
Definition: Box.hpp:60
grid_dist_id_iterator_dec< Decomposition, ghost_or_domain > & operator++()
Get the next element.
Point< dim, T > & get()
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition: grid_key.hpp:516
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:567
grid_key_dx< Decomposition::dims > get()
Get the actual global key of the grid.
Box< dim, T > domain
domain
grid_key_dx< Decomposition::dims > getStop()
Get the starting point of the sub-grid we are iterating.