OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Domain_NN_calculator_cart.hpp
1/*
2 * Domain_NN_calculator.hpp
3 *
4 * Created on: Nov 26, 2016
5 * Author: i-bird
6 */
7
8#ifndef SRC_DECOMPOSITION_DOMAIN_NN_CALCULATOR_CART_HPP_
9#define SRC_DECOMPOSITION_DOMAIN_NN_CALCULATOR_CART_HPP_
10
11#include <Vector/map_vector.hpp>
12#include "NN/CellList/ParticleItCRS_Cells.hpp"
13
20template<unsigned int dim>
22{
25
27
30
33
36
39
41
44
47
49
52
55
58
109 openfpm::vector<grid_key_dx<dim>> & dom_subsub,
111 const ::Box<dim,long int> & proc_box,
112 const openfpm::vector<::Box<dim, size_t>> & loc_box)
113 {
114 // Reset dom and dom_subsub
115 sub_keys.clear();
116 dom_subsub.clear();
117
118 size_t sz[dim];
119
120 // ----Grid size = proc_box.getHigh(j) - proc_box.getLow(j)
121 // +2 is padding
122
123 for (size_t j = 0 ; j < dim ; j++)
124 {sz[j] = proc_box.getHigh(j) - proc_box.getLow(j) + 2 + 1;}
125
126 gs.setDimensions(sz);
127
128 // Set the grid
130 g.setMemory();
131
132 for (size_t i = 0 ; i < dim ; i++)
133 {one.set_d(i,1);}
134
135 // Calculate the csr neighborhood
137 NNcalc_csr(csr);
138
139 // Draw the domain on this grid
140 for (size_t i = 0 ; i < loc_box.size() ; i++)
141 {
142 grid_key_dx<dim> start;
143 grid_key_dx<dim> stop;
144
145 for (size_t j = 0 ; j < dim ; j++)
146 {
147 start.set_d(j,loc_box.template get<0>(i)[j] - proc_box.getLow(j) + 1);
148 stop.set_d(j,loc_box.template get<1>(i)[j] - proc_box.getLow(j) + 1);
149 }
150
151 grid_key_dx_iterator_sub<dim> sub(g.getGrid(),start,stop);
152
153 while (sub.isNext())
154 {
155 auto key = sub.get();
156
157 for (size_t j = 0 ; j < csr.size() ; j++)
158 {
159 grid_key_dx<dim> src = key + csr.get(j).first;
160 grid_key_dx<dim> dst = key + csr.get(j).second;
161 g.template get<0>(src).add(dst);
162 }
163
164 dom_cells.add(key - one);
165
166 ++sub;
167 }
168 }
169
170 // Span all the grid point and take all the sub-sub-domains that has a
171 // neighborhood non-consistent to the normal symmetric NN, and the one that
172 // are consistent to NN symmetric
173 grid_key_dx_iterator<dim> it(g.getGrid());
174
175 while (it.isNext())
176 {
177 auto key = it.get();
178
179 // Adding in the list of the non-normal neighborhood cells
180 if (g.template get<0>(key).size() == openfpm::math::pow(3,dim)/2+1)
181 {
182 // Add in the list of the normal neighborhood list
183 dom_subsub.add(key - one);
184 }
185 else if (g.template get<0>(key).size() != 0)
186 {
187 sub_keys.add();
188 sub_keys.last().subsub = key - one;
189 // Adding the neighborhood of the cell
190
191 sub_keys.last().NN_subsub.resize(g.template get<0>(key).size());
192
193 for (size_t i = 0 ; i < g.template get<0>(key).size() ; i++)
194 {sub_keys.last().NN_subsub.get(i) = g.template get<0>(key).get(i) - one;}
195 }
196
197 ++it;
198 }
199 }
200
214 const grid_key_dx<dim> & shift,
215 const grid_sm<dim,void> & gs)
216 {
217 anom_lin.clear();
218 for (size_t i = 0 ; i < anom.size() ; i++)
219 {
220 grid_key_dx<dim> tmp = anom.get(i).subsub + shift;
221 anom_lin.add();
222 anom_lin.last().subsub = gs.LinId(tmp);
223
224 long int self_cell = -1;
225
226 for (size_t j = 0 ; j < anom.get(i).NN_subsub.size() ; j++)
227 {
228 grid_key_dx<dim> tmp = anom.get(i).NN_subsub.get(j) + shift;
229 anom_lin.get(i).NN_subsub.add((long int)gs.LinId(tmp) - anom_lin.get(i).subsub);
230
231 // This indicate that for example in the neighborhood of one cell it-self is included in the list
232 // For example the cell 100 is in the neighborhood of the cell 100
233 if (anom_lin.get(i).NN_subsub.last() == 0)
234 self_cell = anom_lin.get(i).NN_subsub.size() - 1;
235 }
236
237 // if exist the self interacting cell (Example cell 100 neighborhood of cell 100), this cell MUST BE ALWAYS at the beginning
238 if (self_cell != -1)
239 {
240 // bring the self-cell into the beginning
241 size_t tmp = anom_lin.get(i).NN_subsub.get(0);
242 anom_lin.get(i).NN_subsub.get(0) = 0;
243 anom_lin.get(i).NN_subsub.get(self_cell) = tmp;
244 }
245 }
246 }
247
248public:
249
252 {
253 }
254
261 {
262 this->proc_box = proc_box;
263 }
264
273 const grid_key_dx<dim> & shift,
274 const grid_sm<dim,void> & gs)
275 {
276 if (are_domain_anom_computed == false)
277 {
280
281 dom_cells_lin.clear();
282 for (size_t i = 0 ; i < dom_cells.size() ; i++)
283 {
284 grid_key_dx<dim> tmp = dom_cells.get(i) + shift;
285 dom_cells_lin.add(gs.LinId(tmp));
286 }
287
288
289 dom_lin.clear();
290 for (size_t i = 0 ; i < dom.size() ; i++)
291 {
292 grid_key_dx<dim> tmp = dom.get(i) + shift;
293 dom_lin.add(gs.LinId(tmp));
294 }
295
297 }
298 }
299
307 {
308 return dom_cells_lin;
309 }
310
318 {
319 return dom_lin;
320 }
321
329 {
330 return anom_lin;
331 }
332
333
338 void reset()
339 {
341 }
342};
343
344#endif /* SRC_DECOMPOSITION_DOMAIN_NN_CALCULATOR_CART_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
This class calculate processor domains and neighborhood of each processor domain.
void linearize_subsub(const openfpm::vector< subsub< dim > > &anom, openfpm::vector< subsub_lin< dim > > &anom_lin, const grid_key_dx< dim > &shift, const grid_sm< dim, void > &gs)
Linearize the sub-sub-domains ids.
openfpm::vector< size_t > & getCRSDomainCells()
Get the domain Cells.
openfpm::vector< size_t > dom_cells_lin
Set of linearized domain cells.
openfpm::vector< subsub_lin< dim > > & getCRSAnomDomainCells()
Get the domain anomalous cells.
void CalculateDomAndAnomCells(openfpm::vector< subsub< dim > > &sub_keys, openfpm::vector< grid_key_dx< dim > > &dom_subsub, openfpm::vector< grid_key_dx< dim > > &dom_cells, const ::Box< dim, long int > &proc_box, const openfpm::vector<::Box< dim, size_t > > &loc_box)
Calculate the subdomain that are in the skin part of the domain.
openfpm::vector< subsub_lin< dim > > anom_lin
Set of anomalous CRS domain cells linearized.
openfpm::vector< size_t > & getDomainCells()
Get the domain Cells.
openfpm::vector< grid_key_dx< dim > > dom
Set of normal domain cells for CRS.
grid_sm< dim, void > gs
Processor cells-grid.
openfpm::vector< subsub< dim > > anom
anomalous cell neighborhood for CRS
bool are_domain_anom_computed
True if domain and anomalous domain cells are computed.
void setParameters(const Box< dim, long int > &proc_box)
Set parameters to calculate the cell neighborhood.
void reset()
In case you have to recompute the indexes.
void setNNParameters(openfpm::vector<::Box< dim, size_t > > &loc_box, const grid_key_dx< dim > &shift, const grid_sm< dim, void > &gs)
Set parameters to calculate the cell neighborhood.
Box< dim, long int > proc_box
Processor box.
openfpm::vector< grid_key_dx< dim > > dom_cells
Set of domain cells.
grid_key_dx< dim > one
key with all coordinates set to one
openfpm::vector< size_t > dom_lin
Set of normal CRS domain cells linearized.
Declaration grid_key_dx_iterator_sub.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
bool isNext()
Check if there is the next element.
const grid_key_dx< dim > & get() const
Get the actual key.
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
Declaration grid_sm.
Definition grid_sm.hpp:167
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
Definition grid_sm.hpp:326
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition grid_sm.hpp:454
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
Linearized version of subsub.
sub-sub-domain