OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
grid_dist_util.hpp
1 /*
2  * grid_dist_util.hpp
3  *
4  * Created on: Jan 28, 2016
5  * Author: i-bird
6  */
7 
8 #ifndef SRC_GRID_GRID_DIST_UTIL_HPP_
9 #define SRC_GRID_GRID_DIST_UTIL_HPP_
10 
11 #include "NN/CellList/CellDecomposer.hpp"
12 
21 template<unsigned int dim> void getCellDecomposerPar(size_t (& c_g)[dim], const size_t (& g_sz)[dim], const size_t (& bc)[dim])
22 {
23  for (size_t i = 0 ; i < dim ; i++)
24  {
25  if (bc[i] == NON_PERIODIC)
26  c_g[i] = (g_sz[i]-1 > 0)?(g_sz[i]-1):1;
27  else
28  c_g[i] = g_sz[i];
29  }
30 }
31 
36 template<unsigned int dim> struct periodicity
37 {
38  size_t bc[dim];
39 };
40 
48 template<unsigned int dim> periodicity<dim> create_non_periodic()
49 {
51 
52  for(size_t i = 0 ; i < dim ; i++)
53  p.bc[i] = NON_PERIODIC;
54 
55  return p;
56 }
57 
68 template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::vector<GBoxes<Decomposition::dims>> & gdb_ext, Decomposition & dec, CellDecomposer_sm<Decomposition::dims,typename Decomposition::stype,shift<dim,typename Decomposition::stype>> & cd_sm)
69 {
70  // Get the number of local grid needed
71  size_t n_grid = dec.getNSubDomain();
72 
73  // Allocate the grids
74  for (size_t i = 0 ; i < n_grid ; i++)
75  {
76  gdb_ext.add();
77 
78  // Get the local sub-domain (Grid conversion must be done with the domain P1 equivalent to 0.0)
79  // consider that the sub-domain with point P1 equivalent to the domain P1 is a (0,0,0) in grid unit
81  SpaceBox<Decomposition::dims, typename Decomposition::stype> sp_g = dec.getSubDomainWithGhost(i);
82 
83  // Because of round off we expand for safety the ghost area
84  // std::nextafter return the next bigger or smaller representable floating
85  // point number
86  for (size_t i = 0 ; i < Decomposition::dims ; i++)
87  {
88  sp_g.setLow(i,std::nextafter(sp_g.getLow(i),sp_g.getLow(i) - 1.0));
89  sp_g.setHigh(i,std::nextafter(sp_g.getHigh(i),sp_g.getHigh(i) + 1.0));
90  }
91 
92  // Convert from SpaceBox<dim,St> to SpaceBox<dim,long int>
93  SpaceBox<Decomposition::dims,long int> sp_t = cd_sm.convertDomainSpaceIntoGridUnits(sp,dec.periodicity());
94  SpaceBox<Decomposition::dims,long int> sp_tg = cd_sm.convertDomainSpaceIntoGridUnits(sp_g,dec.periodicity());
95 
97  gdb_ext.last().origin = sp_tg.getP1();
98 
99  // save information about the local grid: domain box seen inside the domain + ghost box (see GDBoxes for a visual meaning)
100  // and where the GDBox start, or the origin of the local grid (+ghost) in global coordinate
101  gdb_ext.last().Dbox = sp_t;
102  gdb_ext.last().Dbox -= sp_tg.getP1();
103 
104  gdb_ext.last().GDbox = sp_tg;
105  gdb_ext.last().GDbox -= sp_tg.getP1();
106  }
107 }
108 
119 template<int dim, typename Decomposition> inline void create_gdb_ext(openfpm::vector<GBoxes<dim>> & gdb_ext, Decomposition & dec, const size_t (& sz)[dim], const Box<Decomposition::dims,typename Decomposition::stype> & domain, typename Decomposition::stype (& spacing)[dim])
120 {
121  // Create the cell decomposer
122  CellDecomposer_sm<Decomposition::dims,typename Decomposition::stype, shift<Decomposition::dims,typename Decomposition::stype>> cd_sm;
123 
124  size_t cdp[dim];
125 
126  // Get the parameters to create a Cell-decomposer
127  getCellDecomposerPar<Decomposition::dims>(cdp,sz,dec.periodicity());
128 
129  // Careful cd_sm require the number of cell
130  cd_sm.setDimensions(domain,cdp,0);
131 
132  create_gdb_ext<dim,Decomposition>(gdb_ext,dec,cd_sm);
133 
134  // fill the spacing
135  for (size_t i = 0 ; i < dim ; i++)
136  {spacing[i] = cd_sm.getCellBox().getP2()[i];}
137 }
138 
142 template<unsigned int dim> struct i_box_id
143 {
146 
148  size_t g_id;
149 
151  size_t r_sub;
152 
155 
156 
157 
159  size_t sub;
160 };
161 
166 template<unsigned int dim> struct i_lbox_id
167 {
170 
172  size_t sub;
173 
175  size_t k;
176 
179 };
180 
185 template <unsigned int dim> struct e_box_id
186 {
189 
192 
195 
197  size_t g_id;
198 
200  size_t sub;
201 };
202 
207 template <unsigned int dim> struct e_lbox_id
208 {
211 
213  bool initialized = false;
214 
216  size_t sub;
217 
219  size_t k;
220 
223 };
224 
228 template <unsigned int dim> struct ip_box_grid
229 {
230  // ghost in grid units
232 
234  size_t prc;
235 };
236 
240 template <unsigned int dim> struct i_lbox_grid
241 {
242  // ghost in grid units
244 };
245 
249 template <unsigned int dim>struct ep_box_grid
250 {
251  // ghost in grid units
253 
255  size_t prc;
256 };
257 
261 template <unsigned int dim> struct e_lbox_grid
262 {
263  // ghost in grid units
265 };
266 
267 #endif /* SRC_GRID_GRID_DIST_UTIL_HPP_ */
This class represent an N-dimensional box.
Definition: SpaceBox.hpp:26
comb< dim > cmb
Sector position of the external ghost.
T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition: Box.hpp:479
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition: comb.hpp:34
local Internal ghost box
size_t sub
sub_id in which sub-domain this box live
it store an internal ghost box, the linked external ghost box and the sub-domain from where it come f...
T getHigh(int i) const
get the high interval of the box
Definition: Box.hpp:490
size_t g_id
id
Per-processor Internal ghost box.
void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:467
size_t sub
sub
::Box< dim, long int > box
Box.
comb< dim > cmb
Sector where it live the linked external ghost box.
size_t prc
processor id
Point< dim, T > getP1() const
Get the point p1.
Definition: Box.hpp:605
size_t k
external ghost box linked to this internal ghost box
size_t g_id
Id.
size_t sub
sub-domain id
It store the information about the local external ghost box.
This structure store the Box that define the domain inside the Ghost + domain box.
Definition: GBoxes.hpp:39
This class define the domain decomposition interface.
bool initialized
Has this external ghost box initialized.
it store a box, its unique id and the sub-domain from where it come from
size_t k
external ghost box linked to this internal ghost box
comb< dim > cmb
combination
void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:456
It store the information about the external ghost box.
This class represent an N-dimensional box.
Definition: Box.hpp:56
size_t sub
sub_id in which sub-domain this box live
::Box< dim, long int > box
Box defining the external ghost box in local coordinates.
Per-processor external ghost box.
::Box< dim, long int > l_e_box
Box defining the external ghost box in local coordinates.
::Box< dim, long int > g_e_box
Box defining the external ghost box in global coordinates.
Per-processor external ghost box.
size_t r_sub
r_sub id of the sub-domain in the sent list
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61
size_t prc
processor id
comb< dim > cmb
Sector position of the local external ghost box.
::Box< dim, long int > box
Box.