35#include <boost/test/unit_test.hpp>
38#include <boost/test/tools/floating_point_comparison.hpp>
39#include <boost/test/unit_test.hpp>
51 BOOST_CHECK_EQUAL(0u, m.GetRows());
52 BOOST_CHECK_EQUAL(0u, m.GetColumns());
53 BOOST_CHECK(std::shared_ptr<InnerMatrix>() != m.GetOwnedMatrix());
54 BOOST_CHECK_EQUAL(
'N', m.GetTransposeFlag());
55 BOOST_CHECK_EQUAL(0u, m.GetStorageSize());
56 BOOST_CHECK_EQUAL(
eFULL, m.GetStorageType());
57 BOOST_CHECK_EQUAL(0.0, m.Scale());
62 double buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
64 std::shared_ptr<InnerMatrix> in(
new InnerMatrix(3, 2, buf));
66 BOOST_CHECK_EQUAL(3u, m.GetRows());
67 BOOST_CHECK_EQUAL(2u, m.GetColumns());
68 BOOST_CHECK_EQUAL(in, m.GetOwnedMatrix());
69 BOOST_CHECK_EQUAL(
'N', m.GetTransposeFlag());
70 BOOST_CHECK_EQUAL(6u, m.GetStorageSize());
71 BOOST_CHECK_EQUAL(
eFULL, m.GetStorageType());
72 BOOST_CHECK_EQUAL(2.7, m.Scale());
77 double buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
79 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, buf));
80 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(3, 2, buf));
81 std::shared_ptr<InnerMatrix> in3(
new InnerMatrix(3, 2, buf));
82 std::shared_ptr<InnerMatrix> in4(
new InnerMatrix(3, 2, buf));
99 BOOST_CHECK_EQUAL(m1(0, 0), 1.0);
100 BOOST_CHECK_EQUAL(m1(1, 0), 2.0);
101 BOOST_CHECK_EQUAL(m1(2, 0), 3.0);
102 BOOST_CHECK_EQUAL(m1(0, 1), 4.0);
103 BOOST_CHECK_EQUAL(m1(1, 1), 5.0);
104 BOOST_CHECK_EQUAL(m1(2, 1), 6.0);
106 BOOST_CHECK_EQUAL(m4(0, 0), 4.0);
107 BOOST_CHECK_EQUAL(m4(1, 0), 8.0);
108 BOOST_CHECK_EQUAL(m4(2, 0), 12.0);
109 BOOST_CHECK_EQUAL(m4(0, 1), 16.0);
110 BOOST_CHECK_EQUAL(m4(1, 1), 20.0);
111 BOOST_CHECK_EQUAL(m4(2, 1), 24.0);
113 BOOST_CHECK_EQUAL(m2(0, 0), 2.0);
114 BOOST_CHECK_EQUAL(m2(0, 1), 4.0);
115 BOOST_CHECK_EQUAL(m2(0, 2), 6.0);
116 BOOST_CHECK_EQUAL(m2(1, 0), 8.0);
117 BOOST_CHECK_EQUAL(m2(1, 1), 10.0);
118 BOOST_CHECK_EQUAL(m2(1, 2), 12.0);
120 BOOST_CHECK_EQUAL(m3(0, 0), 3.0);
121 BOOST_CHECK_EQUAL(m3(0, 1), 6.0);
122 BOOST_CHECK_EQUAL(m3(0, 2), 9.0);
123 BOOST_CHECK_EQUAL(m3(1, 0), 12.0);
124 BOOST_CHECK_EQUAL(m3(1, 1), 15.0);
125 BOOST_CHECK_EQUAL(m3(1, 2), 18.0);
130 double buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
132 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, buf));
133 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(3, 2, buf));
134 std::shared_ptr<InnerMatrix> in3(
new InnerMatrix(3, 2, buf));
135 std::shared_ptr<InnerMatrix> in4(
new InnerMatrix(3, 2, buf));
152 SMat::const_iterator i1 = m1.begin();
153 SMat::const_iterator i2 = m2.begin();
154 SMat::const_iterator i3 = m3.begin();
155 SMat::const_iterator i4 = m4.begin();
157 BOOST_CHECK(1.0 == *(i1++));
158 BOOST_CHECK(2.0 == *(i1++));
159 BOOST_CHECK(3.0 == *(i1++));
160 BOOST_CHECK(4.0 == *(i1++));
161 BOOST_CHECK(5.0 == *(i1++));
162 BOOST_CHECK(6.0 == *(i1++));
163 BOOST_CHECK(m1.end() == i1);
165 BOOST_CHECK(2.0 == *(i2++));
166 BOOST_CHECK(8.0 == *(i2++));
167 BOOST_CHECK(4.0 == *(i2++));
168 BOOST_CHECK(10.0 == *(i2++));
169 BOOST_CHECK(6.0 == *(i2++));
170 BOOST_CHECK(12.0 == *(i2++));
171 BOOST_CHECK(m2.end() == i2);
173 BOOST_CHECK(3.0 == *(i3++));
174 BOOST_CHECK(12.0 == *(i3++));
175 BOOST_CHECK(6.0 == *(i3++));
176 BOOST_CHECK(15.0 == *(i3++));
177 BOOST_CHECK(9.0 == *(i3++));
178 BOOST_CHECK(18.0 == *(i3++));
179 BOOST_CHECK(m3.end() == i3);
181 BOOST_CHECK(4.0 == *(i4++));
182 BOOST_CHECK(8.0 == *(i4++));
183 BOOST_CHECK(12.0 == *(i4++));
184 BOOST_CHECK(16.0 == *(i4++));
185 BOOST_CHECK(20.0 == *(i4++));
186 BOOST_CHECK(24.0 == *(i4++));
187 BOOST_CHECK(m4.end() == i4);
193 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
194 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
195 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, lhs_buf));
196 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
201 double expected_result_buf[] = {78.0, 108.0, 138.0, 98.0, 136.0,
202 174.0, 118.0, 164.0, 210.0};
203 InnerMatrix expected_result(3, 3, expected_result_buf);
205 BOOST_CHECK_EQUAL(expected_result, result1);
210 BOOST_CHECK_EQUAL(expected_result, result2);
215 BOOST_CHECK_EQUAL(expected_result, result3);
220 BOOST_CHECK_EQUAL(expected_result, result4);
227 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
228 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
229 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(2, 3, lhs_buf));
230 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
235 double expected_result_buf[] = {46.0, 106.0, 166.0, 58.0, 134.0,
236 210.0, 70.0, 162.0, 254.0};
237 InnerMatrix expected_result(3, 3, expected_result_buf);
241 BOOST_CHECK_EQUAL(expected_result, result1);
246 BOOST_CHECK_EQUAL(expected_result, result2);
253 BOOST_CHECK_EQUAL(expected_result, result3);
258 BOOST_CHECK_EQUAL(expected_result, result4);
265 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
266 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
267 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(2, 3, lhs_buf));
268 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
273 double expected_result_buf[] = {178.0, 232.0, 196.0, 256.0};
274 InnerMatrix expected_result(2, 2, expected_result_buf);
278 BOOST_CHECK_EQUAL(expected_result, result1);
283 BOOST_CHECK_EQUAL(expected_result, result2);
290 BOOST_CHECK_EQUAL(expected_result, result3);
295 BOOST_CHECK_EQUAL(expected_result, result4);
302 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
303 double rhs_buf[] = {7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
304 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, lhs_buf));
305 std::shared_ptr<InnerMatrix> in2(
new InnerMatrix(2, 3, rhs_buf));
310 double expected_result_buf[] = {116.0, 278.0, 128.0, 308.0};
311 InnerMatrix expected_result(2, 2, expected_result_buf);
316 BOOST_CHECK_EQUAL(expected_result, result1);
321 BOOST_CHECK_EQUAL(expected_result, result2);
326 BOOST_CHECK_EQUAL(expected_result, result3);
331 BOOST_CHECK_EQUAL(expected_result, result4);
338 double lhs_buf[] = {1, 2, 3, 4, 5, 6};
340 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(3, 2, lhs_buf));
344 BOOST_CHECK_EQUAL(m1(0, 0), transpose(0, 0));
345 BOOST_CHECK_EQUAL(m1(1, 0), transpose(0, 1));
346 BOOST_CHECK_EQUAL(m1(2, 0), transpose(0, 2));
347 BOOST_CHECK_EQUAL(m1(0, 1), transpose(1, 0));
348 BOOST_CHECK_EQUAL(m1(1, 1), transpose(1, 1));
349 BOOST_CHECK_EQUAL(m1(2, 1), transpose(1, 2));
356 double lhs_buf[] = {1.0, 3.0, 5.0, 7.0, 2.0, 4.0, 6.0, 8.0};
357 double rhs_buf[] = {1.0, 2.0};
359 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(4, 2, lhs_buf));
363 double expected_result_buf[] = {10, 22, 34, 46};
367 BOOST_CHECK_EQUAL(expected_result, result1);
372 BOOST_CHECK_EQUAL(expected_result, result2);
378 double buf1[] = {1.0, 2.0, 3.0, 4.0};
379 double buf2[] = {5.0, 6.0, 7.0, 8.0};
380 double buf3[] = {-1.0, -2.0, -3.0, -4.0};
382 std::shared_ptr<NekMatrix<NekDouble>> DMatInner(
384 std::shared_ptr<NekMatrix<NekDouble>> InvMassInner(
390 Mat = Mat + DMat * InvMass *
Transpose(DMat);
392 BOOST_CHECK_EQUAL(1391.0, Mat(0, 0));
393 BOOST_CHECK_EQUAL(2037.0, Mat(0, 1));
394 BOOST_CHECK_EQUAL(2062.0, Mat(1, 0));
395 BOOST_CHECK_EQUAL(3020.0, Mat(1, 1));
401 double dmat_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
402 std::shared_ptr<NekMatrix<NekDouble>> inner(
406 std::shared_ptr<NekMatrix<NekDouble>> inner1(
412 LocMat = LocMat * invMass;
414 BOOST_CHECK_EQUAL(LocMat(0, 0), 30.0);
415 BOOST_CHECK_EQUAL(LocMat(0, 1), 66.0);
416 BOOST_CHECK_EQUAL(LocMat(0, 2), 102.0);
417 BOOST_CHECK_EQUAL(LocMat(1, 0), 66.0);
418 BOOST_CHECK_EQUAL(LocMat(1, 1), 150.0);
419 BOOST_CHECK_EQUAL(LocMat(1, 2), 234.0);
420 BOOST_CHECK_EQUAL(LocMat(2, 0), 102.0);
421 BOOST_CHECK_EQUAL(LocMat(2, 1), 234.0);
422 BOOST_CHECK_EQUAL(LocMat(2, 2), 366.0);
426 double dmat_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
427 std::shared_ptr<NekMatrix<NekDouble>> inner(
430 std::shared_ptr<NekMatrix<NekDouble>> inner1(
435 BOOST_CHECK_EQUAL(result2(0, 0), 30.0);
436 BOOST_CHECK_EQUAL(result2(0, 1), 66.0);
437 BOOST_CHECK_EQUAL(result2(0, 2), 102.0);
438 BOOST_CHECK_EQUAL(result2(1, 0), 66.0);
439 BOOST_CHECK_EQUAL(result2(1, 1), 150.0);
440 BOOST_CHECK_EQUAL(result2(1, 2), 234.0);
441 BOOST_CHECK_EQUAL(result2(2, 0), 102.0);
442 BOOST_CHECK_EQUAL(result2(2, 1), 234.0);
443 BOOST_CHECK_EQUAL(result2(2, 2), 366.0);
450 double lhs_buf[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
451 double rhs_buf[] = {1.0, 2.0};
453 std::shared_ptr<InnerMatrix> in1(
new InnerMatrix(2, 4, lhs_buf));
457 double expected_result_buf[] = {10, 22, 34, 46};
462 BOOST_CHECK_EQUAL(expected_result, result3);
466 BOOST_CHECK_EQUAL(expected_result, result1);
471 BOOST_CHECK_EQUAL(expected_result, result2);
BOOST_AUTO_TEST_CASE(TestDefaultConstructor)
NekMatrix< InnerMatrix, ScaledMatrixTag > SMat
NekMatrix< double > InnerMatrix
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)