OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
main.cpp
1
23#include "Vector/vector_dist.hpp"
24
25int main(int argc, char* argv[])
26{
84
85 // initialize the library
86 openfpm_init(&argc,&argv);
87
88 // Here we define our domain a 2D box with internals from 0 to 1.0 for x and y
89 Box<2,float> domain({0.0,0.0},{1.0,1.0});
90
91 // Here we define the boundary conditions of our problem
92 size_t bc[2]={PERIODIC,PERIODIC};
93
94 // extended boundary around the domain, and the processor domain
95 Ghost<2,float> g(0.01);
96
97 // the scalar is the element at position 0 in the aggregate
98 constexpr int scalar = 0;
99
100 // the vector is the element at position 1 in the aggregate
101 constexpr int vector = 1;
102
103 // the tensor is the element at position 2 in the aggregate
104 constexpr int point = 2;
105
106 // A list1
107 constexpr int list = 3;
108
109 // A listA
110 constexpr int listA = 4;
111
112 // A list of list
113 constexpr int listlist = 5;
114
116
118
119 // The custom structure
120 struct A
121 {
122 float p1;
123 int p2;
124
125 A() {};
126
127 A(float p1, int p2)
128 :p1(p1),p2(p2)
129 {}
130 };
131
133
135
136 vector_dist<2,float, aggregate<float,
137 float[3],
142 vd(4096,domain,bc,g);
143
145
164
165 auto it = vd.getDomainIterator();
166
167 while (it.isNext())
168 {
169 auto p = it.get();
170
171 // we define x, assign a random position between 0.0 and 1.0
172 vd.getPos(p)[0] = (float)rand() / RAND_MAX;
173
174 // we define y, assign a random position between 0.0 and 1.0
175 vd.getPos(p)[1] = (float)rand() / RAND_MAX;
176
177
178 vd.getProp<scalar>(p) = 1.0;
179
180 vd.getProp<vector>(p)[0] = 1.0;
181 vd.getProp<vector>(p)[1] = 1.0;
182 vd.getProp<vector>(p)[2] = 1.0;
183
184 vd.getProp<point>(p).get(0) = 1.0;
185 vd.getProp<point>(p).get(1) = 1.0;
186 vd.getProp<point>(p).get(2) = 1.0;
187
188 size_t n_cp = (float)10.0 * rand()/RAND_MAX;
189
190 vd.getProp<listA>(p).resize(n_cp);
191
192 for (size_t i = 0 ; i < n_cp ; i++)
193 {
194 vd.getProp<list>(p).add(i + 10);
195 vd.getProp<list>(p).add(i + 20);
196 vd.getProp<list>(p).add(i + 30);
197
198 vd.getProp<listA>(p).get(i) = A(i+10.0,i+20.0);
199 }
200
201 vd.getProp<listlist>(p).resize(2);
202 vd.getProp<listlist>(p).get(0).resize(2);
203 vd.getProp<listlist>(p).get(1).resize(2);
204
205 vd.getProp<listlist>(p).get(0).get(0) = 1.0;
206 vd.getProp<listlist>(p).get(0).get(1) = 2.0;
207 vd.getProp<listlist>(p).get(1).get(0) = 3.0;
208 vd.getProp<listlist>(p).get(1).get(1) = 4.0;
209
210 // next particle
211 ++it;
212 }
213
215
238
239 // Particles are redistribued across the processors but only the scalar,vector, and point properties
240 // are transfert
241 vd.map_list<scalar,vector,point,list,listA,listlist>();
242
243 // Synchronize the ghost
244 vd.ghost_get<scalar,vector,point,listA,listlist>();
245
247
265
266 vd.write("particles");
267
269
284
285 size_t fg = vd.size_local();
286
287 Vcluster<> & v_cl = create_vcluster();
288 if (v_cl.getProcessUnitID() == 0)
289 {
290 for ( ; fg < vd.size_local()+4 ; fg++)
291 {
292 std::cout << "List of A" << std::endl;
293 for (size_t i = 0 ; i < vd.getProp<listA>(fg).size() ; i++)
294 std::cout << "Element: " << i << " p1=" << vd.getProp<listA>(fg).get(i).p1 << " p2=" << vd.getProp<listA>(fg).get(i).p2 << std::endl;
295
296 std::cout << "List of list" << std::endl;
297 for (size_t i = 0 ; i < vd.getProp<listlist>(fg).size() ; i++)
298 {
299 for (size_t j = 0 ; j < vd.getProp<listlist>(fg).get(i).size() ; j++)
300 std::cout << "Element: " << i << " " << j << " " << vd.getProp<listlist>(fg).get(i).get(j) << std::endl;
301 }
302 }
303 }
304
306
319
320 openfpm_finalize();
321
323
332}
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
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
Definition VCluster.hpp:59
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...