OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
Support_unit_tests.cpp
1 //
2 // Created by tommaso on 26/03/19.
3 //
4 
5 #define BOOST_TEST_DYN_LINK
6 
7 #include <boost/test/unit_test.hpp>
8 #include "Vector/vector_dist.hpp"
9 #include <Space/Shape/Point.hpp>
10 #include "DCPSE/SupportBuilder.hpp"
11 
12 BOOST_AUTO_TEST_SUITE(Support_tests)
13 
14  BOOST_AUTO_TEST_CASE(SupportBuilder_2D_1_0_2spacing_test)
15  {
16  // Here build some easy domain and get some points around a given one
17  size_t edgeSemiSize = 100;
18  const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
19  Box<2, double> box({-1.1, -1.1}, {1.1, 1.1});
20  size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
21  double spacing[2];
22  spacing[0] = 1.0 / (sz[0] - 1);
23  spacing[1] = 1.0 / (sz[1] - 1);
24  Ghost<2, double> ghost(0.1);
25 
26  vector_dist<2, double, aggregate<double>> domain(0, box, bc, ghost);
27  auto it = domain.getGridIterator(sz);
28  size_t pointId = 0;
29  size_t counter = 0;
30  double minNormOne = 999;
31  while (it.isNext())
32  {
33  domain.add();
34  auto key = it.get();
35  mem_id k0 = key.get(0) - edgeSemiSize;
36  double x = k0 * spacing[0];
37  domain.getLastPos()[0] = x;
38  mem_id k1 = key.get(1) - edgeSemiSize;
39  double y = k1 * spacing[1];
40  domain.getLastPos()[1] = y;
41  domain.template getLastProp<0>() = 0.0;
42 
43  ++counter;
44  ++it;
45  }
46  // Now get iterator to point of interest
47  auto itPoint = domain.getIterator();
48  size_t foo = (sqrt(counter) + counter) / 2;
49  for (int i = 0; i < foo; ++i)
50  {
51  ++itPoint;
52  }
53  // Get spatial position from point iterator
54  vect_dist_key_dx p = itPoint.get();
55  const auto pos = domain.getPos(p.getKey());
56  //std::cout << "p=(" << pos[0] << "," << pos[1] << ")" << std::endl;
57 // BOOST_REQUIRE_CLOSE(pos[0], 0, 1e-16);
58 // BOOST_REQUIRE_CLOSE(pos[1], 0, 1e-16);
59 
60  // Now that domain is built and populated, let's test SupportBuilder
61  // We use (0,0) as initial point
62  SupportBuilder<vector_dist<2, double, aggregate<double>>> supportBuilder(domain, {1,0}, 2*spacing[0]);
63  auto support = supportBuilder.getSupport(itPoint, 6, support_options::N_PARTICLES);
64 // for (const auto &off : support.getOffsets())
65 // {
66 // std::cout << off.toString() << std::endl;
67 // }
68  BOOST_REQUIRE_GE(support.size(), 6);
69  }
70 
71  BOOST_AUTO_TEST_CASE(SupportBuilder_2D_2_2_2spacing_test)
72  {
73  // Here build some easy domain and get some points around a given one
74  size_t edgeSemiSize = 25;
75  const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
76  Box<2, double> box({-1.2, -1.2}, {1.2, 1.2});
77 // Box<2, double> innerDomain({-1.0, -1.0}, {1.0, 1.0});
78  size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
79  double spacing[2];
80  spacing[0] = 1.0 / (sz[0] - 1);
81  spacing[1] = 1.0 / (sz[1] - 1);
82  Ghost<2, double> ghost(3.0 * spacing[0]);
83 
84  vector_dist<2, double, aggregate<double>> domain(0, box, bc, ghost);
85  auto it = domain.getGridIterator(sz);
86  size_t pointId = 0;
87  size_t counter = 0;
88  while (it.isNext())
89  {
90  domain.add();
91  auto key = it.get();
92  mem_id k0 = key.get(0) - edgeSemiSize;
93  double x = k0 * spacing[0];
94  domain.getLastPos()[0] = x;
95  mem_id k1 = key.get(1) - edgeSemiSize;
96  double y = k1 * spacing[1];
97  domain.getLastPos()[1] = y;
98  domain.template getLastProp<0>() = 0.0;
99  if (abs(domain.getLastPos()[0]) + abs(domain.getLastPos()[1]) < 1e-16) // i.e. if we are at (0,0)
100  {
101  pointId = counter;
102  }
103  ++counter;
104  ++it;
105  }
106  // Now get iterator to point of interest
107  auto itPoint = domain.getDomainIterator();
108  size_t foo = (sqrt(counter) + counter) / 2;
109  for (int i = 0; i < foo; ++i)
110  {
111  ++itPoint;
112  }
113  // Get spatial position from point iterator
114  vect_dist_key_dx p = itPoint.get();
115  const auto pos = domain.getPos(p.getKey());
116  //std::cout << "p=(" << pos[0] << "," << pos[1] << ")" << std::endl;
117 // BOOST_REQUIRE_CLOSE(pos[0], 0, 1e-16);
118 // BOOST_REQUIRE_CLOSE(pos[1], 0, 1e-16);
119 
120  // Now that domain is built and populated, let's test SupportBuilder
121  // We use (0,0) as initial point
122  SupportBuilder<vector_dist<2, double, aggregate<double>>> supportBuilder(domain, {2,2}, 2*spacing[0]);
123  auto supportPoints = supportBuilder.getSupport(itPoint, 20, support_options::N_PARTICLES);
124 // for (const auto &k : supportPoints)
125 // {
126 // Point<2, double> pt = domain.getPos(k);
127 // std::cout << pt.toString() << std::endl;
128 // }
129  BOOST_REQUIRE_GE(supportPoints.size(), 20);
130  }
131 
132 // BOOST_AUTO_TEST_CASE(Support_CopyConstructor_test)
133 // {
134 //
135 // }
136 
137 BOOST_AUTO_TEST_SUITE_END()
Grid key for a distributed grid.
Definition: Ghost.hpp:39
This class represent an N-dimensional box.
Definition: Box.hpp:60
__device__ __host__ size_t getKey() const
Get the key.
Distributed vector.