1/*
2 * VTKWriter_unit_tests.hpp
3 *
4 * Created on: May 6, 2015
5 * Author: Pietro Incardona
6 */
7
8#ifndef VTKWRITER_UNIT_TESTS_HPP_
9#define VTKWRITER_UNIT_TESTS_HPP_
10
11#include "data_type/aggregate.hpp"
12#include <random>
13#include "VTKWriter.hpp"
14#include "util/SimpleRNG.hpp"
15
16BOOST_AUTO_TEST_SUITE( vtk_writer_test )
17
18/*! \brief Sub-domain vertex graph node
19 *
20 */
21struct vertex
22{
23 //! The node contain 3 unsigned long integer for communication computation memory and id
24 typedef boost::fusion::vector<float,float,float,float,size_t,double,unsigned char,long int> type;
25
26 //! type of the positional field
27 typedef float s_type;
28
29 //! Attributes name
30 struct attributes
31 {
32 static const std::string name[];
33 };
34
35 //! The data
36 type data;
37
38 //! x
39 static const unsigned int x = 0;
40 //! y
41 static const unsigned int y = 1;
42 //! z
43 static const unsigned int z = 2;
44 //! property 1
45 static const unsigned int prp1 = 3;
46 //! property 2
47 static const unsigned int prp2 = 4;
48 //! property 3
49 static const unsigned int prp3 = 5;
50 //! property 4
51 static const unsigned int prp4 = 6;
52 //! property 5
53 static const unsigned int prp5 = 7;
54
55 //! total number of properties boost::fusion::vector
56 static const unsigned int max_prop = 8;
57
58 /*!
59 * Default constructor
60 *
61 */
62 vertex()
63 {
64
65 }
66
67 static inline bool noPointers()
68 {
69 return true;
70 }
71
72 /*! \brief Initialize the VTKVertex
73 *
74 * \param x coordinate x
75 * \param y coordinate y
76 * \param z coordinate z
77 *
78 */
79 vertex(float x, float y, float z)
80 {
81 boost::fusion::at_c<vertex::x>(data) = x;
82 boost::fusion::at_c<vertex::y>(data) = y;
83 boost::fusion::at_c<vertex::z>(data) = z;
84 }
85};
86
87const std::string vertex::attributes::name[] = {"x","y","z","prp1","prp2","prp3","prp4","prp5"};
88
89struct vertex2
90{
91 //! The node contain 3 unsigned long integer for communication computation memory and id
92 typedef boost::fusion::vector<float[3],size_t,double> type;
93
94 //! type of the positional field
95 typedef float s_type;
96
97 //! Attributes name
98 struct attributes
99 {
100 static const std::string name[];
101 };
102
103 //! The data
104 type data;
105
106 //! computation property id in boost::fusion::vector
107 static const unsigned int x = 0;
108 static const unsigned int prp1 = 1;
109 static const unsigned int prp2 = 2;
110
111 //! total number of properties boost::fusion::vector
112 static const unsigned int max_prop = 3;
113
114 /*!
115 * Default constructor
116 *
117 */
118 vertex2()
119 {
120
121 }
122
123 static inline bool noPointers()
124 {
125 return true;
126 }
127
128 /*! \brief Initialize the VTKVertex
129 *
130 * \param x coordinate x
131 * \param y coordinate y
132 * \param z coordinate z
133 *
134 */
135 vertex2(float x, float y, float z)
136 {
137 boost::fusion::at_c<vertex::x>(data)[0] = x;
138 boost::fusion::at_c<vertex::x>(data)[1] = y;
139 boost::fusion::at_c<vertex::x>(data)[2] = z;
140 }
141};
142
143// use the vertex like the edge
144typedef vertex edge;
145
146const std::string vertex2::attributes::name[] = {"x","prp1","prp2"};
147
148
149
150BOOST_AUTO_TEST_CASE( vtk_writer_use_graph3D )
151{
152 Vcluster<> & v_cl = create_vcluster();
153
154 if (v_cl.getProcessUnitID() != 0)
155 return;
156
157 // Create some graphs and output them
158
159 // Graph
160
161 Graph_CSR<vertex2,edge> gr;
162
163 // Create a cube graph
164
165 gr.addVertex(vertex2(0.0,0.0,0.0));
166 gr.addVertex(vertex2(0.0,0.0,1.0));
167 gr.addVertex(vertex2(0.0,1.0,0.0));
168 gr.addVertex(vertex2(0.0,1.0,1.0));
169 gr.addVertex(vertex2(1.0,0.0,0.0));
170 gr.addVertex(vertex2(1.0,0.0,1.0));
171 gr.addVertex(vertex2(1.0,1.0,0.0));
172 gr.addVertex(vertex2(1.0,1.0,1.0));
173
174 gr.addEdge(0,6);
175 gr.addEdge(6,4);
176 gr.addEdge(4,0);
177
178 gr.addEdge(0,2);
179 gr.addEdge(2,6);
180 gr.addEdge(6,0);
181
182 gr.addEdge(0,3);
183 gr.addEdge(3,2);
184 gr.addEdge(2,0);
185
186 gr.addEdge(0,1);
187 gr.addEdge(1,3);
188 gr.addEdge(3,0);
189
190 gr.addEdge(2,7);
191 gr.addEdge(7,6);
192 gr.addEdge(6,2);
193
194 gr.addEdge(2,3);
195 gr.addEdge(3,7);
196 gr.addEdge(7,2);
197
198 gr.addEdge(4,6);
199 gr.addEdge(6,7);
200 gr.addEdge(7,4);
201
202 gr.addEdge(4,7);
203 gr.addEdge(7,5);
204 gr.addEdge(5,4);
205
206 gr.addEdge(0,4);
207 gr.addEdge(4,5);
208 gr.addEdge(5,0);
209
210 gr.addEdge(0,5);
211 gr.addEdge(5,1);
212 gr.addEdge(1,0);
213
214 gr.addEdge(1,5);
215 gr.addEdge(5,7);
216 gr.addEdge(7,1);
217
218 gr.addEdge(1,7);
219 gr.addEdge(7,3);
220 gr.addEdge(3,1);
221
222 // Write the VTK file
223
224 VTKWriter<Graph_CSR<vertex2,edge>,VTK_GRAPH> vtk(gr);
225 vtk.write("vtk_graph_v2.vtk");
226
227 // check that match
228
229 bool test = compare("vtk_graph_v2.vtk","test_data/vtk_graph_v2_test.vtk");
230 BOOST_REQUIRE_EQUAL(true,test);
231}
232
233BOOST_AUTO_TEST_CASE( vtk_writer_use_graph3D_edge )
234{
235 Vcluster<> & v_cl = create_vcluster();
236
237 if (v_cl.getProcessUnitID() != 0)
238 return;
239
240 // Create some graphs and output them
241
242 // Graph
243
244 Graph_CSR<vertex2,vertex2> gr;
245
246 // Create a cube graph
247
248 gr.addVertex(vertex2(0.0,0.0,0.0));
249 gr.addVertex(vertex2(0.0,0.0,1.0));
250 gr.addVertex(vertex2(0.0,1.0,0.0));
251 gr.addVertex(vertex2(0.0,1.0,1.0));
252 gr.addVertex(vertex2(1.0,0.0,0.0));
253 gr.addVertex(vertex2(1.0,0.0,1.0));
254 gr.addVertex(vertex2(1.0,1.0,0.0));
255 gr.addVertex(vertex2(1.0,1.0,1.0));
256
257 gr.addEdge(0,6,vertex2(0.0,0.0,1.0));
258 gr.addEdge(6,4,vertex2(0.0,0.0,1.0));
259 gr.addEdge(4,0,vertex2(0.0,0.0,1.0));
260
261 gr.addEdge(0,2,vertex2(0.0,0.0,1.0));
262 gr.addEdge(2,6,vertex2(0.0,0.0,1.0));
263 gr.addEdge(6,0,vertex2(0.0,0.0,1.0));
264
265 gr.addEdge(0,3,vertex2(0.0,0.0,1.0));
266 gr.addEdge(3,2,vertex2(0.0,0.0,1.0));
267 gr.addEdge(2,0,vertex2(0.0,0.0,1.0));
268
269 gr.addEdge(0,1,vertex2(0.0,0.0,1.0));
270 gr.addEdge(1,3,vertex2(0.0,0.0,1.0));
271 gr.addEdge(3,0,vertex2(0.0,0.0,1.0));
272
273 gr.addEdge(2,7,vertex2(0.0,0.0,1.0));
274 gr.addEdge(7,6,vertex2(0.0,0.0,1.0));
275 gr.addEdge(6,2,vertex2(0.0,0.0,1.0));
276
277 gr.addEdge(2,3,vertex2(0.0,0.0,1.0));
278 gr.addEdge(3,7,vertex2(0.0,0.0,1.0));
279 gr.addEdge(7,2,vertex2(0.0,0.0,1.0));
280
281 gr.addEdge(4,6,vertex2(0.0,0.0,1.0));
282 gr.addEdge(6,7,vertex2(0.0,0.0,1.0));
283 gr.addEdge(7,4,vertex2(0.0,0.0,1.0));
284
285 gr.addEdge(4,7,vertex2(0.0,0.0,1.0));
286 gr.addEdge(7,5,vertex2(0.0,0.0,1.0));
287 gr.addEdge(5,4,vertex2(0.0,0.0,1.0));
288
289 gr.addEdge(0,4,vertex2(0.0,0.0,1.0));
290 gr.addEdge(4,5,vertex2(0.0,0.0,1.0));
291 gr.addEdge(5,0,vertex2(0.0,0.0,1.0));
292
293 gr.addEdge(0,5,vertex2(0.0,0.0,1.0));
294 gr.addEdge(5,1,vertex2(0.0,0.0,1.0));
295 gr.addEdge(1,0,vertex2(0.0,0.0,1.0));
296
297 gr.addEdge(1,5,vertex2(0.0,0.0,1.0));
298 gr.addEdge(5,7,vertex2(0.0,0.0,1.0));
299 gr.addEdge(7,1,vertex2(0.0,0.0,1.0));
300
301 gr.addEdge(1,7,vertex2(0.0,0.0,1.0));
302 gr.addEdge(7,3,vertex2(0.0,0.0,1.0));
303 gr.addEdge(3,1,vertex2(0.0,0.0,1.0));
304
305 // Write the VTK file
306
307 VTKWriter<Graph_CSR<vertex2,vertex2>,VTK_GRAPH> vtk(gr);
308 vtk.write("vtk_graph_v4.vtk");
309
310 // check that match
311
312 bool test = compare("vtk_graph_v4.vtk","test_data/vtk_graph_v4_test.vtk");
313 BOOST_REQUIRE_EQUAL(true,test);
314}
315
316struct vertex3
317{
318 //! The node contain 3 unsigned long integer for communication computation memory and id
319 typedef boost::fusion::vector<float[2],size_t,double> type;
320
321 //! type of the positional field
322 typedef float s_type;
323
324 //! Attributes name
325 struct attributes
326 {
327 static const std::string name[];
328 };
329
330 //! The data
331 type data;
332
333 //! computation property id in boost::fusion::vector
334 static const unsigned int x = 0;
335 static const unsigned int prp1 = 1;
336 static const unsigned int prp2 = 2;
337
338 //! total number of properties boost::fusion::vector
339 static const unsigned int max_prop = 3;
340
341 /*!
342 * Default constructor
343 *
344 */
345 vertex3()
346 {
347
348 }
349
350 static inline bool noPointers()
351 {
352 return true;
353 }
354
355 /*! \brief Initialize the VTKVertex
356 *
357 * \param
358 *
359 */
360 vertex3(float x, float y)
361 {
362 boost::fusion::at_c<vertex::x>(data)[0] = x;
363 boost::fusion::at_c<vertex::x>(data)[1] = y;
364 }
365};
366
367// use the vertex like the edge
368typedef vertex edge;
369
370const std::string vertex3::attributes::name[] = {"x","prp1","prp2"};
371
372BOOST_AUTO_TEST_CASE( vtk_writer_use_graph2D )
373{
374 Vcluster<> & v_cl = create_vcluster();
375
376 if (v_cl.getProcessUnitID() != 0)
377 return;
378
379 // Create some graphs and output them
380
381 // Graph
382
383 Graph_CSR<vertex3,edge> gr;
384
385 // Create a cube graph
386
387 gr.addVertex(vertex3(0.0,0.0));
388 gr.addVertex(vertex3(0.0,1.0));
389 gr.addVertex(vertex3(1.0,0.0));
390 gr.addVertex(vertex3(1.0,1.0));
391
392 gr.addEdge(0,1);
393 gr.addEdge(1,3);
394 gr.addEdge(3,2);
395 gr.addEdge(2,0);
396
397 // Write the VTK file
398
399 VTKWriter<Graph_CSR<vertex3,edge>,VTK_GRAPH> vtk(gr);
400 vtk.write("vtk_graph_v3.vtk");
401
402 // check that match
403
404 bool test = compare("vtk_graph_v3.vtk","test_data/vtk_graph_v3_test.vtk");
405 BOOST_REQUIRE_EQUAL(true,test);
406}
407
408BOOST_AUTO_TEST_CASE( vtk_writer_use_graph)
409{
410 Vcluster<> & v_cl = create_vcluster();
411
412 if (v_cl.getProcessUnitID() != 0)
413 return;
414
415 // Create some graphs and output them
416
417 std::cout << "Graph unit test start" << "\n";
418
419 // Graph
420
421 Graph_CSR<vertex,edge> gr;
422
423 // Create a cube graph
424
425 gr.addVertex(vertex(0.0,0.0,0.0));
426 gr.addVertex(vertex(0.0,0.0,1.0));
427 gr.addVertex(vertex(0.0,1.0,0.0));
428 gr.addVertex(vertex(0.0,1.0,1.0));
429 gr.addVertex(vertex(1.0,0.0,0.0));
430 gr.addVertex(vertex(1.0,0.0,1.0));
431 gr.addVertex(vertex(1.0,1.0,0.0));
432 gr.addVertex(vertex(1.0,1.0,1.0));
433
434 gr.addEdge(0,6);
435 gr.addEdge(6,4);
436 gr.addEdge(4,0);
437
438 gr.addEdge(0,2);
439 gr.addEdge(2,6);
440 gr.addEdge(6,0);
441
442 gr.addEdge(0,3);
443 gr.addEdge(3,2);
444 gr.addEdge(2,0);
445
446 gr.addEdge(0,1);
447 gr.addEdge(1,3);
448 gr.addEdge(3,0);
449
450 gr.addEdge(2,7);
451 gr.addEdge(7,6);
452 gr.addEdge(6,2);
453
454 gr.addEdge(2,3);
455 gr.addEdge(3,7);
456 gr.addEdge(7,2);
457
458 gr.addEdge(4,6);
459 gr.addEdge(6,7);
460 gr.addEdge(7,4);
461
462 gr.addEdge(4,7);
463 gr.addEdge(7,5);
464 gr.addEdge(5,4);
465
466 gr.addEdge(0,4);
467 gr.addEdge(4,5);
468 gr.addEdge(5,0);
469
470 gr.addEdge(0,5);
471 gr.addEdge(5,1);
472 gr.addEdge(1,0);
473
474 gr.addEdge(1,5);
475 gr.addEdge(5,7);
476 gr.addEdge(7,1);
477
478 gr.addEdge(1,7);
479 gr.addEdge(7,3);
480 gr.addEdge(3,1);
481
482 // Write the VTK file
483
484 VTKWriter<Graph_CSR<vertex,edge>,VTK_GRAPH> vtk(gr);
485 vtk.write("vtk_graph.vtk");
486
487 // check that match
488
489 bool test = compare("vtk_graph.vtk","test_data/vtk_graph_test.vtk");
490 BOOST_REQUIRE_EQUAL(true,test);
491}
492
493BOOST_AUTO_TEST_CASE( vtk_writer_use_vector_box)
494{
495 Vcluster<> & v_cl = create_vcluster();
496
497 if (v_cl.getProcessUnitID() != 0)
498 return;
499
500 // Create a vector of boxes
501 openfpm::vector<Box<2,float>> vb;
502
503 vb.add(Box<2,float>({0.2,0.2},{1.0,0.5}));
504 vb.add(Box<2,float>({0.0,0.0},{0.2,0.2}));
505 vb.add(Box<2,float>({0.2,0.0},{0.5,0.2}));
506 vb.add(Box<2,float>({0.5,0.0},{1.0,0.2}));
507 vb.add(Box<2,float>({0.0,0.2},{0.2,0.5}));
508 vb.add(Box<2,float>({0.0,0.5},{1.0,1.0}));
509
510 // Create a writer and write
511 VTKWriter<openfpm::vector<Box<2,float>>,VECTOR_BOX> vtk_box;
512 vtk_box.add(vb);
513 vtk_box.write("vtk_box.vtk");
514
515 // Check that match
516 bool test = compare("vtk_box.vtk","test_data/vtk_box_test.vtk");
517 BOOST_REQUIRE_EQUAL(test,true);
518
519 // Create a vector of boxes
520 openfpm::vector<Box<3,float>> vb2;
521
522 vb2.add(Box<3,float>({0.2,0.2,0.0},{1.0,0.5,0.5}));
523 vb2.add(Box<3,float>({0.0,0.0,0.0},{0.2,0.2,0.5}));
524 vb2.add(Box<3,float>({0.2,0.0,0.0},{0.5,0.2,0.5}));
525 vb2.add(Box<3,float>({0.5,0.0,0.0},{1.0,0.2,0.5}));
526 vb2.add(Box<3,float>({0.0,0.2,0.0},{0.2,0.5,0.5}));
527 vb2.add(Box<3,float>({0.0,0.5,0.0},{1.0,1.0,0.5}));
528
529 // Create a writer and write
530 VTKWriter<openfpm::vector<Box<3,float>>,VECTOR_BOX> vtk_box2;
531 vtk_box2.add(vb2);
532 vtk_box2.write("vtk_box_3D.vtk");
533
534 // Check that match
535 test = compare("vtk_box_3D.vtk","test_data/vtk_box_3D_test.vtk");
536 BOOST_REQUIRE_EQUAL(test,true);
537
538 // Create a vector of boxes
539 openfpm::vector<Box<3,float>> vb3;
540 vb3.add(Box<3,float>({0.2,0.2,0.5},{1.0,0.5,1.0}));
541 vb3.add(Box<3,float>({0.0,0.0,0.5},{0.2,0.2,1.0}));
542 vb3.add(Box<3,float>({0.2,0.0,0.5},{0.5,0.2,1.0}));
543 vb3.add(Box<3,float>({0.5,0.0,0.5},{1.0,0.2,1.0}));
544 vb3.add(Box<3,float>({0.0,0.2,0.5},{0.2,0.5,1.0}));
545 vb3.add(Box<3,float>({0.0,0.5,0.5},{1.0,1.0,1.0}));
546
547 // Create a writer and write
548 VTKWriter<openfpm::vector<Box<3,float>>,VECTOR_BOX> vtk_box3;
549 vtk_box3.add(vb2);
550 vtk_box3.add(vb3);
551 vtk_box3.write("vtk_box_3D_2.vtk");
552
553 // Check that match
554 test = compare("vtk_box_3D_2.vtk","test_data/vtk_box_3D_2_test.vtk");
555 BOOST_REQUIRE_EQUAL(test,true);
556}
557
558/*! \brief fill the grid with some random data
559 *
560 * \param g Grid to fill
561 *
562 */
563template<typename grid_type> void fill_grid_some_data(grid_type & g)
564{
565 typedef Point_test<float> p;
566
567 auto it = g.getIterator();
568
569 while (it.isNext())
570 {
571 g.template get<p::x>(it.get()) = it.get().get(0);
572 if (grid_type::dims != 1)
573 {g.template get<p::y>(it.get()) = it.get().get(1);}
574 else
575 {g.template get<p::y>(it.get()) = 0.0;}
576 g.template get<p::z>(it.get()) = 0;
577 g.template get<p::s>(it.get()) = 1.0;
578 g.template get<p::v>(it.get())[0] = g.getGrid().LinId(it.get());
579 g.template get<p::v>(it.get())[1] = g.getGrid().LinId(it.get());
580 g.template get<p::v>(it.get())[2] = g.getGrid().LinId(it.get());
581
582 g.template get<p::t>(it.get())[0][0] = g.getGrid().LinId(it.get());
583 g.template get<p::t>(it.get())[0][1] = g.getGrid().LinId(it.get());
584 g.template get<p::t>(it.get())[0][2] = g.getGrid().LinId(it.get());
585 g.template get<p::t>(it.get())[1][0] = g.getGrid().LinId(it.get());
586 g.template get<p::t>(it.get())[1][1] = g.getGrid().LinId(it.get());
587 g.template get<p::t>(it.get())[1][2] = g.getGrid().LinId(it.get());
588 g.template get<p::t>(it.get())[2][0] = g.getGrid().LinId(it.get());
589 g.template get<p::t>(it.get())[2][1] = g.getGrid().LinId(it.get());
590 g.template get<p::t>(it.get())[2][2] = g.getGrid().LinId(it.get());
591
592 ++it;
593 }
594}
595
596/*! \brief fill the grid with some random data
597 *
598 * \param g Grid to fill
599 *
600 */
601void fill_grid_some_data_prp(grid_cpu<2,Point_test_prp<float>> & g)
602{
603 typedef Point_test<float> p;
604
605 auto it = g.getIterator();
606
607 while (it.isNext())
608 {
609 g.template get<p::x>(it.get()) = it.get().get(0);
610 g.template get<p::y>(it.get()) = it.get().get(1);
611 g.template get<p::z>(it.get()) = 0;
612 g.template get<p::s>(it.get()) = 1.0;
613 g.template get<p::v>(it.get())[0] = g.getGrid().LinId(it.get());
614 g.template get<p::v>(it.get())[1] = g.getGrid().LinId(it.get());
615 g.template get<p::v>(it.get())[2] = g.getGrid().LinId(it.get());
616
617 g.template get<p::t>(it.get())[0][0] = g.getGrid().LinId(it.get());
618 g.template get<p::t>(it.get())[0][1] = g.getGrid().LinId(it.get());
619 g.template get<p::t>(it.get())[0][2] = g.getGrid().LinId(it.get());
620 g.template get<p::t>(it.get())[1][0] = g.getGrid().LinId(it.get());
621 g.template get<p::t>(it.get())[1][1] = g.getGrid().LinId(it.get());
622 g.template get<p::t>(it.get())[1][2] = g.getGrid().LinId(it.get());
623 g.template get<p::t>(it.get())[2][0] = g.getGrid().LinId(it.get());
624 g.template get<p::t>(it.get())[2][1] = g.getGrid().LinId(it.get());
625 g.template get<p::t>(it.get())[2][2] = g.getGrid().LinId(it.get());
626
627 ++it;
628 }
629}
630
631/*! \brief fill the grid with some random data
632 *
633 *
634 */
635void fill_grid_some_data_scal(grid_cpu<2,Point_test_scal<float>> & g)
636{
637 typedef Point_test<float> p;
638
639 auto it = g.getIterator();
640
641 while (it.isNext())
642 {
643 g.template get<p::x>(it.get()) = it.get().get(0);
644 g.template get<p::y>(it.get()) = it.get().get(1);
645 g.template get<p::z>(it.get()) = 0;
646 g.template get<p::s>(it.get()) = 1.0;
647
648 ++it;
649 }
650}
651
652BOOST_AUTO_TEST_CASE( vtk_writer_use_grids)
653{
654 Vcluster<> & v_cl = create_vcluster();
655
656 if (v_cl.getProcessUnitID() != 0)
657 {return;}
658
659 {
660
661 // Create box grids
662 Point<1,float> offset1({0.0});
663 Point<1,float> spacing1({0.1});
664 Box<1,size_t> d1({1},{14});
665
666 // Create box grids
667 Point<1,float> offset2({5.0});
668 Point<1,float> spacing2({0.2});
669 Box<1,size_t> d2({2},{13});
670
671 // Create box grids
672 Point<1,float> offset3({0.0});
673 Point<1,float> spacing3({0.05});
674 Box<1,size_t> d3({3},{11});
675
676 // Create box grids
677 Point<1,float> offset4({5.0});
678 Point<1,float> spacing4({0.1});
679 Box<1,size_t> d4({1},{7});
680
681 size_t sz[] = {16};
682 grid_cpu<1,Point_test<float>> g1(sz);
683 g1.setMemory();
684 fill_grid_some_data(g1);
685 grid_cpu<1,Point_test<float>> g2(sz);
686 g2.setMemory();
687 fill_grid_some_data(g2);
688 grid_cpu<1,Point_test<float>> g3(sz);
689 g3.setMemory();
690 fill_grid_some_data(g3);
691 grid_cpu<1,Point_test<float>> g4(sz);
692 g4.setMemory();
693 fill_grid_some_data(g4);
694
695 // Create a writer and write
696 VTKWriter<boost::mpl::pair<grid_cpu<1,Point_test<float>>,float>,VECTOR_GRIDS> vtk_g;
697 vtk_g.add(g1,offset1,spacing1,d1);
698 vtk_g.add(g2,offset2,spacing2,d2);
699 vtk_g.add(g3,offset3,spacing3,d3);
700 vtk_g.add(g4,offset4,spacing4,d4);
701
702 openfpm::vector<std::string> prp_names;
703 vtk_g.write("vtk_grids_1d.vtk",prp_names);
704
705 #ifndef SE_CLASS3
706
707 // Check that match
708 bool test = compare("vtk_grids_1d.vtk","test_data/vtk_grids_test_1d.vtk");
709 BOOST_REQUIRE_EQUAL(test,true);
710
711 #endif
712 }
713
714 {
715
716 // Create box grids
717 Point<2,float> offset1({0.0,0.0});
718 Point<2,float> spacing1({0.1,0.2});
719 Box<2,size_t> d1({1,2},{14,15});
720
721 // Create box grids
722 Point<2,float> offset2({5.0,7.0});
723 Point<2,float> spacing2({0.2,0.1});
724 Box<2,size_t> d2({2,1},{13,15});
725
726 // Create box grids
727 Point<2,float> offset3({0.0,7.0});
728 Point<2,float> spacing3({0.05,0.07});
729 Box<2,size_t> d3({3,2},{11,10});
730
731 // Create box grids
732 Point<2,float> offset4({5.0,0.0});
733 Point<2,float> spacing4({0.1,0.1});
734 Box<2,size_t> d4({1,1},{7,7});
735
736 size_t sz[] = {16,16};
737 grid_cpu<2,Point_test<float>> g1(sz);
738 g1.setMemory();
739 fill_grid_some_data(g1);
740 grid_cpu<2,Point_test<float>> g2(sz);
741 g2.setMemory();
742 fill_grid_some_data(g2);
743 grid_cpu<2,Point_test<float>> g3(sz);
744 g3.setMemory();
745 fill_grid_some_data(g3);
746 grid_cpu<2,Point_test<float>> g4(sz);
747 g4.setMemory();
748 fill_grid_some_data(g4);
749
750 // Create a writer and write
751 VTKWriter<boost::mpl::pair<grid_cpu<2,Point_test<float>>,float>,VECTOR_GRIDS> vtk_g;
752 vtk_g.add(g1,offset1,spacing1,d1);
753 vtk_g.add(g2,offset2,spacing2,d2);
754 vtk_g.add(g3,offset3,spacing3,d3);
755 vtk_g.add(g4,offset4,spacing4,d4);
756
757 openfpm::vector<std::string> prp_names;
758 vtk_g.write("vtk_grids.vtk",prp_names);
759
760 #ifndef SE_CLASS3
761
762 // Check that match
763 bool test = compare("vtk_grids.vtk","test_data/vtk_grids_test.vtk");
764 BOOST_REQUIRE_EQUAL(test,true);
765
766 #endif
767 }
768
769 {
770 // Create box grids
771 Point<2,float> offset1({0.0,0.0});
772 Point<2,float> spacing1({0.1,0.1});
773 Box<2,size_t> d1({1,2},{14,15});
774
775 // Create box grids
776 Point<2,float> offset2({0.0,0.0});
777 Point<2,float> spacing2({0.1,0.1});
778 Box<2,size_t> d2({2,1},{13,15});
779
780 // Create box grids
781 Point<2,float> offset3({5.0,5.0});
782 Point<2,float> spacing3({0.1,0.1});
783 Box<2,size_t> d3({3,2},{11,10});
784
785 // Create box grids
786 Point<2,float> offset4({5.0,5.0});
787 Point<2,float> spacing4({0.1,0.1});
788 Box<2,size_t> d4({1,1},{7,7});
789
790 size_t sz[] = {16,16};
791 grid_cpu<2,Point_test<float>> g1(sz);
792 g1.setMemory();
793 fill_grid_some_data(g1);
794 grid_cpu<2,Point_test<float>> g2(sz);
795 g2.setMemory();
796 fill_grid_some_data(g2);
797 grid_cpu<2,Point_test<float>> g3(sz);
798 g3.setMemory();
799 fill_grid_some_data(g3);
800 grid_cpu<2,Point_test<float>> g4(sz);
801 g4.setMemory();
802 fill_grid_some_data(g4);
803
804 comb<2> cmb;
805 cmb.zero();
806
807 comb<2> cmb2;
808 cmb2.mone();
809
810 // Create a writer and write
811 VTKWriter<boost::mpl::pair<grid_cpu<2,Point_test<float>>,float>,VECTOR_ST_GRIDS> vtk_g;
812 vtk_g.add(0,g1,offset1,spacing1,d1,cmb);
813 vtk_g.add(0,g2,offset2,spacing2,d2,cmb);
814 vtk_g.add(1,g3,offset3,spacing3,d3,cmb);
815 vtk_g.add(1,g4,offset4,spacing4,d4,cmb2);
816
817 vtk_g.write("vtk_grids_st.vtk");
818
819 // Check that match
820 bool test = compare("vtk_grids_st.vtk","test_data/vtk_grids_st_test.vtk");
821 BOOST_REQUIRE_EQUAL(test,true);
822 }
823
824 {
825 // Create box grids
826 Point<2,float> offset1({0.0,0.0});
827 Point<2,float> spacing1({0.1,0.1});
828 Box<2,size_t> d1({1,2},{14,15});
829
830 // Create box grids
831 Point<2,float> offset2({0.0,0.0});
832 Point<2,float> spacing2({0.1,0.1});
833 Box<2,size_t> d2({2,1},{13,15});
834
835 // Create box grids
836 Point<2,float> offset3({5.0,5.0});
837 Point<2,float> spacing3({0.1,0.1});
838 Box<2,size_t> d3({3,2},{11,10});
839
840 // Create box grids
841 Point<2,float> offset4({5.0,5.0});
842 Point<2,float> spacing4({0.1,0.1});
843 Box<2,size_t> d4({1,1},{7,7});
844
845 size_t sz[] = {16,16};
846 grid_cpu<2,Point_test_scal<float>> g1(sz);
847 g1.setMemory();
848 fill_grid_some_data_scal(g1);
849 grid_cpu<2,Point_test_scal<float>> g2(sz);
850 g2.setMemory();
851 fill_grid_some_data_scal(g2);
852 grid_cpu<2,Point_test_scal<float>> g3(sz);
853 g3.setMemory();
854 fill_grid_some_data_scal(g3);
855 grid_cpu<2,Point_test_scal<float>> g4(sz);
856 g4.setMemory();
857 fill_grid_some_data_scal(g4);
858
859 // Create a writer and write
860 VTKWriter<boost::mpl::pair<grid_cpu<2,Point_test_scal<float>>,float>,VECTOR_GRIDS> vtk_g;
861 vtk_g.add(g1,offset1,spacing1,d1);
862 vtk_g.add(g2,offset2,spacing2,d2);
863 vtk_g.add(g3,offset3,spacing3,d3);
864 vtk_g.add(g4,offset4,spacing4,d4);
865
866 openfpm::vector<std::string> prp_names;
867 vtk_g.write("vtk_grids_prp.vtk",prp_names);
868
869 // Check that match
870 bool test = compare("vtk_grids_prp.vtk","test_data/vtk_grids_prp_test.vtk");
871 BOOST_REQUIRE_EQUAL(test,true);
872 }
873
874 {
875 // Create box grids
876 Point<2,float> offset1({0.0,0.0});
877 Point<2,float> spacing1({0.1,0.2});
878 Box<2,size_t> d1({1,2},{14,15});
879
880 // Create box grids
881 Point<2,float> offset2({5.0,7.0});
882 Point<2,float> spacing2({0.2,0.1});
883 Box<2,size_t> d2({2,1},{13,15});
884
885 // Create box grids
886 Point<2,float> offset3({0.0,7.0});
887 Point<2,float> spacing3({0.05,0.07});
888 Box<2,size_t> d3({3,2},{11,10});
889
890 // Create box grids
891 Point<2,float> offset4({5.0,0.0});
892 Point<2,float> spacing4({0.1,0.1});
893 Box<2,size_t> d4({1,1},{7,7});
894
895 size_t sz[] = {16,16};
896 grid_cpu<2,aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> > g1(sz);
897 g1.setMemory();
898 fill_grid_some_data(g1);
899 grid_cpu<2,aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> > g2(sz);
900 g2.setMemory();
901 fill_grid_some_data(g2);
902 grid_cpu<2,aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> > g3(sz);
903 g3.setMemory();
904 fill_grid_some_data(g3);
905 grid_cpu<2,aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> > g4(sz);
906 g4.setMemory();
907 fill_grid_some_data(g4);
908
909 // Create a writer and write
910 VTKWriter<boost::mpl::pair<grid_cpu<2,aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> >,float>,VECTOR_GRIDS> vtk_g;
911 vtk_g.add(g1,offset1,spacing1,d1);
912 vtk_g.add(g2,offset2,spacing2,d2);
913 vtk_g.add(g3,offset3,spacing3,d3);
914 vtk_g.add(g4,offset4,spacing4,d4);
915
916 openfpm::vector<std::string> prp_names;
917 vtk_g.write("vtk_grids_unk.vtk",prp_names);
918
919#ifndef SE_CLASS3
920
921 // Check that match
922 bool test = compare("vtk_grids_unk.vtk","test_data/vtk_grids_test.vtk");
923 BOOST_REQUIRE_EQUAL(test,true);
924
925#endif
926
927 }
928
929 // Try
930
931 {
932 bool ret = is_vtk_writable<Point<3,float>>::value;
933 BOOST_REQUIRE_EQUAL(ret,true);
934 ret = is_vtk_writable<Point<3,double>>::value;
935 BOOST_REQUIRE_EQUAL(ret,true);
936
937 int dims = vtk_dims<Point<3,float>>::value;
938 BOOST_REQUIRE_EQUAL(dims,3);
939
940 dims = vtk_dims<long int>::value;
941 BOOST_REQUIRE_EQUAL(dims,1);
942 }
943
944}
945
946
947BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set )
948{
949 Vcluster<> & v_cl = create_vcluster();
950
951 if (v_cl.getProcessUnitID() != 0)
952 return;
953
954 {
955 // Create 3 vectors with random particles
956 openfpm::vector<Point<3,double>> v1ps;
957 openfpm::vector<Point<3,double>> v2ps;
958 openfpm::vector<Point<3,double>> v3ps;
959 openfpm::vector<aggregate<float,float[3]>> v1pp;
960 openfpm::vector<aggregate<float,float[3]>> v2pp;
961 openfpm::vector<aggregate<float,float[3]>> v3pp;
962 openfpm::vector<aggregate<float,Point<3,float>>> v4pp;
963
964 // set the seed
965 // create the random generator engine
966 SimpleRNG rng;
967
968 // fill the vector with random data
969 v1ps.resize(100);
970 v2ps.resize(100);
971 v3ps.resize(100);
972
973 v1pp.resize(100);
974 v2pp.resize(100);
975 v3pp.resize(100);
976 v4pp.resize(100);
977
978 for (size_t i = 0 ; i < v1ps.size(); i++)
979 {
980 v1ps.template get<0>(i)[0] = rng.GetUniform();
981 v1ps.template get<0>(i)[1] = rng.GetUniform();
982 v1ps.template get<0>(i)[2] = rng.GetUniform();
983
984 v2ps.template get<0>(i)[0] = rng.GetUniform()*0.5;
985 v2ps.template get<0>(i)[1] = rng.GetUniform()*0.5;
986 v2ps.template get<0>(i)[2] = rng.GetUniform()*0.5;
987
988 v3ps.template get<0>(i)[0] = rng.GetUniform()*0.3;
989 v3ps.template get<0>(i)[1] = rng.GetUniform()*0.3;
990 v3ps.template get<0>(i)[2] = rng.GetUniform()*0.3;
991
992 v1pp.template get<0>(i) = rng.GetUniform();
993 v1pp.template get<1>(i)[0] = rng.GetUniform();
994 v1pp.template get<1>(i)[1] = rng.GetUniform();
995 v1pp.template get<1>(i)[2] = rng.GetUniform();
996
997 v2pp.template get<0>(i) = rng.GetUniform();
998 v2pp.template get<1>(i)[0] = rng.GetUniform();
999 v2pp.template get<1>(i)[1] = rng.GetUniform();
1000 v2pp.template get<1>(i)[2] = rng.GetUniform();
1001
1002 v3pp.template get<0>(i) = rng.GetUniform();
1003 v3pp.template get<1>(i)[0] = rng.GetUniform();
1004 v3pp.template get<1>(i)[1] = rng.GetUniform();
1005 v3pp.template get<1>(i)[2] = rng.GetUniform();
1006
1007 v4pp.template get<0>(i) = rng.GetUniform();
1008 v4pp.template get<1>(i).get(0) = rng.GetUniform();
1009 v4pp.template get<1>(i).get(1) = rng.GetUniform();
1010 v4pp.template get<1>(i).get(2) = rng.GetUniform();
1011 }
1012
1013 // Create a writer and write
1014 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,float[3]>>>,VECTOR_POINTS> vtk_v;
1015 vtk_v.add(v1ps,v1pp,75);
1016 vtk_v.add(v2ps,v2pp,88);
1017 vtk_v.add(v3ps,v3pp,90);
1018
1019 openfpm::vector<std::string> prp_names;
1020 vtk_v.write("vtk_points.vtk",prp_names);
1021
1022#ifndef SE_CLASS3
1023
1024 bool test = true;
1025
1026 // Check that match
1027 test = compare("vtk_points.vtk","test_data/vtk_points_test.vtk");
1028 BOOST_REQUIRE_EQUAL(test,true);
1029
1030#endif
1031
1032 // Create a writer and write
1033 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,Point<3,float>>>>,VECTOR_POINTS> vtk_v2;
1034 vtk_v2.add(v1ps,v4pp,75);
1035
1036 vtk_v2.write("vtk_points_pp.vtk",prp_names);
1037
1038#ifndef SE_CLASS3
1039
1040 // Check that match
1041 test = compare("vtk_points_pp.vtk","test_data/vtk_points_pp_test.vtk");
1042 BOOST_REQUIRE_EQUAL(test,true);
1043
1044#endif
1045
1046 // Create a writer and write
1047 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,Point<3,float>>>>,VECTOR_POINTS> vtk_v3;
1048 vtk_v3.add(v1ps,v4pp,75);
1049
1050 vtk_v3.write("vtk_points_pp_header.vtk",prp_names,"points","time=5.123");
1051
1052 // We try binary
1053 vtk_v3.write("vtk_points_pp_header_bin.vtk",prp_names,"points","time=5.123",file_type::BINARY);
1054
1055#ifndef SE_CLASS3
1056
1057 // Check that match
1058 test = compare("vtk_points_pp_header.vtk","test_data/vtk_points_pp_header_test.vtk");
1059 BOOST_REQUIRE_EQUAL(test,true);
1060
1061#endif
1062
1063 }
1064}
1065
1066BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_properties )
1067{
1068 Vcluster<> & v_cl = create_vcluster();
1069
1070 if (v_cl.getProcessUnitID() != 0)
1071 return;
1072
1073 {
1074 // Create 3 vectors with random particles
1075 openfpm::vector<Point<3,double>> v1ps;
1076 openfpm::vector<aggregate<float,float[3]>> v1pp;
1077
1078 // set the seed
1079 // create the random generator engine
1080 SimpleRNG rng;
1081
1082 // fill the vector with random data
1083 v1ps.resize(100);
1084 v1pp.resize(100);
1085
1086 for (size_t i = 0 ; i < v1ps.size(); i++)
1087 {
1088 v1ps.template get<0>(i)[0] = rng.GetUniform();
1089 v1ps.template get<0>(i)[1] = rng.GetUniform();
1090 v1ps.template get<0>(i)[2] = rng.GetUniform();
1091
1092
1093 v1pp.template get<0>(i) = rng.GetUniform();
1094 v1pp.template get<1>(i)[0] = rng.GetUniform();
1095 v1pp.template get<1>(i)[1] = rng.GetUniform();
1096 v1pp.template get<1>(i)[2] = rng.GetUniform();
1097 }
1098
1099 openfpm::vector<std::string> prop_names;
1100
1101 // Create a writer and write adding names to the properties
1102 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,float[3]>>>,VECTOR_POINTS> vtk_v;
1103 vtk_v.add(v1ps,v1pp,75);
1104 openfpm::vector<std::string> prp_names({"scalar","vector"});
1105 vtk_v.write("vtk_points_with_prp_names.vtk",prp_names);
1106
1107#ifndef SE_CLASS3
1108
1109 // Check that match
1110 bool test = compare("vtk_points_with_prp_names.vtk","test_data/vtk_points_with_prp_names_test.vtk");
1111 BOOST_REQUIRE_EQUAL(test,true);
1112
1113#endif
1114
1115 }
1116}
1117
1118BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_check_out_precision )
1119{
1120 Vcluster<> & v_cl = create_vcluster();
1121
1122 if (v_cl.getProcessUnitID() != 0)
1123 return;
1124
1125 {
1126 // Create 3 vectors with random particles
1127 openfpm::vector<Point<3,double>> v1ps;
1128 openfpm::vector<aggregate<float,double[3]>> v1pp;
1129
1130 // fill the vector with random data
1131 v1ps.resize(100);
1132 v1pp.resize(100);
1133
1134 for (size_t i = 0 ; i < v1ps.size(); i++)
1135 {
1136 v1ps.template get<0>(i)[0] = std::numeric_limits<double>::max();
1137 v1ps.template get<0>(i)[1] = std::numeric_limits<double>::max();
1138 v1ps.template get<0>(i)[2] = std::numeric_limits<double>::max();
1139
1140
1141 v1pp.template get<0>(i) = std::numeric_limits<float>::max();
1142 v1pp.template get<1>(i)[0] = std::numeric_limits<double>::max();
1143 v1pp.template get<1>(i)[1] = std::numeric_limits<double>::max();
1144 v1pp.template get<1>(i)[2] = std::numeric_limits<double>::max();
1145 }
1146
1147 openfpm::vector<std::string> prop_names;
1148
1149 // Create a writer and write adding names to the properties
1150 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,double[3]>>>,VECTOR_POINTS> vtk_v;
1151 vtk_v.add(v1ps,v1pp,75);
1152 openfpm::vector<std::string> prp_names({"scalar","vector"});
1153 vtk_v.write("vtk_points_with_prp_names_prec_check.vtk",prp_names);
1154
1155#ifndef SE_CLASS3
1156
1157 // Check that match
1158 bool test = compare("vtk_points_with_prp_names_prec_check.vtk","test_data/vtk_points_with_prp_names_prec_check_test.vtk");
1159 BOOST_REQUIRE_EQUAL(test,true);
1160
1161#endif
1162
1163 }
1164}
1165
1166BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_binary )
1167{
1168 Vcluster<> & v_cl = create_vcluster();
1169
1170 if (v_cl.getProcessUnitID() != 0)
1171 return;
1172
1173 {
1174 // Create 3 vectors with random particles
1175 openfpm::vector<Point<3,double>> v1ps;
1176 openfpm::vector<Point<3,double>> v2ps;
1177 openfpm::vector<Point<3,double>> v3ps;
1178 openfpm::vector<aggregate<float,float[3]>> v1pp;
1179 openfpm::vector<aggregate<float,float[3]>> v2pp;
1180 openfpm::vector<aggregate<float,float[3]>> v3pp;
1181 openfpm::vector<aggregate<float,Point<3,float>>> v4pp;
1182
1183 // set the seed
1184 // create the random generator engine
1185 SimpleRNG rng;
1186
1187 // fill the vector with random data
1188 v1ps.resize(100);
1189 v2ps.resize(100);
1190 v3ps.resize(100);
1191
1192 v1pp.resize(100);
1193 v2pp.resize(100);
1194 v3pp.resize(100);
1195 v4pp.resize(100);
1196
1197 for (size_t i = 0 ; i < v1ps.size(); i++)
1198 {
1199 v1ps.template get<0>(i)[0] = rng.GetUniform();
1200 v1ps.template get<0>(i)[1] = rng.GetUniform();
1201 v1ps.template get<0>(i)[2] = rng.GetUniform();
1202
1203 v2ps.template get<0>(i)[0] = rng.GetUniform()*0.5;
1204 v2ps.template get<0>(i)[1] = rng.GetUniform()*0.5;
1205 v2ps.template get<0>(i)[2] = rng.GetUniform()*0.5;
1206
1207 v3ps.template get<0>(i)[0] = rng.GetUniform()*0.3;
1208 v3ps.template get<0>(i)[1] = rng.GetUniform()*0.3;
1209 v3ps.template get<0>(i)[2] = rng.GetUniform()*0.3;
1210
1211 v1pp.template get<0>(i) = rng.GetUniform();
1212 v1pp.template get<1>(i)[0] = rng.GetUniform();
1213 v1pp.template get<1>(i)[1] = rng.GetUniform();
1214 v1pp.template get<1>(i)[2] = rng.GetUniform();
1215
1216 v2pp.template get<0>(i) = rng.GetUniform();
1217 v2pp.template get<1>(i)[0] = rng.GetUniform();
1218 v2pp.template get<1>(i)[1] = rng.GetUniform();
1219 v2pp.template get<1>(i)[2] = rng.GetUniform();
1220
1221 v3pp.template get<0>(i) = rng.GetUniform();
1222 v3pp.template get<1>(i)[0] = rng.GetUniform();
1223 v3pp.template get<1>(i)[1] = rng.GetUniform();
1224 v3pp.template get<1>(i)[2] = rng.GetUniform();
1225
1226 v4pp.template get<0>(i) = rng.GetUniform();
1227 v4pp.template get<1>(i).get(0) = rng.GetUniform();
1228 v4pp.template get<1>(i).get(1) = rng.GetUniform();
1229 v4pp.template get<1>(i).get(2) = rng.GetUniform();
1230 }
1231
1232 // Create a writer and write
1233 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,float[3]>>>,VECTOR_POINTS> vtk_v;
1234 vtk_v.add(v1ps,v1pp,75);
1235 vtk_v.add(v2ps,v2pp,88);
1236 vtk_v.add(v3ps,v3pp,90);
1237
1238 openfpm::vector<std::string> prp_names;
1239 vtk_v.write("vtk_points_bin.vtk",prp_names,"vtk output","",file_type::BINARY);
1240 vtk_v.write("vtk_points_bin2.vtk",prp_names,"vtk output","",file_type::BINARY);
1241
1242#ifndef SE_CLASS3
1243
1244 bool test = true;
1245
1246 // Check that match
1247 test = compare("vtk_points_bin.vtk","test_data/vtk_points_bin_test.vtk");
1248 BOOST_REQUIRE_EQUAL(test,true);
1249 test = compare("vtk_points_bin2.vtk","test_data/vtk_points_bin_test.vtk");
1250 BOOST_REQUIRE_EQUAL(test,true);
1251
1252#endif
1253
1254 // Create a writer and write
1255 VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,Point<3,float>>>>,VECTOR_POINTS> vtk_v2;
1256 vtk_v2.add(v1ps,v4pp,75);
1257
1258 vtk_v2.write("vtk_points_pp_bin.vtk",prp_names,"vtk output","",file_type::BINARY);
1259
1260#ifndef SE_CLASS3
1261
1262 // Check that match
1263 test = compare("vtk_points_pp_bin.vtk","test_data/vtk_points_pp_bin_test.vtk");
1264 BOOST_REQUIRE_EQUAL(test,true);
1265
1266#endif
1267
1268 }
1269
1270
1271 {
1272 // Create 3 vectors with random particles
1273 openfpm::vector<Point<2,double>> v1ps;
1274 openfpm::vector<Point<2,double>> v2ps;
1275 openfpm::vector<Point<2,double>> v3ps;
1276 openfpm::vector<aggregate<float,float[3][3]>> v1pp;
1277 openfpm::vector<aggregate<float,float[3][3]>> v2pp;
1278 openfpm::vector<aggregate<float,float[3][3]>> v3pp;
1279 openfpm::vector<aggregate<float[3],double[2]>> v4pp;
1280
1281 // set the seed
1282 // create the random generator engine
1283 SimpleRNG rng;
1284
1285 // fill the vector with random data
1286 v1ps.resize(100);
1287 v2ps.resize(100);
1288 v3ps.resize(100);
1289
1290 v1pp.resize(100);
1291 v2pp.resize(100);
1292 v3pp.resize(100);
1293 v4pp.resize(100);
1294
1295 for (size_t i = 0 ; i < v1ps.size(); i++)
1296 {
1297 v1ps.template get<0>(i)[0] = rng.GetUniform();
1298 v1ps.template get<0>(i)[1] = rng.GetUniform();
1299
1300 v2ps.template get<0>(i)[0] = rng.GetUniform()*0.5;
1301 v2ps.template get<0>(i)[1] = rng.GetUniform()*0.5;
1302
1303 v3ps.template get<0>(i)[0] = rng.GetUniform()*0.3;
1304 v3ps.template get<0>(i)[1] = rng.GetUniform()*0.3;
1305
1306 v1pp.template get<0>(i) = rng.GetUniform();
1307 v1pp.template get<1>(i)[0][0] = rng.GetUniform();
1308 v1pp.template get<1>(i)[0][1] = rng.GetUniform();
1309 v1pp.template get<1>(i)[0][2] = rng.GetUniform();
1310 v1pp.template get<1>(i)[1][0] = rng.GetUniform();
1311 v1pp.template get<1>(i)[1][1] = rng.GetUniform();
1312 v1pp.template get<1>(i)[1][2] = rng.GetUniform();
1313 v1pp.template get<1>(i)[2][0] = rng.GetUniform();
1314 v1pp.template get<1>(i)[2][1] = rng.GetUniform();
1315 v1pp.template get<1>(i)[2][2] = rng.GetUniform();
1316
1317 v2pp.template get<0>(i) = rng.GetUniform();
1318 v2pp.template get<1>(i)[0][0] = rng.GetUniform();
1319 v2pp.template get<1>(i)[0][1] = rng.GetUniform();
1320 v2pp.template get<1>(i)[0][2] = rng.GetUniform();
1321 v2pp.template get<1>(i)[1][0] = rng.GetUniform();
1322 v2pp.template get<1>(i)[1][1] = rng.GetUniform();
1323 v2pp.template get<1>(i)[1][2] = rng.GetUniform();
1324 v2pp.template get<1>(i)[2][0] = rng.GetUniform();
1325 v2pp.template get<1>(i)[2][1] = rng.GetUniform();
1326 v2pp.template get<1>(i)[2][2] = rng.GetUniform();
1327
1328 v3pp.template get<0>(i) = rng.GetUniform();
1329 v3pp.template get<1>(i)[0][0] = rng.GetUniform();
1330 v3pp.template get<1>(i)[0][1] = rng.GetUniform();
1331 v3pp.template get<1>(i)[0][2] = rng.GetUniform();
1332 v3pp.template get<1>(i)[1][0] = rng.GetUniform();
1333 v3pp.template get<1>(i)[1][1] = rng.GetUniform();
1334 v3pp.template get<1>(i)[1][2] = rng.GetUniform();
1335 v3pp.template get<1>(i)[2][0] = rng.GetUniform();
1336 v3pp.template get<1>(i)[2][1] = rng.GetUniform();
1337 v3pp.template get<1>(i)[2][2] = rng.GetUniform();
1338
1339 v4pp.template get<0>(i)[0] = rng.GetUniform();
1340 v4pp.template get<0>(i)[1] = rng.GetUniform();
1341 v4pp.template get<0>(i)[2] = rng.GetUniform();
1342 v4pp.template get<1>(i)[0] = rng.GetUniform();
1343 v4pp.template get<1>(i)[1] = rng.GetUniform();
1344 }
1345
1346 // Create a writer and write
1347 VTKWriter<boost::mpl::pair<openfpm::vector<Point<2,double>>,openfpm::vector<aggregate<float,float[3][3]>>>,VECTOR_POINTS> vtk_v;
1348 vtk_v.add(v1ps,v1pp,75);
1349 vtk_v.add(v2ps,v2pp,88);
1350 vtk_v.add(v3ps,v3pp,90);
1351
1352 openfpm::vector<std::string> stub;
1353
1354 vtk_v.write("vtk_points_2d_bin.vtk",stub,"vtk output","",file_type::BINARY);
1355
1356#ifndef SE_CLASS3
1357
1358 bool test = true;
1359
1360 // Check that match
1361 test = compare("vtk_points_2d_bin.vtk","test_data/vtk_points_2d_bin_test.vtk");
1362 BOOST_REQUIRE_EQUAL(test,true);
1363
1364#endif
1365
1366 // Create a writer and write
1367 VTKWriter<boost::mpl::pair<openfpm::vector<Point<2,double>>,openfpm::vector<aggregate<float[3],double[2]>>>,VECTOR_POINTS> vtk_v2;
1368 vtk_v2.add(v1ps,v4pp,75);
1369
1370 vtk_v2.write("vtk_points_2d_pp_bin.vtk",stub,"vtk output","",file_type::BINARY);
1371
1372#ifndef SE_CLASS3
1373
1374 // Check that match
1375 test = compare("vtk_points_2d_pp_bin.vtk","test_data/vtk_points_2d_pp_bin_test.vtk");
1376 BOOST_REQUIRE_EQUAL(test,true);
1377
1378#endif
1379 }
1380}
1381
1382BOOST_AUTO_TEST_SUITE_END()
1383
1384#endif /* VTKWRITER_UNIT_TESTS_HPP_ */
1385