35#include <boost/test/unit_test.hpp>
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
45namespace ScaledMatrixUnitTests
53 BOOST_CHECK_EQUAL(0u, m.GetRows());
54 BOOST_CHECK_EQUAL(0u, m.GetColumns());
55 BOOST_CHECK(std::shared_ptr<InnerMatrix>() != m.GetOwnedMatrix());
56 BOOST_CHECK_EQUAL(
'N', m.GetTransposeFlag());
57 BOOST_CHECK_EQUAL(0u, m.GetStorageSize());
58 BOOST_CHECK_EQUAL(
eFULL, m.GetStorageType());
59 BOOST_CHECK_EQUAL(0.0, m.Scale());
64 double buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
66 std::shared_ptr<InnerMatrix> in(
new InnerMatrix(3, 2, buf));
68 BOOST_CHECK_EQUAL(3u, m.GetRows());
69 BOOST_CHECK_EQUAL(2u, m.GetColumns());
70 BOOST_CHECK_EQUAL(in, m.GetOwnedMatrix());
71 BOOST_CHECK_EQUAL(
'N', m.GetTransposeFlag());
72 BOOST_CHECK_EQUAL(6u, m.GetStorageSize());
73 BOOST_CHECK_EQUAL(
eFULL, m.GetStorageType());
74 BOOST_CHECK_EQUAL(2.7, m.Scale());
79 double buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
81 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, buf));
82 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(3, 2, buf));
83 std::shared_ptr<InnerMatrix> in3(
new InnerMatrix(3, 2, buf));
84 std::shared_ptr<InnerMatrix> in4(
new InnerMatrix(3, 2, buf));
101 BOOST_CHECK_EQUAL(m1(0, 0), 1.0);
102 BOOST_CHECK_EQUAL(m1(1, 0), 2.0);
103 BOOST_CHECK_EQUAL(m1(2, 0), 3.0);
104 BOOST_CHECK_EQUAL(m1(0, 1), 4.0);
105 BOOST_CHECK_EQUAL(m1(1, 1), 5.0);
106 BOOST_CHECK_EQUAL(m1(2, 1), 6.0);
108 BOOST_CHECK_EQUAL(m4(0, 0), 4.0);
109 BOOST_CHECK_EQUAL(m4(1, 0), 8.0);
110 BOOST_CHECK_EQUAL(m4(2, 0), 12.0);
111 BOOST_CHECK_EQUAL(m4(0, 1), 16.0);
112 BOOST_CHECK_EQUAL(m4(1, 1), 20.0);
113 BOOST_CHECK_EQUAL(m4(2, 1), 24.0);
115 BOOST_CHECK_EQUAL(m2(0, 0), 2.0);
116 BOOST_CHECK_EQUAL(m2(0, 1), 4.0);
117 BOOST_CHECK_EQUAL(m2(0, 2), 6.0);
118 BOOST_CHECK_EQUAL(m2(1, 0), 8.0);
119 BOOST_CHECK_EQUAL(m2(1, 1), 10.0);
120 BOOST_CHECK_EQUAL(m2(1, 2), 12.0);
122 BOOST_CHECK_EQUAL(m3(0, 0), 3.0);
123 BOOST_CHECK_EQUAL(m3(0, 1), 6.0);
124 BOOST_CHECK_EQUAL(m3(0, 2), 9.0);
125 BOOST_CHECK_EQUAL(m3(1, 0), 12.0);
126 BOOST_CHECK_EQUAL(m3(1, 1), 15.0);
127 BOOST_CHECK_EQUAL(m3(1, 2), 18.0);
132 double buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
134 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, buf));
135 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(3, 2, buf));
136 std::shared_ptr<InnerMatrix> in3(
new InnerMatrix(3, 2, buf));
137 std::shared_ptr<InnerMatrix> in4(
new InnerMatrix(3, 2, buf));
154 SMat::const_iterator i1 = m1.begin();
155 SMat::const_iterator i2 = m2.begin();
156 SMat::const_iterator i3 = m3.begin();
157 SMat::const_iterator i4 = m4.begin();
159 BOOST_CHECK(1.0 == *(i1++));
160 BOOST_CHECK(2.0 == *(i1++));
161 BOOST_CHECK(3.0 == *(i1++));
162 BOOST_CHECK(4.0 == *(i1++));
163 BOOST_CHECK(5.0 == *(i1++));
164 BOOST_CHECK(6.0 == *(i1++));
165 BOOST_CHECK(m1.end() == i1);
167 BOOST_CHECK(2.0 == *(i2++));
168 BOOST_CHECK(8.0 == *(i2++));
169 BOOST_CHECK(4.0 == *(i2++));
170 BOOST_CHECK(10.0 == *(i2++));
171 BOOST_CHECK(6.0 == *(i2++));
172 BOOST_CHECK(12.0 == *(i2++));
173 BOOST_CHECK(m2.end() == i2);
175 BOOST_CHECK(3.0 == *(i3++));
176 BOOST_CHECK(12.0 == *(i3++));
177 BOOST_CHECK(6.0 == *(i3++));
178 BOOST_CHECK(15.0 == *(i3++));
179 BOOST_CHECK(9.0 == *(i3++));
180 BOOST_CHECK(18.0 == *(i3++));
181 BOOST_CHECK(m3.end() == i3);
183 BOOST_CHECK(4.0 == *(i4++));
184 BOOST_CHECK(8.0 == *(i4++));
185 BOOST_CHECK(12.0 == *(i4++));
186 BOOST_CHECK(16.0 == *(i4++));
187 BOOST_CHECK(20.0 == *(i4++));
188 BOOST_CHECK(24.0 == *(i4++));
189 BOOST_CHECK(m4.end() == i4);
195 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
196 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
197 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, lhs_buf));
198 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
203 double expected_result_buf[] = {78.0, 108.0, 138.0, 98.0, 136.0,
204 174.0, 118.0, 164.0, 210.0};
205 InnerMatrix expected_result(3, 3, expected_result_buf);
207 BOOST_CHECK_EQUAL(expected_result, result1);
212 BOOST_CHECK_EQUAL(expected_result, result2);
217 BOOST_CHECK_EQUAL(expected_result, result3);
222 BOOST_CHECK_EQUAL(expected_result, result4);
229 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
230 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
231 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(2, 3, lhs_buf));
232 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
237 double expected_result_buf[] = {46.0, 106.0, 166.0, 58.0, 134.0,
238 210.0, 70.0, 162.0, 254.0};
239 InnerMatrix expected_result(3, 3, expected_result_buf);
243 BOOST_CHECK_EQUAL(expected_result, result1);
248 BOOST_CHECK_EQUAL(expected_result, result2);
255 BOOST_CHECK_EQUAL(expected_result, result3);
260 BOOST_CHECK_EQUAL(expected_result, result4);
267 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
268 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
269 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(2, 3, lhs_buf));
270 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
275 double expected_result_buf[] = {178.0, 232.0, 196.0, 256.0};
276 InnerMatrix expected_result(2, 2, expected_result_buf);
280 BOOST_CHECK_EQUAL(expected_result, result1);
285 BOOST_CHECK_EQUAL(expected_result, result2);
292 BOOST_CHECK_EQUAL(expected_result, result3);
297 BOOST_CHECK_EQUAL(expected_result, result4);
304 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
305 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
306 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, lhs_buf));
307 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
312 double expected_result_buf[] = {116.0, 278.0, 128.0, 308.0};
313 InnerMatrix expected_result(2, 2, expected_result_buf);
318 BOOST_CHECK_EQUAL(expected_result, result1);
323 BOOST_CHECK_EQUAL(expected_result, result2);
328 BOOST_CHECK_EQUAL(expected_result, result3);
333 BOOST_CHECK_EQUAL(expected_result, result4);
340 double lhs_buf[] = {1, 2, 3, 4, 5, 6};
342 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, lhs_buf));
346 BOOST_CHECK_EQUAL(m1(0, 0), transpose(0, 0));
347 BOOST_CHECK_EQUAL(m1(1, 0), transpose(0, 1));
348 BOOST_CHECK_EQUAL(m1(2, 0), transpose(0, 2));
349 BOOST_CHECK_EQUAL(m1(0, 1), transpose(1, 0));
350 BOOST_CHECK_EQUAL(m1(1, 1), transpose(1, 1));
351 BOOST_CHECK_EQUAL(m1(2, 1), transpose(1, 2));
358 double lhs_buf[] = {1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0};
359 double rhs_buf[] = {1.0, 2.0};
361 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(4, 2, lhs_buf));
365 double expected_result_buf[] = {10, 22, 34, 46};
369 BOOST_CHECK_EQUAL(expected_result, result1);
374 BOOST_CHECK_EQUAL(expected_result, result2);
380 double buf1[] = {1.0, 2.0, 3.0, 4.0};
381 double buf2[] = {5.0, 6.0, 7.0, 8.0};
382 double buf3[] = {-1.0, -2.0, -3.0, -4.0};
384 std::shared_ptr<NekMatrix<NekDouble>> DMatInner(
386 std::shared_ptr<NekMatrix<NekDouble>> InvMassInner(
392 Mat = Mat + DMat * InvMass *
Transpose(DMat);
394 BOOST_CHECK_EQUAL(1391.0, Mat(0, 0));
395 BOOST_CHECK_EQUAL(2037.0, Mat(0, 1));
396 BOOST_CHECK_EQUAL(2062.0, Mat(1, 0));
397 BOOST_CHECK_EQUAL(3020.0, Mat(1, 1));
403 double dmat_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
404 std::shared_ptr<NekMatrix<NekDouble>> inner(
408 std::shared_ptr<NekMatrix<NekDouble>> inner1(
414 LocMat = LocMat * invMass;
416 BOOST_CHECK_EQUAL(LocMat(0, 0), 30.0);
417 BOOST_CHECK_EQUAL(LocMat(0, 1), 66.0);
418 BOOST_CHECK_EQUAL(LocMat(0, 2), 102.0);
419 BOOST_CHECK_EQUAL(LocMat(1, 0), 66.0);
420 BOOST_CHECK_EQUAL(LocMat(1, 1), 150.0);
421 BOOST_CHECK_EQUAL(LocMat(1, 2), 234.0);
422 BOOST_CHECK_EQUAL(LocMat(2, 0), 102.0);
423 BOOST_CHECK_EQUAL(LocMat(2, 1), 234.0);
424 BOOST_CHECK_EQUAL(LocMat(2, 2), 366.0);
428 double dmat_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
429 std::shared_ptr<NekMatrix<NekDouble>> inner(
432 std::shared_ptr<NekMatrix<NekDouble>> inner1(
437 BOOST_CHECK_EQUAL(result2(0, 0), 30.0);
438 BOOST_CHECK_EQUAL(result2(0, 1), 66.0);
439 BOOST_CHECK_EQUAL(result2(0, 2), 102.0);
440 BOOST_CHECK_EQUAL(result2(1, 0), 66.0);
441 BOOST_CHECK_EQUAL(result2(1, 1), 150.0);
442 BOOST_CHECK_EQUAL(result2(1, 2), 234.0);
443 BOOST_CHECK_EQUAL(result2(2, 0), 102.0);
444 BOOST_CHECK_EQUAL(result2(2, 1), 234.0);
445 BOOST_CHECK_EQUAL(result2(2, 2), 366.0);
452 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
453 double rhs_buf[] = {1.0, 2.0};
455 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(2, 4, lhs_buf));
459 double expected_result_buf[] = {10, 22, 34, 46};
464 BOOST_CHECK_EQUAL(expected_result, result3);
468 BOOST_CHECK_EQUAL(expected_result, result1);
473 BOOST_CHECK_EQUAL(expected_result, result2);
BOOST_AUTO_TEST_CASE(TestDefaultConstructor)
NekMatrix< InnerMatrix, ScaledMatrixTag > SMat
NekMatrix< double > InnerMatrix
The above copyright notice and this permission notice shall be included.
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)