OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
53template<unsigned int dim>
55{
56protected:
59
60private:
61
63 size_t act;
64
65public:
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_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
bool isValid() const
Check if the Box is a valid box P2 >= P1.
Definition Box.hpp:1180
The same as grid_key_dx_iterator_sub_p but with periodic boundary.
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
grid_key_dx_iterator_sub_bc< dim > sub_it[2 *dim]
Internal iterator for each faces.
size_t act
Actual iterator.
void reset()
Reset the iterator (it restart from the beginning)
bool isNext()
Check if there is the next element.
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>
grid_key_dx< dim > get() const
Get the actual key.
grid_skin_iterator_bc< dim > & operator++()
Get the next element.
Declaration grid_sm.
Definition grid_sm.hpp:167