OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
main.cpp
1#include "Vector/vector_dist.hpp"
2#include "data_type/aggregate.hpp"
3#include "Plot/GoogleChart.hpp"
4#include "Plot/util.hpp"
5#include "timer.hpp"
6
29int main(int argc, char* argv[])
30{
48
49 openfpm_init(&argc,&argv);
50
51 constexpr int gid = 0;
52 constexpr int nn_norm = 1;
53 constexpr int nn_sym = 2;
54
55 // used to define the domain
56 float L = 1000.0;
57
58 // Domain
59 Box<3,float> box({-L,-L,-L},{L,L,L});
60
61 // Boundary conditions
62 size_t bc[3]={PERIODIC,PERIODIC,PERIODIC};
63
64 // cut-off radius
65 float r_cut = 100.0;
66
67 // ghost
68 Ghost<3,float> ghost(r_cut);
69
70 // Point and global id
71 struct point_and_gid
72 {
73 // global id of the particle
74 size_t id;
75
76 // Position of the neighborhood particle
78
79 // Used to reorder the neighborhood particles by id
80 bool operator<(const struct point_and_gid & pag) const
81 {
82 return (id < pag.id);
83 }
84 };
85
87
106
107 // Particle properties list
109
111
133
134 // Distributed vector
135 vector_dist<3,float, part_prop > vd(4096,box,bc,ghost);
136
137 // used to calculate a global index for each particle
138 size_t start = vd.accum();
139
140 auto it = vd.getDomainIterator();
141
142 while (it.isNext())
143 {
144 auto key = it.get();
145
146 vd.getPos(key)[0] = 2.0*L*((float)rand()/RAND_MAX) - L;
147 vd.getPos(key)[1] = 2.0*L*((float)rand()/RAND_MAX) - L;
148 vd.getPos(key)[2] = 2.0*L*((float)rand()/RAND_MAX) - L;
149
150 vd.getProp<gid>(key) = key.getKey() + start;
151
152 ++it;
153 }
154
156
170
171 vd.map();
172
173 // sync the ghost
174 vd.ghost_get<gid>();
175
177
192
193 auto NN = vd.getCellList(r_cut);
194 auto p_it = vd.getDomainIterator();
195
196 while (p_it.isNext())
197 {
198 auto p = p_it.get();
199
200 Point<3,float> xp = vd.getPos(p);
201
202 auto Np = NN.getNNIterator(NN.getCell(vd.getPos(p)));
203
204 while (Np.isNext())
205 {
206 auto q = Np.get();
207
208 // skip self interaction
209 if (p.getKey() == q)
210 {
211 ++Np;
212 continue;
213 }
214
215 Point<3,float> xq = vd.getPos(q);
216 Point<3,float> f = (xp - xq);
217
218 float distance = f.norm();
219
220 // if the distance smalle than the cut-off radius add it to the neighborhood list
221 if (distance < r_cut )
222 {
223 vd.getProp<nn_norm>(p).add();
224 vd.getProp<nn_norm>(p).last().xq = xq;
225 vd.getProp<nn_norm>(p).last().id = vd.getProp<0>(q);
226 }
227
228 // Next neighborhood
229 ++Np;
230 }
231
232 // Next particle
233 ++p_it;
234 }
235
237
257
258 auto NN2 = vd.getCellListSym(r_cut);
259
260 auto p_it2 = vd.getDomainIterator();
261
262 while (p_it2.isNext())
263 {
264 auto p = p_it2.get();
265
266 Point<3,float> xp = vd.getPos(p);
267
268 auto Np = NN2.template getNNIteratorSym<NO_CHECK>(NN2.getCell(vd.getPos(p)),p.getKey(),vd.getPosVector());
269
270 while (Np.isNext())
271 {
272 auto q = Np.get();
273
274 if (p.getKey() == q)
275 {
276 ++Np;
277 continue;
278 }
279
280 // repulsive
281
282 Point<3,float> xq = vd.getPos(q);
283 Point<3,float> f = (xp - xq);
284
285 float distance = f.norm();
286
287 // Particle should be inside r_cut range
288
289 if (distance < r_cut )
290 {
291 vd.getProp<nn_sym>(p).add();
292 vd.getProp<nn_sym>(q).add();
293
294 vd.getProp<nn_sym>(p).last().xq = xq;
295 vd.getProp<nn_sym>(q).last().xq = xp;
296 vd.getProp<nn_sym>(p).last().id = vd.getProp<0>(q);
297 vd.getProp<nn_sym>(q).last().id = vd.getProp<0>(p);
298 }
299
300 ++Np;
301 }
302
303 ++p_it2;
304 }
305
306 vd.ghost_put<merge_,2>();
307
309
350
351 auto p_it3 = vd.getDomainIterator();
352
353 bool ret = true;
354 while (p_it3.isNext())
355 {
356 auto p = p_it3.get();
357
358 vd.getProp<nn_norm>(p).sort();
359 vd.getProp<nn_sym>(p).sort();
360
361 ret &= vd.getProp<nn_norm>(p).size() == vd.getProp<nn_sym>(p).size();
362
363 for (size_t i = 0 ; i < vd.getProp<1>(p).size() ; i++)
364 {
365 ret &= vd.getProp<nn_norm>(p).get(i).id == vd.getProp<nn_sym>(p).get(i).id;
366
367 if (box.isInside(vd.getProp<nn_norm>(p).get(i).xq) == true)
368 {
369 ret &= vd.getProp<nn_norm>(p).get(i).xq == vd.getProp<nn_sym>(p).get(i).xq;
370 }
371 }
372
373 ++p_it3;
374 }
375
376 if (ret != true)
377 {
378 std::cout << "ERROR" << std::endl;
379 exit(1);
380 }
381
383
396
397 openfpm_finalize();
398
400
409}
This class represent an N-dimensional box.
Definition Box.hpp:61
This class implement the point shape in an N-dimensional space.
Definition Point.hpp:28
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition Point.hpp:172
Implementation of 1-D std::vector like structure.
Distributed vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition ids.hpp:149
This structure define the operation add to use with copy general.