OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
ParticleItCRS_Cells.hpp
1 /*
2  * CellListIterator_CRS.hpp
3  *
4  * Created on: Nov 14, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEITCRS_CELLS_HPP_
9 #define OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEITCRS_CELLS_HPP_
10 
11 #include "CellNNIterator.hpp"
12 #include "CellList_util.hpp"
13 #include "NN/CellList/NNc_array.hpp"
14 
20 template<unsigned int dim>
21 struct subsub
22 {
25 
28 };
29 
35 template<unsigned int dim>
36 struct subsub_lin
37 {
39  size_t subsub;
40 
43 };
44 
52 template<unsigned int dim,typename CellListType> class ParticleItCRS_Cells
53 {
54 private:
55 
57  const typename CellListType::Mem_type_type::loc_index * start;
58 
60  const typename CellListType::Mem_type_type::loc_index * stop;
61 
63  size_t cid;
64 
66  const long int * NNc;
67 
69  long int NNc_size;
70 
73  size_t dom_or_anom;
74 
77 
80 
82  //
83  // * * *
84  // x *
85  //
86  const NNc_array<dim,openfpm::math::pow(3,dim)/2+1> & NNc_sym;
87 
89  CellListType & cli;
90 
95  void selectValid()
96  {
97  while (start == stop)
98  {
99  cid++;
100 
101  size_t s_cell;
102  if (dom_or_anom == 0)
103  {
104  if (cid >= dom_cell.size())
105  {
106  dom_or_anom = 1;
107  cid = 0;
108 
109  // Terminate if we do not have anom cell
110  if (anom_dom_cell.size() == 0)
111  {
112  dom_or_anom = 2;
113  return;
114  }
115 
116  s_cell = anom_dom_cell.get(cid).subsub;
117  }
118  else
119  s_cell = dom_cell.get(cid);
120  }
121  else
122  {
123  if (cid >= anom_dom_cell.size())
124  {
125  dom_or_anom = 2;
126  return;
127  }
128 
129  s_cell = anom_dom_cell.get(cid).subsub;
130  }
131 
132  // Get the starting particle
133  start = &cli.getStartId(s_cell);
134 
135  // Get the stop particle
136  stop = &cli.getStopId(s_cell);
137  }
138  }
139 
140 public:
141 
151  ParticleItCRS_Cells(CellListType & cli,
154  const NNc_array<dim,openfpm::math::pow(3,dim)/2+1> & NNc_sym)
155  :cid(0),NNc(NULL),NNc_size(0),dom_or_anom(0),dom_cell(dom_cell),anom_dom_cell(anom_dom_cell),NNc_sym(NNc_sym),cli(cli)
156  {
157  size_t s_cell;
158  if (dom_cell.size() != 0)
159  s_cell = dom_cell.get(0);
160  else if (anom_dom_cell.size() != 0)
161  {
162  s_cell = anom_dom_cell.get(0).subsub;
163  dom_or_anom = 1;
164  }
165  else
166  {
167  dom_or_anom = 2;
168 
169  start = NULL;
170  stop = NULL;
171 
172  return;
173  }
174 
175  // Get the starting particle
176  start = &cli.getStartId(s_cell);
177 
178  // Get the stop particle
179  stop = &cli.getStopId(s_cell);
180 
181  selectValid();
182  }
183 
190  {
191  ++start;
192 
193  selectValid();
194 
195  return *this;
196  }
197 
203  bool isNext()
204  {
205  return dom_or_anom != 2;
206  }
207 
213  size_t get()
214  {
215  return *start;
216  }
217 
218 
234  typename CellListType::SymNNIterator getNNIteratorCSR(const openfpm::vector<Point<dim,typename CellListType::stype>> & v) const
235  {
236  if (dom_or_anom == 0)
237  return typename CellListType::SymNNIterator(dom_cell.get(cid),*start,NNc_sym.getPointer(),openfpm::math::pow(3,dim)/2+1,cli,v);
238  else
239  return typename CellListType::SymNNIterator(anom_dom_cell.get(cid).subsub,
240  *start,
241  &anom_dom_cell.get(cid).NN_subsub.get(0),
242  anom_dom_cell.get(cid).NN_subsub.size(),
243  cli,
244  v);
245  }
246 
263  {
264  if (dom_or_anom == 0)
265  return typename CellListType::SymNNIterator(dom_cell.get(cid),CellListType::getV(*start),CellListType::getP(*start),NNc_sym.getPointer(),openfpm::math::pow(3,dim)/2+1,cli,pos,v);
266  else
267  return typename CellListType::SymNNIterator(anom_dom_cell.get(cid).subsub,CellListType::getV(*start),CellListType::getP(*start),&anom_dom_cell.get(cid).NN_subsub.get(0),anom_dom_cell.get(cid).NN_subsub.size(),cli,pos,v);
268  }
269 };
270 
271 
272 #endif /* OPENFPM_DATA_SRC_NN_CELLLIST_PARTICLEITCRS_CELLS_HPP_ */
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
sub-sub-domain
const long int * getPointer() const
return the pointer to the array
Definition: NNc_array.hpp:146
size_t cid
Actual cell.
const openfpm::vector< subsub_lin< dim > > & anom_dom_cell
List of all anomalous domain cells with neighborhood.
grid_key_dx< dim > subsub
sub-sub-domain
ParticleItCRS_Cells & operator++()
Increment to the next particle.
ParticleItCRS_Cells(CellListType &cli, const openfpm::vector< size_t > &dom_cell, const openfpm::vector< subsub_lin< dim >> &anom_dom_cell, const NNc_array< dim, openfpm::math::pow(3, dim)/2+1 > &NNc_sym)
Initialize the iterator.
CellListType::SymNNIterator getNNIteratorCSR(const openfpm::vector< Point< dim, typename CellListType::stype >> &v) const
Get the neighborhood iterator according to the CRS scheme.
size_t size()
Stub size.
Definition: map_vector.hpp:70
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:22
Structure that contain a reference to a vector of particles.
openfpm::vector< long int > NN_subsub
Neighborhood of each sub-sub-domains (indicate the relative position compared to subsub) ...
const CellListType::Mem_type_type::loc_index * start
starting position
This iterator iterate across the particles of a Cell-list following the Cell structure.
long int NNc_size
Neighborhood size.
size_t subsub
sub-sub-domain
const NNc_array< dim, openfpm::math::pow(3, dim)/2+1 > & NNc_sym
The array contain the neighborhood of the cell-id in case of symmetric interaction.
CellListType::SymNNIterator getNNIteratorCSRM(const openfpm::vector< Point< dim, typename CellListType::stype >> &pos, const openfpm::vector< pos_v< dim, typename CellListType::stype >> &v) const
Get the neighborhood iterator according to the CRS scheme Multi-phase case.
void selectValid()
Adjust the counters to reach a valid particle element.
const CellListType::Mem_type_type::loc_index * stop
stop position
CellListType & cli
Celllist type.
bool isNext()
Return true if there is the next particle.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
const long int * NNc
Neighborhood.
Linearized version of subsub.
const openfpm::vector< size_t > & dom_cell
List of all the domain cells.
openfpm::vector< grid_key_dx< dim > > NN_subsub
Neighborhood of each sub-sub-domains.