OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
12BOOST_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
57 typedef vector_dist<2, double, aggregate<double>> vector_dist_type;
58
59 SupportBuilder<vector_dist_type,vector_dist_type> supportBuilder(domain, domain, {1,0}, 2*spacing[0],false);
60 auto support = supportBuilder.getSupport(itPoint, 6, support_options::N_PARTICLES);
61
62 BOOST_REQUIRE_GE(support.size(), 6);
63 }
64
65 BOOST_AUTO_TEST_CASE(SupportBuilder_2D_2_2_2spacing_test)
66 {
67 // Here build some easy domain and get some points around a given one
68 size_t edgeSemiSize = 25;
69 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
70 Box<2, double> box({-1.2, -1.2}, {1.2, 1.2});
71// Box<2, double> innerDomain({-1.0, -1.0}, {1.0, 1.0});
72 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
73 double spacing[2];
74 spacing[0] = 1.0 / (sz[0] - 1);
75 spacing[1] = 1.0 / (sz[1] - 1);
76 Ghost<2, double> ghost(3.0 * spacing[0]);
77
78 vector_dist<2, double, aggregate<double>> domain(0, box, bc, ghost);
79 auto it = domain.getGridIterator(sz);
80 size_t pointId = 0;
81 size_t counter = 0;
82 while (it.isNext())
83 {
84 domain.add();
85 auto key = it.get();
86 mem_id k0 = key.get(0) - edgeSemiSize;
87 double x = k0 * spacing[0];
88 domain.getLastPos()[0] = x;
89 mem_id k1 = key.get(1) - edgeSemiSize;
90 double y = k1 * spacing[1];
91 domain.getLastPos()[1] = y;
92 domain.template getLastProp<0>() = 0.0;
93 if (abs(domain.getLastPos()[0]) + abs(domain.getLastPos()[1]) < 1e-16) // i.e. if we are at (0,0)
94 {
95 pointId = counter;
96 }
97 ++counter;
98 ++it;
99 }
100 // Now get iterator to point of interest
101 auto itPoint = domain.getDomainIterator();
102 size_t foo = (sqrt(counter) + counter) / 2;
103 for (int i = 0; i < foo; ++i)
104 {
105 ++itPoint;
106 }
107 // Get spatial position from point iterator
108 vect_dist_key_dx p = itPoint.get();
109 const auto pos = domain.getPos(p.getKey());
110
111 typedef vector_dist<2, double, aggregate<double>> vector_dist_type;
112
113 SupportBuilder<vector_dist_type,vector_dist_type> supportBuilder(domain, domain, {2,2}, 2*spacing[0],false);
114 auto supportPoints = supportBuilder.getSupport(itPoint, 20, support_options::N_PARTICLES);
115
116 BOOST_REQUIRE_GE(supportPoints.size(), 20);
117 }
118
119
120
121BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Definition Box.hpp:61
Grid key for a distributed grid.
__device__ __host__ size_t getKey() const
Get the key.
Distributed vector.