5 #define BOOST_TEST_DYN_LINK
7 #include <boost/test/unit_test.hpp>
8 #include <boost/test/tools/floating_point_comparison.hpp>
9 #include <Vector/vector_dist.hpp>
10 #include <DCPSE/Dcpse.hpp>
13 void check_small_or_close(T value, T expected, T tolerance)
15 if (fabs(expected) < tolerance)
17 BOOST_CHECK_SMALL(value, tolerance);
20 BOOST_CHECK_CLOSE(value, expected, tolerance);
25 void check_small_or_close_abs(T value, T expected, T absTolerance)
27 BOOST_CHECK_SMALL(value - expected, absTolerance);
31 BOOST_AUTO_TEST_SUITE(Dcpse_tests)
36 BOOST_AUTO_TEST_CASE(Dcpse_2D_test)
39 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
41 BOOST_TEST_MESSAGE(
"Init vars...");
44 size_t edgeSemiSize = 20;
45 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
47 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
49 spacing[0] = 1.0 / (sz[0] - 1);
50 spacing[1] = 1.0 / (sz[1] - 1);
53 double rCut = 3.1 * spacing[0];
55 BOOST_TEST_MESSAGE(
"Init vector_dist...");
60 BOOST_TEST_MESSAGE(
"Init domain...");
61 auto it = domain.getGridIterator(sz);
64 double minNormOne = 999;
69 mem_id k0 = key.get(0);
70 double x = k0 * spacing[0];
71 domain.getLastPos()[0] = x;
72 mem_id k1 = key.get(1);
73 double y = k1 * spacing[1];
74 domain.getLastPos()[1] = y;
76 domain.template getLastProp<0>() = sin(x);
80 domain.template getLastProp<2>() = cos(x);
87 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
91 BOOST_TEST_MESSAGE(
"Getting ghost...");
96 BOOST_TEST_MESSAGE(
"DCPSE init & compute coefficients...");
97 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
98 Dcpse<2, decltype(verletList),
vector_dist<2, double, aggregate<double, double, double>> > dcpse(domain, verletList,
Point<2, unsigned int>({1, 0}), 2, rCut, support_options::RADIUS);
99 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
100 dcpse.template computeDifferentialOperator<0, 1>(domain);
105 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
107 const double avgSpacing = spacing[0] + spacing[1];
108 const double TOL = 2 * avgSpacing * avgSpacing;
109 auto itVal = domain.getDomainIterator();
111 double computedValue;
112 double validationValue;
113 while (itVal.isNext())
115 auto key = itVal.get();
116 computedValue = domain.template getProp<1>(key);
117 validationValue = domain.template getProp<2>(key);
118 bool locCheck = (fabs(computedValue - validationValue) < TOL);
119 check = check && locCheck;
123 <<
", computedValue=" << computedValue
124 <<
", validationValue=" << validationValue
125 <<
", difference=" << fabs(computedValue - validationValue)
126 <<
", tolerance=" << TOL
132 BOOST_REQUIRE(check);
135 BOOST_AUTO_TEST_CASE(Dcpse_2D_perturbed_test)
138 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
140 BOOST_TEST_MESSAGE(
"Init vars...");
143 size_t edgeSemiSize = 20;
144 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
146 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
148 spacing[0] = 1.0 / (sz[0] - 1);
149 spacing[1] = 1.0 / (sz[1] - 1);
151 double sigma2 = spacing[0] * spacing[1] / (4);
156 double rCut = 2 * (spacing[0] + sqrt(sigma2));
160 BOOST_TEST_MESSAGE(
"Init vector_dist...");
165 BOOST_TEST_MESSAGE(
"Init domain...");
168 std::mt19937 rng{6666666};
170 std::normal_distribution<> gaussian{0, sigma2};
172 auto it = domain.getGridIterator(sz);
175 double minNormOne = 999;
180 mem_id k0 = key.get(0);
181 double x = k0 * spacing[0];
182 domain.getLastPos()[0] = x + gaussian(rng);
183 mem_id k1 = key.get(1);
184 double y = k1 * spacing[1];
185 domain.getLastPos()[1] = y + gaussian(rng);
187 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]);
191 domain.template getLastProp<2>() = cos(domain.getLastPos()[0]);
198 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
206 BOOST_TEST_MESSAGE(
"DCPSE init & compute coefficients...");
207 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
208 Dcpse<2, decltype(verletList),
vector_dist<2, double, aggregate<double, double, double>> > dcpse(domain, verletList,
Point<2, unsigned int>({1, 0}), 2, rCut, support_options::RADIUS);
209 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
210 dcpse.template computeDifferentialOperator<0, 1>(domain);
213 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
215 const double avgSpacing = spacing[0] + spacing[1] + 2 * sqrt(sigma2);
216 const double TOL = 2 * avgSpacing * avgSpacing;
217 auto itVal = domain.getDomainIterator();
219 double computedValue;
220 double validationValue;
221 while (itVal.isNext())
223 auto key = itVal.get();
224 computedValue = domain.template getProp<1>(key);
225 validationValue = domain.template getProp<2>(key);
226 bool locCheck = (fabs(computedValue - validationValue) < TOL);
227 check = check && locCheck;
231 <<
", computedValue=" << computedValue
232 <<
", validationValue=" << validationValue
233 <<
", difference=" << fabs(computedValue - validationValue)
234 <<
", tolerance=" << TOL
240 BOOST_REQUIRE(check);
243 BOOST_AUTO_TEST_CASE(Dcpse_3D_test)
246 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
248 BOOST_TEST_MESSAGE(
"Init vars...");
251 size_t edgeSemiSize = 20;
252 const unsigned int DIM = 3;
253 const size_t sz[DIM] = {2 * edgeSemiSize, 2 * edgeSemiSize, 2 * edgeSemiSize};
255 size_t bc[DIM] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
257 spacing[0] = 1.0 / (sz[0] - 1);
258 spacing[1] = 1.0 / (sz[1] - 1);
259 spacing[2] = 1.0 / (sz[2] - 1);
262 double rCut = 3.1 * spacing[0];
264 BOOST_TEST_MESSAGE(
"Init vector_dist...");
269 BOOST_TEST_MESSAGE(
"Init domain...");
270 auto it = domain.getGridIterator(sz);
273 double minNormOne = 999;
278 mem_id k0 = key.get(0);
279 double x = k0 * spacing[0];
280 domain.getLastPos()[0] = x;
281 mem_id k1 = key.get(1);
282 double y = k1 * spacing[1];
283 domain.getLastPos()[1] = y;
284 mem_id k2 = key.get(2);
285 double z = k2 * spacing[2];
286 domain.getLastPos()[2] = z;
288 domain.template getLastProp<0>() = sin(z);
292 domain.template getLastProp<2>() = cos(z);
299 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
304 BOOST_TEST_MESSAGE(
"DCPSE init & compute coefficients...");
305 auto verletList = domain.template getVerlet<VL_NON_SYMMETRIC|VL_SKIP_REF_PART>(rCut);
306 Dcpse<DIM, decltype(verletList),
vector_dist<DIM, double, aggregate<double, double, double>>> dcpse(domain, verletList,
Point<DIM, unsigned int>({0, 0, 1}), 2, rCut, support_options::RADIUS);
307 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
308 dcpse.template computeDifferentialOperator<0, 1>(domain);
311 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
313 const double avgSpacing = spacing[0] + spacing[1] + spacing[2];
314 const double TOL = avgSpacing * avgSpacing;
315 auto itVal = domain.getDomainIterator();
317 double computedValue;
318 double validationValue;
319 while (itVal.isNext())
321 auto key = itVal.get();
322 computedValue = domain.template getProp<1>(key);
323 validationValue = domain.template getProp<2>(key);
324 check = check && (fabs(computedValue - validationValue) < TOL);
328 <<
", computedValue=" << computedValue
329 <<
", validationValue=" << validationValue
330 <<
", tolerance=" << TOL
336 BOOST_REQUIRE(check);
341 BOOST_AUTO_TEST_SUITE_END()