OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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 
20 template<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  anom_lin.add();
221  anom_lin.last().subsub = gs.LinId(anom.get(i).subsub + shift);
222 
223  long int self_cell = -1;
224 
225  for (size_t j = 0 ; j < anom.get(i).NN_subsub.size() ; j++)
226  {
227  anom_lin.get(i).NN_subsub.add((long int)gs.LinId(anom.get(i).NN_subsub.get(j) + shift) - anom_lin.get(i).subsub);
228 
229  // This indicate that for example in the neighborhood of one cell it-self is included in the list
230  // For example the cell 100 is in the neighborhood of the cell 100
231  if (anom_lin.get(i).NN_subsub.last() == 0)
232  self_cell = anom_lin.get(i).NN_subsub.size() - 1;
233  }
234 
235  // if exist the self interacting cell (Example cell 100 neighborhood of cell 100), this cell MUST BE ALWAYS at the beginning
236  if (self_cell != -1)
237  {
238  // bring the self-cell into the beginning
239  size_t tmp = anom_lin.get(i).NN_subsub.get(0);
240  anom_lin.get(i).NN_subsub.get(0) = 0;
241  anom_lin.get(i).NN_subsub.get(self_cell) = tmp;
242  }
243  }
244  }
245 
246 public:
247 
250  {
251  }
252 
259  {
260  this->proc_box = proc_box;
261  }
262 
271  const grid_key_dx<dim> & shift,
272  const grid_sm<dim,void> & gs)
273  {
274  if (are_domain_anom_computed == false)
275  {
278 
279  dom_cells_lin.clear();
280  for (size_t i = 0 ; i < dom_cells.size() ; i++)
281  dom_cells_lin.add(gs.LinId(dom_cells.get(i) + shift));
282 
283 
284  dom_lin.clear();
285  for (size_t i = 0 ; i < dom.size() ; i++)
286  dom_lin.add(gs.LinId(dom.get(i) + shift));
287 
288  linearize_subsub(anom,anom_lin,shift,gs);
289  }
290  }
291 
299  {
300  return dom_cells_lin;
301  }
302 
310  {
311  return dom_lin;
312  }
313 
321  {
322  return anom_lin;
323  }
324 
325 
330  void reset()
331  {
332  are_domain_anom_computed = false;
333  }
334 };
335 
336 #endif /* SRC_DECOMPOSITION_DOMAIN_NN_CALCULATOR_CART_HPP_ */
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.
bool are_domain_anom_computed
True if domain and anomalous domain cells are computed.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition: grid_sm.hpp:337
openfpm::vector< subsub_lin< dim > > & getCRSAnomDomainCells()
Get the domain anomalous cells.
void setParameters(const Box< dim, long int > &proc_box)
Set parameters to calculate the cell neighborhood.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
sub-sub-domain
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.
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< dim > > anom
anomalous cell neighborhood for CRS
openfpm::vector< size_t > dom_cells_lin
Set of linearized domain cells.
grid_key_dx< dim > one
key with all coordinates set to one
size_t size()
Stub size.
Definition: map_vector.hpp:70
openfpm::vector< grid_key_dx< dim > > dom_cells
Set of domain cells.
openfpm::vector< size_t > & getCRSDomainCells()
Get the domain Cells.
grid_sm< dim, void > gs
Processor cells-grid.
openfpm::vector< subsub_lin< dim > > anom_lin
Set of anomalous CRS domain cells linearized.
void reset()
In case you have to recompute the indexes.
openfpm::vector< size_t > & getDomainCells()
Get the domain Cells.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:201
openfpm::vector< size_t > dom_lin
Set of normal CRS domain cells linearized.
This class calculate processor domains and neighborhood of each processor domain. ...
openfpm::vector< grid_key_dx< dim > > dom
Set of normal domain cells for CRS.
void set_d(size_t i, mem_id id)
Set the i index.
Definition: grid_key.hpp:407
Box< dim, long int > proc_box
Processor box.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
Linearized version of subsub.
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
Definition: grid_sm.hpp:229