1 | /* |
2 | * DrawParticles_unit_tests.hpp |
3 | * |
4 | * Created on: Jan 3, 2017 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_UNIT_TESTS_HPP_ |
9 | #define OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_UNIT_TESTS_HPP_ |
10 | |
11 | #include "PointIterator.hpp" |
12 | #include "PointIteratorSkin.hpp" |
13 | #include "DrawParticles.hpp" |
14 | |
15 | BOOST_AUTO_TEST_SUITE( draw_particles ) |
16 | |
17 | BOOST_AUTO_TEST_CASE(point_iterator) |
18 | { |
19 | //! [DrawBox_example] |
20 | |
21 | size_t sz[] = {23,27,20}; |
22 | |
23 | Box<3,double> domain({-1.2,0.5,-0.6},{1.0,3.1,1.3}); |
24 | Box<3,double> sub_domain({-0.15,0.75,0.15},{1.05,1.15,1.05}); |
25 | Box<3,double> sub_real({-0.1,0.80,0.2},{1.0,1.1,1.0}); |
26 | |
27 | size_t sz_sub[] = {12,4,9}; |
28 | |
29 | // Boundary conditions |
30 | size_t bc[3]={NON_PERIODIC,NON_PERIODIC,NON_PERIODIC}; |
31 | |
32 | // ghost, big enough to contain the interaction radius |
33 | Ghost<3,float> ghost(0.01); |
34 | |
35 | vector_dist<3,double,aggregate<double>> vd(0,domain,bc,ghost); |
36 | |
37 | auto p = DrawParticles::DrawBox(vd,sz,domain,sub_domain); |
38 | |
39 | size_t cnt = 0; |
40 | |
41 | bool good = true; |
42 | while (p.isNext()) |
43 | { |
44 | vd.add(); |
45 | |
46 | vd.getLastPos()[0] = p.get().get(0); |
47 | vd.getLastPos()[1] = p.get().get(1); |
48 | vd.getLastPos()[2] = p.get().get(2); |
49 | |
50 | good &= sub_domain.isInside(p.get()); |
51 | |
52 | cnt++; |
53 | |
54 | ++p; |
55 | } |
56 | |
57 | //! [DrawBox_example] |
58 | |
59 | Vcluster<> & v_cl = create_vcluster(); |
60 | |
61 | v_cl.sum(cnt); |
62 | v_cl.execute(); |
63 | |
64 | BOOST_REQUIRE_EQUAL(cnt,sz_sub[0]*sz_sub[1]*sz_sub[2]); |
65 | BOOST_REQUIRE_EQUAL(good,true); |
66 | |
67 | Box<3,double> marg = p.getBoxMargins(); |
68 | |
69 | BOOST_REQUIRE_CLOSE(marg.getLow(0), sub_real.getLow(0) ,0.0001); |
70 | BOOST_REQUIRE_CLOSE(marg.getLow(1), sub_real.getLow(1) ,0.0001); |
71 | BOOST_REQUIRE_CLOSE(marg.getLow(2), sub_real.getLow(2) ,0.0001); |
72 | |
73 | BOOST_REQUIRE_CLOSE(marg.getHigh(0), sub_real.getHigh(0) ,0.0001); |
74 | BOOST_REQUIRE_CLOSE(marg.getHigh(1), sub_real.getHigh(1) ,0.0001); |
75 | BOOST_REQUIRE_CLOSE(marg.getHigh(2), sub_real.getHigh(2) ,0.0001); |
76 | } |
77 | |
78 | BOOST_AUTO_TEST_CASE(point_iterator_skin) |
79 | { |
80 | size_t sz[] = {23,27,20}; |
81 | |
82 | Box<3,double> domain({-1.2,0.5,-0.6},{1.0,3.1,1.3}); |
83 | Box<3,double> sub_domainA({-0.15,0.75,0.15},{1.05,1.15,1.05}); |
84 | Box<3,double> sub_domainB({-0.25,0.65,0.05},{0.95,1.05,1.05}); |
85 | |
86 | // Boundary conditions |
87 | size_t bc[3]={NON_PERIODIC,NON_PERIODIC,NON_PERIODIC}; |
88 | |
89 | // ghost, big enough to contain the interaction radius |
90 | Ghost<3,float> ghost(0.01); |
91 | |
92 | vector_dist<3,double,aggregate<double>> vd(0,domain,bc,ghost); |
93 | |
94 | auto p = DrawParticles::DrawSkin(vd,sz,domain,sub_domainA, sub_domainB); |
95 | |
96 | size_t cnt = 0; |
97 | |
98 | bool good = true; |
99 | while (p.isNext()) |
100 | { |
101 | vd.add(); |
102 | |
103 | vd.getLastPos()[0] = p.get().get(0); |
104 | vd.getLastPos()[1] = p.get().get(1); |
105 | vd.getLastPos()[2] = p.get().get(2); |
106 | |
107 | if (!((p.get().get(0) > -0.21 && p.get().get(0) < -0.19) || (p.get().get(1) > 0.69 && p.get().get(1) < 0.71) || (p.get().get(2) > 0.09 && p.get().get(2) < 0.11)) ) |
108 | good &= false; |
109 | |
110 | if (sub_domainA.isInside(p.get())) |
111 | good &= false; |
112 | |
113 | cnt++; |
114 | |
115 | ++p; |
116 | } |
117 | |
118 | Vcluster<> & v_cl = create_vcluster(); |
119 | |
120 | v_cl.sum(cnt); |
121 | v_cl.execute(); |
122 | |
123 | BOOST_REQUIRE_EQUAL(good,true); |
124 | } |
125 | |
126 | BOOST_AUTO_TEST_SUITE_END() |
127 | |
128 | #endif /* OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_UNIT_TESTS_HPP_ */ |
129 | |