OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
57template<unsigned int dim, typename T, typename Decomposition>
58class 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
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
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
109public:
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_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
This class define the domain decomposition interface.
this class draw particles on subset of grid-like position
Box< dim, T > getBoxMargins()
Return the real Margin of the box.
T sp[dim]
Spacing.
Box< dim, T > domain
domain
Box< dim, T > sub_domain
sub_domain
Point< dim, T > ap
Actual point.
PointIterator & operator++()
Next point.
Point< dim, T > & get()
PointIterator(Decomposition &dec, size_t(&sz)[dim], const Box< dim, T > &domain, Box< dim, T > &sub_domain)
Draw Particles.
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
Given the decomposition it create an iterator.
grid_key_dx< Decomposition::dims > start
start key
grid_key_dx< Decomposition::dims > getStart()
Get the starting point of the sub-grid we are iterating.
grid_key_dx< Decomposition::dims > get()
Get the actual global key of the grid.
grid_key_dx< Decomposition::dims > getStop()
Get the starting point of the sub-grid we are iterating.
grid_key_dx< Decomposition::dims > stop
stop key
grid_dist_id_iterator_dec< Decomposition, ghost_or_domain > & operator++()
Get the next element.
bool isNext()
Check if there is the next element.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition grid_key.hpp:516
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503