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>
13void 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);
25void check_small_or_close_abs(T value, T expected, T absTolerance)
27 BOOST_CHECK_SMALL(value - expected, absTolerance);
31BOOST_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 = 2 * 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 Dcpse<2, vector_dist<2, double, aggregate<double, double, double>> > dcpse(domain,
Point<2, unsigned int>({1, 0}), 2, rCut,2,support_options::N_PARTICLES);
98 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
99 dcpse.template computeDifferentialOperator<0, 1>(domain);
104 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
106 const double avgSpacing = spacing[0] + spacing[1];
107 const double TOL = 2 * avgSpacing * avgSpacing;
108 auto itVal = domain.getDomainIterator();
110 double computedValue;
111 double validationValue;
112 while (itVal.isNext())
114 auto key = itVal.get();
115 computedValue = domain.template getProp<1>(key);
116 validationValue = domain.template getProp<2>(key);
117 bool locCheck = (fabs(computedValue - validationValue) < TOL);
118 check = check && locCheck;
122 <<
", computedValue=" << computedValue
123 <<
", validationValue=" << validationValue
124 <<
", difference=" << fabs(computedValue - validationValue)
125 <<
", tolerance=" << TOL
131 BOOST_REQUIRE(check);
134 BOOST_AUTO_TEST_CASE(Dcpse_2D_perturbed_test)
137 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
139 BOOST_TEST_MESSAGE(
"Init vars...");
142 size_t edgeSemiSize = 20;
143 const size_t sz[2] = {2 * edgeSemiSize, 2 * edgeSemiSize};
145 size_t bc[2] = {NON_PERIODIC, NON_PERIODIC};
147 spacing[0] = 1.0 / (sz[0] - 1);
148 spacing[1] = 1.0 / (sz[1] - 1);
150 double sigma2 = spacing[0] * spacing[1] / (2 * 4);
155 double rCut = 2 * (spacing[0] + sqrt(sigma2));
159 BOOST_TEST_MESSAGE(
"Init vector_dist...");
164 BOOST_TEST_MESSAGE(
"Init domain...");
167 std::mt19937 rng{6666666};
169 std::normal_distribution<> gaussian{0, sigma2};
171 auto it = domain.getGridIterator(sz);
174 double minNormOne = 999;
179 mem_id k0 = key.get(0);
180 double x = k0 * spacing[0];
181 domain.getLastPos()[0] = x + gaussian(rng);
182 mem_id k1 = key.get(1);
183 double y = k1 * spacing[1];
184 domain.getLastPos()[1] = y + gaussian(rng);
186 domain.template getLastProp<0>() = sin(domain.getLastPos()[0]);
190 domain.template getLastProp<2>() = cos(domain.getLastPos()[0]);
197 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
204 BOOST_TEST_MESSAGE(
"DCPSE init & compute coefficients...");
205 Dcpse<2, vector_dist<2, double, aggregate<double, double, double>> > dcpse(domain,
Point<2, unsigned int>({1, 0}), 2, rCut, 2,support_options::N_PARTICLES);
206 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
207 dcpse.template computeDifferentialOperator<0, 1>(domain);
210 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
212 const double avgSpacing = spacing[0] + spacing[1] + 2 * sqrt(sigma2);
213 const double TOL = 2 * avgSpacing * avgSpacing;
214 auto itVal = domain.getDomainIterator();
216 double computedValue;
217 double validationValue;
218 while (itVal.isNext())
220 auto key = itVal.get();
221 computedValue = domain.template getProp<1>(key);
222 validationValue = domain.template getProp<2>(key);
223 bool locCheck = (fabs(computedValue - validationValue) < TOL);
224 check = check && locCheck;
228 <<
", computedValue=" << computedValue
229 <<
", validationValue=" << validationValue
230 <<
", difference=" << fabs(computedValue - validationValue)
231 <<
", tolerance=" << TOL
237 BOOST_REQUIRE(check);
240 BOOST_AUTO_TEST_CASE(Dcpse_3D_test)
243 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
245 BOOST_TEST_MESSAGE(
"Init vars...");
248 size_t edgeSemiSize = 20;
249 const unsigned int DIM = 3;
250 const size_t sz[DIM] = {2 * edgeSemiSize, 2 * edgeSemiSize, 2 * edgeSemiSize};
252 size_t bc[DIM] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
254 spacing[0] = 1.0 / (sz[0] - 1);
255 spacing[1] = 1.0 / (sz[1] - 1);
256 spacing[2] = 1.0 / (sz[2] - 1);
259 double rCut = 2 * spacing[0];
261 BOOST_TEST_MESSAGE(
"Init vector_dist...");
266 BOOST_TEST_MESSAGE(
"Init domain...");
267 auto it = domain.getGridIterator(sz);
270 double minNormOne = 999;
275 mem_id k0 = key.get(0);
276 double x = k0 * spacing[0];
277 domain.getLastPos()[0] = x;
278 mem_id k1 = key.get(1);
279 double y = k1 * spacing[1];
280 domain.getLastPos()[1] = y;
281 mem_id k2 = key.get(2);
282 double z = k2 * spacing[2];
283 domain.getLastPos()[2] = z;
285 domain.template getLastProp<0>() = sin(z);
289 domain.template getLastProp<2>() = cos(z);
296 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
301 BOOST_TEST_MESSAGE(
"DCPSE init & compute coefficients...");
302 Dcpse<DIM, vector_dist<DIM, double, aggregate<double, double, double>>> dcpse(domain,
Point<DIM, unsigned int>({0, 0, 1}), 2, rCut,2.5,support_options::N_PARTICLES);
303 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
304 dcpse.template computeDifferentialOperator<0, 1>(domain);
307 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
309 const double avgSpacing = spacing[0] + spacing[1] + spacing[2];
310 const double TOL = avgSpacing * avgSpacing;
311 auto itVal = domain.getDomainIterator();
313 double computedValue;
314 double validationValue;
315 while (itVal.isNext())
317 auto key = itVal.get();
318 computedValue = domain.template getProp<1>(key);
319 validationValue = domain.template getProp<2>(key);
320 check = check && (fabs(computedValue - validationValue) < TOL);
324 <<
", computedValue=" << computedValue
325 <<
", validationValue=" << validationValue
326 <<
", tolerance=" << TOL
332 BOOST_REQUIRE(check);
335 BOOST_AUTO_TEST_CASE(Dcpse_3D_2_test)
338 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
340 BOOST_TEST_MESSAGE(
"Init vars...");
343 size_t edgeSemiSize = 10;
344 const unsigned int DIM = 3;
345 const size_t sz[DIM] = {2 * edgeSemiSize, 2 * edgeSemiSize, 2 * edgeSemiSize};
347 size_t bc[DIM] = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};
349 spacing[0] = 1.0 / (sz[0] - 1);
350 spacing[1] = 1.0 / (sz[1] - 1);
351 spacing[2] = 1.0 / (sz[2] - 1);
353 double rCut = 2 * spacing[0];
357 BOOST_TEST_MESSAGE(
"Init vector_dist...");
362 BOOST_TEST_MESSAGE(
"Init domain...");
363 auto it = domain.getGridIterator(sz);
366 double minNormOne = 999;
371 mem_id k0 = key.get(0);
372 double x = k0 * spacing[0];
373 domain.getLastPos()[0] = x;
374 mem_id k1 = key.get(1);;
375 double y = k1 * spacing[1];
376 domain.getLastPos()[1] = y;
377 mem_id k2 = key.get(2);
378 double z = k2 * spacing[2];
379 domain.getLastPos()[2] = z;
381 domain.template getLastProp<0>() = x * x * sin(z);
383 domain.template getLastProp<2>() = -2*sin(z);
388 BOOST_TEST_MESSAGE(
"Sync domain across processors...");
394 BOOST_TEST_MESSAGE(
"DCPSE init & compute coefficients...");
395 Dcpse<DIM, vector_dist<DIM, double, aggregate<double, double, double>> > dcpse(domain,
Point<DIM, unsigned int>({2, 0, 2}), r, rCut,2.5,support_options::N_PARTICLES);
396 BOOST_TEST_MESSAGE(
"DCPSE compute diff operator...");
397 dcpse.template computeDifferentialOperator<0, 1>(domain);
400 BOOST_TEST_MESSAGE(
"Validating against ground truth...");
402 const double avgSpacing = spacing[0] + spacing[1] + spacing[2];
403 const double TOL = pow(avgSpacing, r);
404 auto itVal = domain.getDomainIterator();
406 double computedValue;
407 double validationValue;
408 while (itVal.isNext())
410 auto key = itVal.get();
411 computedValue = domain.template getProp<1>(key);
412 validationValue = domain.template getProp<2>(key);
413 check = check && (fabs(computedValue - validationValue) < TOL);
417 <<
", computedValue=" << computedValue
418 <<
", validationValue=" << validationValue
419 <<
", tolerance=" << TOL
425 BOOST_REQUIRE(check);
430BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
This class implement the point shape in an N-dimensional space.
std::string toString() const
Return the string with the point coordinate.