OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
main.cu
1 #define SYNC_BEFORE_TAKE_TIME
2 #include "Decomposition/Distribution/BoxDistribution.hpp"
3 #include "Grid/grid_dist_id.hpp"
4 #include "data_type/aggregate.hpp"
5 #include "timer.hpp"
6 
37 #ifdef __NVCC__
38 
39 constexpr int U = 0;
40 constexpr int V = 1;
41 constexpr int U_next = 2;
42 constexpr int V_next = 3;
43 
45 
46 typedef sgrid_dist_id_gpu<3,double,aggregate<double,double,double,double>, CudaMemory,Dec > sgrid_type;
47 
48 void draw_oscillation_shock(sgrid_type & grid, Box<3,double> & domain)
49 {
50  auto it = grid.getGridIterator();
51  Point<3,double> p({1.25,1.25,1.25});
52 
53 
54 // Point<3,double> u({1.0,0.0,0.0});
55 // Box<3,double> channel_box(p3,p1);
56 
57  double spacing_x = grid.spacing(0);
58  double spacing_y = grid.spacing(1);
59  double spacing_z = grid.spacing(2);
60 
61  typedef typename GetAddBlockType<sgrid_type>::type InsertBlockT;
62 
63  // Draw a shock expanding from 0.4 to 0.8 and than contracting from 0.8 to 0.4
64  for (int i = 0 ; i < 100 ; i++)
65  {
66  Sphere<3,double> sph(p,0.2 + (double)i/160.0);
67  Sphere<3,double> sph2(p,0.4 + (double)i/160.0);
68 
69  Box<3,size_t> bx;
70 
71  for (int j = 0 ; j < 3 ; j++)
72  {
73  bx.setLow(j,(size_t)((sph.center(j) - 0.4 - (double)i/160.0)/grid.spacing(j)));
74  bx.setHigh(j,(size_t)((sph.center(j) + 0.4 + (double)i/160.0)/grid.spacing(j)));
75  }
76 
77  timer t_add;
78  t_add.start();
79 
80  grid.addPoints(bx.getKP1(),bx.getKP2(),[spacing_x,spacing_y,spacing_z,sph,sph2] __device__ (int i, int j, int k)
81  {
82  Point<3,double> pc({i*spacing_x,j*spacing_y,k*spacing_z});
83 
84  // Check if the point is in the domain
85  if (sph2.isInside(pc) )
86  {
87  if (sph.isInside(pc) == false)
88  {return true;}
89  }
90 
91  return false;
92  },
93  [] __device__ (InsertBlockT & data, int i, int j, int k)
94  {
95  data.template get<U>() = 1.0;
96  data.template get<V>() = 0.0;
97  }
98  );
99 
100  t_add.stop();
101 
102  timer t_flush;
103  t_flush.start();
104  grid.template flush<smax_<U>,smax_<V>>(flush_type::FLUSH_ON_DEVICE);
105  t_flush.stop();
106 
107  timer t_ghost;
108  t_ghost.start();
109  grid.template ghost_get<U,V>(RUN_ON_DEVICE);
110  t_ghost.stop();
111  timer t_ghost2;
112  t_ghost2.start();
113  grid.template ghost_get<U,V>(RUN_ON_DEVICE | SKIP_LABELLING);
114  t_ghost2.stop();
115  std::cout << t_ghost.getwct() << std::endl;
116 
117  std::cout << "TIME ghost1: " << t_ghost.getwct() << " ghost2: " << t_ghost2.getwct() << " flush: " << t_flush.getwct() << " " << std::endl;
118 
119 
120  grid.removeUnusedBuffers();
121 
122  }
123 
124  std::cout << "Second Pass" <<std::endl;
125 
126  for (int i = 0 ; i < 100 ; i++)
127  {
128  Sphere<3,double> sph(p,0.2 + (double)i/160.0);
129  Sphere<3,double> sph2(p,0.4 + (double)i/160.0);
130 
131  Box<3,size_t> bx;
132 
133  for (int j = 0 ; j < 3 ; j++)
134  {
135  bx.setLow(j,(size_t)((sph.center(j) - 0.4 - (double)i/160.0)/grid.spacing(j)));
136  bx.setHigh(j,(size_t)((sph.center(j) + 0.4 + (double)i/160.0)/grid.spacing(j)));
137  }
138 
139  timer t_add;
140  t_add.start();
141 
142  grid.addPoints(bx.getKP1(),bx.getKP2(),[spacing_x,spacing_y,spacing_z,sph,sph2] __device__ (int i, int j, int k)
143  {
144  Point<3,double> pc({i*spacing_x,j*spacing_y,k*spacing_z});
145 
146  // Check if the point is in the domain
147  if (sph2.isInside(pc) )
148  {
149  if (sph.isInside(pc) == false)
150  {return true;}
151  }
152 
153  return false;
154  },
155  [] __device__ (InsertBlockT & data, int i, int j, int k)
156  {
157  data.template get<U>() = 1.0;
158  data.template get<V>() = 0.0;
159  }
160  );
161 
162  t_add.stop();
163 
164 
165  timer t_flush;
166  t_flush.start();
167  grid.template flush<smax_<U>,smax_<V>>(flush_type::FLUSH_ON_DEVICE);
168  t_flush.stop();
169 // grid.removeUnusedBuffers();
170 
171 
172  timer t_ghost;
173  t_ghost.start();
174  grid.template ghost_get<U,V>(RUN_ON_DEVICE);
175  t_ghost.stop();
176  timer t_ghost2;
177  t_ghost2.start();
178  grid.template ghost_get<U,V>(RUN_ON_DEVICE | SKIP_LABELLING);
179  t_ghost2.stop();
180 
181  std::cout << "TIME ghost1: " << t_ghost.getwct() << " ghost2: " << t_ghost2.getwct() << " flush: " << t_flush.getwct() << " " << std::endl;
182 
183 // if (i % 10 == 0)
184 // {
185 // grid.template deviceToHost<U,V>();
186 // grid.write_frame("Final",i);
187 // }
188  }
189 
190 }
191 
192 
193 int main(int argc, char* argv[])
194 {
195  openfpm_init(&argc,&argv);
196 
197  // domain
198  Box<3,double> domain({0.0,0.0,0.0},{2.5,2.5,2.5});
199 
200  // grid size
201  size_t sz[3] = {384,384,384};
202 
203  // Define periodicity of the grid
204  periodicity<3> bc = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
205 
206  // Ghost in grid unit
207  Ghost<3,long int> g(1);
208 
209  // deltaT
210  double deltaT = 0.025;
211 
212  // Diffusion constant for specie U
213  double du = 2*1e-5;
214 
215  // Diffusion constant for specie V
216  double dv = 1*1e-5;
217 
218 #ifdef TEST_RUN
219  // Number of timesteps
220  size_t timeSteps = 300;
221 #else
222  // Number of timesteps
223  size_t timeSteps = 50000;
224 #endif
225 
226  // K and F (Physical constant in the equation)
227  double K = 0.053;
228  double F = 0.014;
229 
230  grid_sm<3,void> gv({3,1,1});
231 
232  sgrid_type grid(sz,domain,g,bc,0,gv);
233 
234  grid.template setBackgroundValue<0>(-0.5);
235  grid.template setBackgroundValue<1>(-0.5);
236  grid.template setBackgroundValue<2>(-0.5);
237  grid.template setBackgroundValue<3>(-0.5);
238 
239  // spacing of the grid on x and y
240  double spacing[3] = {grid.spacing(0),grid.spacing(1),grid.spacing(2)};
241 
242  draw_oscillation_shock(grid,domain);
243 
244  grid.template deviceToHost<U,V>();
245  grid.write("Final");
246 
248 
260 
262  openfpm_finalize();
263 
265 
274 }
275 
276 #else
277 
278 int main(int argc, char* argv[])
279 {
280  return 0;
281 }
282 
283 #endif
284 
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:27
double getwct()
Return the elapsed real time.
Definition: timer.hpp:130
Definition: Ghost.hpp:39
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition: Box.hpp:544
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
Definition: Box.hpp:669
This class decompose a space into sub-sub-domains and distribute them across processors.
This is a distributed grid.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition: Box.hpp:533
void start()
Start the timer.
Definition: timer.hpp:90
This class represent an N-dimensional box.
Definition: Box.hpp:60
Declaration grid_sm.
Definition: grid_sm.hpp:147
This class implement the Sphere concept in an N-dimensional space.
Definition: Sphere.hpp:23
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
Definition: Box.hpp:656
Boundary conditions.
Definition: common.hpp:21
Class for cpu time benchmarking.
Definition: timer.hpp:27
void stop()
Stop the timer.
Definition: timer.hpp:119
[v_transform metafunction]