5 #define BOOST_TEST_DYN_LINK 7 #include <boost/test/unit_test.hpp> 8 #include <DCPSE/MonomialBasis.hpp> 9 #include <DCPSE/VandermondeRowBuilder.hpp> 10 #include <DCPSE/Vandermonde.hpp> 11 #include "../../openfpm_numerics/src/DMatrix/EMatrix.hpp" 13 BOOST_AUTO_TEST_SUITE(Vandermonde_tests)
18 BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_AllOnes_test)
21 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
25 vrb.buildRow(row, 0, x, eps);
27 bool isRowAllOnes =
true;
28 for (
int i = 0; i < mb.size(); ++i)
30 isRowAllOnes = isRowAllOnes && (row(0, i) == 1);
32 BOOST_REQUIRE(isRowAllOnes);
35 BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_OneZero_test)
38 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
42 vrb.buildRow(row, 0, x, eps);
44 bool areValuesOk =
true;
45 for (
int i = 0; i < mb.size(); ++i)
47 bool isThereY = mb.getElement(i).getExponent(1) > 0;
48 bool curCheck = (row(0, i) == !isThereY);
49 areValuesOk = areValuesOk && curCheck;
51 BOOST_REQUIRE(areValuesOk);
54 BOOST_AUTO_TEST_CASE(VandermondeRowBuilder_ZeroOne_test)
57 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> row(1, mb.size());
61 vrb.buildRow(row, 0, x, eps);
63 bool areValuesOk =
true;
64 for (
int i = 0; i < mb.size(); ++i)
66 bool isThereX = mb.getElement(i).getExponent(0) > 0;
67 bool curCheck = (row(0, i) == !isThereX);
68 areValuesOk = areValuesOk && curCheck;
70 BOOST_REQUIRE(areValuesOk);
73 BOOST_AUTO_TEST_CASE(Vandermonde_KnownValues_test)
78 std::vector<Point<2, double>> neighbours;
79 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> V(mb.size(), mb.size());
80 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> ExpectedV(mb.size(), mb.size());
86 parts.getLastPos()[0]=0;
87 parts.getLastPos()[1]=0;
89 parts.getLastPos()[0]=1;
90 parts.getLastPos()[1]=1;
92 parts.getLastPos()[0]=-1;
93 parts.getLastPos()[1]=-1;
95 parts.getLastPos()[0]=1;
96 parts.getLastPos()[1]=-1;
98 parts.getLastPos()[0]=-1;
99 parts.getLastPos()[1]=1;
101 parts.getLastPos()[0]=0;
102 parts.getLastPos()[1]=1;
104 parts.getLastPos()[0]=0;
105 parts.getLastPos()[1]=-1;
107 const std::vector<size_t> keys({1,2,3,4,5,6});
113 vandermonde.getMatrix(V);
117 ExpectedV(0, 1) = -0.3;
118 ExpectedV(0, 2) = 0.09;
119 ExpectedV(0, 3) = -0.3;
120 ExpectedV(0, 4) = +0.09;
121 ExpectedV(0, 5) = 0.09;
123 ExpectedV(1, 1) = +0.3;
124 ExpectedV(1, 2) = 0.09;
125 ExpectedV(1, 3) = +0.3;
126 ExpectedV(1, 4) = +0.09;
127 ExpectedV(1, 5) = 0.09;
129 ExpectedV(2, 1) = -0.3;
130 ExpectedV(2, 2) = 0.09;
131 ExpectedV(2, 3) = +0.3;
132 ExpectedV(2, 4) = -0.09;
133 ExpectedV(2, 5) = 0.09;
135 ExpectedV(3, 1) = +0.3;
136 ExpectedV(3, 2) = 0.09;
137 ExpectedV(3, 3) = -0.3;
138 ExpectedV(3, 4) = -0.09;
139 ExpectedV(3, 5) = 0.09;
143 ExpectedV(4, 3) = -0.3;
145 ExpectedV(4, 5) = 0.09;
149 ExpectedV(5, 3) = +0.3;
151 ExpectedV(5, 5) = 0.09;
154 for (
int i = 0; i < mb.size(); ++i)
157 for (
int j = 0; j < mb.size(); ++j)
160 BOOST_REQUIRE_CLOSE(V(i, j), ExpectedV(i, j), 1e-6);
165 BOOST_AUTO_TEST_CASE(Vandermonde_TranslatedSetup_test)
170 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> V(mb.size(), mb.size());
171 EMatrix<double, Eigen::Dynamic, Eigen::Dynamic> ExpectedV(mb.size(), mb.size());
178 parts.getLastPos()[0]=1;
179 parts.getLastPos()[1]=1;
181 parts.getLastPos()[0]=2;
182 parts.getLastPos()[1]=2;
184 parts.getLastPos()[0]=0;
185 parts.getLastPos()[1]=0;
187 parts.getLastPos()[0]=2;
188 parts.getLastPos()[1]=0;
190 parts.getLastPos()[0]=0;
191 parts.getLastPos()[1]=2;
193 parts.getLastPos()[0]=1;
194 parts.getLastPos()[1]=2;
196 parts.getLastPos()[0]=1;
197 parts.getLastPos()[1]=0;
199 const std::vector<size_t> keys({1,2,3,4,5,6});
205 vandermonde.getMatrix(V);
209 ExpectedV(0, 1) = -0.3;
210 ExpectedV(0, 2) = 0.09;
211 ExpectedV(0, 3) = -0.3;
212 ExpectedV(0, 4) = +0.09;
213 ExpectedV(0, 5) = 0.09;
215 ExpectedV(1, 1) = +0.3;
216 ExpectedV(1, 2) = 0.09;
217 ExpectedV(1, 3) = +0.3;
218 ExpectedV(1, 4) = +0.09;
219 ExpectedV(1, 5) = 0.09;
221 ExpectedV(2, 1) = -0.3;
222 ExpectedV(2, 2) = 0.09;
223 ExpectedV(2, 3) = +0.3;
224 ExpectedV(2, 4) = -0.09;
225 ExpectedV(2, 5) = 0.09;
227 ExpectedV(3, 1) = +0.3;
228 ExpectedV(3, 2) = 0.09;
229 ExpectedV(3, 3) = -0.3;
230 ExpectedV(3, 4) = -0.09;
231 ExpectedV(3, 5) = 0.09;
235 ExpectedV(4, 3) = -0.3;
237 ExpectedV(4, 5) = 0.09;
241 ExpectedV(5, 3) = +0.3;
243 ExpectedV(5, 5) = 0.09;
246 for (
int i = 0; i < mb.size(); ++i)
249 for (
int j = 0; j < mb.size(); ++j)
252 BOOST_REQUIRE_CLOSE(V(i, j), ExpectedV(i, j), 1e-6);
259 BOOST_AUTO_TEST_SUITE_END()
This class implement the point shape in an N-dimensional space.
void add()
Add local particle.