OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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)
117  :grid_dist_id_iterator_dec<Decomposition>(dec, sz, getStart(sz,domain,sub_domain,sp), getStop(sz,domain,sub_domain,sp)),sub_domain(sub_domain),domain(domain)
118  {
119  calculateAp();
120  }
121 
126  Point<dim,T> & get()
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_ */
Box< dim, T > getBoxMargins()
Return the real Margin of the box.
PointIterator & operator++()
Next point.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:479
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
Box< dim, T > sub_domain
sub_domain
T sp[dim]
Spacing.
Given the decomposition it create an iterator.
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:490
this class draw particles on subset of grid-like position
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:467
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
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.
grid_key_dx< Decomposition::dims > start
start key
bool isNext()
Check if there is the next element.
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
This class define the domain decomposition interface.
grid_key_dx< Decomposition::dims > get()
Get the actual global key of the grid.
grid_dist_id_iterator_dec< Decomposition > & operator++()
Get the next element.
grid_key_dx< Decomposition::dims > getStart()
Get the starting point of the sub-grid we are iterating.
grid_key_dx< Decomposition::dims > stop
stop key
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:456
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:201
grid_key_dx< Decomposition::dims > getStop()
Get the starting point of the sub-grid we are iterating.
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_key.hpp:407
Box< dim, T > domain
domain