OpenFPM  5.2.0
Project that contain the implementation of distributed structures
Vandermonde_unit_tests.cpp
1 //
2 // Created by tommaso on 22/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 <DCPSE/MonomialBasis.hpp>
10 #include <DCPSE/VandermondeRowBuilder.hpp>
11 #include <DCPSE/Vandermonde.hpp>
12 #include "DMatrix/EMatrix.hpp"
13 
14 BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
15 
16 // If EIGEN is not present, EMatrix is not available and we don't need to build this test
17 #ifdef HAVE_EIGEN
18 
19  BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_AllOnes_test)
20  {
21  MonomialBasis<2> mb({1, 0}, 2);
22  EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
23  Point<2, double> x({2, 2});
24  double eps = 2;
26  vrb.buildRow(row, 0, x / eps);
27  // For the way the row has been constructed, it should be composed of only 1s
28  bool isRowAllOnes = true;
29  for (int i = 0; i < mb.size(); ++i)
30  {
31  isRowAllOnes = isRowAllOnes && (row(0, i) == 1);
32  }
33  BOOST_REQUIRE(isRowAllOnes);
34  }
35 
36  BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_OneZero_test)
37  {
38  MonomialBasis<2> mb({1, 0}, 2);
39  EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
40  Point<2, double> x({1, 0});
41  double eps = 1;
43  vrb.buildRow(row, 0, x / eps);
44  // For the way the row has been constructed, it should be composed of only 1s
45  bool areValuesOk = true;
46  for (int i = 0; i < mb.size(); ++i)
47  {
48  bool isThereY = mb.getElement(i).getExponent(1) > 0;
49  bool curCheck = (row(0, i) == !isThereY);
50  areValuesOk = areValuesOk && curCheck;
51  }
52  BOOST_REQUIRE(areValuesOk);
53  }
54 
55  BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_ZeroOne_test)
56  {
57  MonomialBasis<2> mb({1, 0}, 2);
58  EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
59  Point<2, double> x({0, 1});
60  double eps = 1;
62  vrb.buildRow(row, 0, x / eps);
63  // For the way the row has been constructed, it should be composed of only 1s
64  bool areValuesOk = true;
65  for (int i = 0; i < mb.size(); ++i)
66  {
67  bool isThereX = mb.getElement(i).getExponent(0) > 0;
68  bool curCheck = (row(0, i) == !isThereX);
69  areValuesOk = areValuesOk && curCheck;
70  }
71  BOOST_REQUIRE(areValuesOk);
72  }
73 
74 #endif // HAVE_EIGEN
75 
76 BOOST_AUTO_TEST_SUITE_END()