Nektar++
Functions
Nektar::ScaledBlockMatrixUnitTests Namespace Reference

Functions

 BOOST_AUTO_TEST_CASE (TestMatrixVectorMultiplication)
 
 BOOST_AUTO_TEST_CASE (TestMultiplicationScaledBlock_1)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

Nektar::ScaledBlockMatrixUnitTests::BOOST_AUTO_TEST_CASE ( TestMatrixVectorMultiplication  )

Definition at line 47 of file TestScaledBlockMatrixOperations.cpp.

48{
49 typedef NekMatrix<double> InnerType;
51
52 double m1_buf[] = {1.0 / 2.0, 6.0 / 2.0, 2.0 / 2.0,
53 7.0 / 2.0, 3.0 / 2.0, 8.0 / 2.0};
54 double m2_buf[] = {4.0 / 2.0, 9.0 / 2.0, 5.0 / 2.0, 10.0 / 2.0};
55 double m3_buf[] = {11.0 / 2.0, 16.0 / 2.0, 12.0 / 2.0,
56 17.0 / 2.0, 13.0 / 2.0, 18 / 2.0};
57 double m4_buf[] = {14.0 / 2.0, 19.0 / 2.0, 15.0 / 2.0, 20.0 / 2.0};
58
59 std::shared_ptr<InnerType> in_m1(new InnerType(2, 3, m1_buf));
60 std::shared_ptr<InnerType> in_m2(new InnerType(2, 2, m2_buf));
61 std::shared_ptr<InnerType> in_m3(new InnerType(2, 3, m3_buf));
62 std::shared_ptr<InnerType> in_m4(new InnerType(2, 2, m4_buf));
63
64 std::shared_ptr<ScaleType> m1(new ScaleType(2.0, in_m1));
65 std::shared_ptr<ScaleType> m2(new ScaleType(2.0, in_m2));
66 std::shared_ptr<ScaleType> m3(new ScaleType(2.0, in_m3));
67 std::shared_ptr<ScaleType> m4(new ScaleType(2.0, in_m4));
68
69 unsigned int rowCounts[] = {2, 2};
70 unsigned int colCounts[] = {3, 2};
71
72 typedef NekMatrix<ScaleType, BlockMatrixTag> BlockType;
73
74 std::shared_ptr<BlockType> b(new BlockType(2, 2, rowCounts, colCounts));
75 b->SetBlock(0, 0, m1);
76 b->SetBlock(0, 1, m2);
77 b->SetBlock(1, 0, m3);
78 b->SetBlock(1, 1, m4);
79
80 double rhs_buf[] = {10, 20, 30, 40, 50};
81 NekVector<double> rhs(5, rhs_buf);
82
83 NekVector<double> result = (*b) * rhs;
84
85 double expected_buf[] = {550, 1300, 2050, 2800};
86 NekVector<double> expected_result(4, expected_buf);
87
88 BOOST_CHECK_EQUAL(expected_result, result);
89}

◆ BOOST_AUTO_TEST_CASE() [2/2]

Nektar::ScaledBlockMatrixUnitTests::BOOST_AUTO_TEST_CASE ( TestMultiplicationScaledBlock_1  )

Definition at line 91 of file TestScaledBlockMatrixOperations.cpp.

92{
93 typedef NekMatrix<double> InnerType;
95
96 double m_00_buf[] = {3, 1, 5, 5};
97 double m_01_buf[] = {2, 4, 4, 1, 1, 3};
98 double m_02_buf[] = {3, 1, 2, 2, 4, 1, 4, 2};
99
100 double m_10_buf[] = {1, 3, 5, 1, 4, 2};
101 double m_11_buf[] = {4, 4, 1, 1, 1, 4, 5, 5, 3};
102 double m_12_buf[] = {5, 2, 1, 2, 3, 1, 1, 3, 1, 4, 1, 1};
103
104 double m_20_buf[] = {3, 1, 4, 2, 5, 1, 4, 2};
105 double m_21_buf[] = {4, 5, 2, 4, 4, 2, 3, 5, 2, 2, 5, 3};
106 double m_22_buf[] = {3, 4, 3, 1, 2, 1, 2, 4, 4, 5, 2, 3, 5, 4, 1, 1};
107
108 double m_30_buf[] = {2, 2, 1, 4, 5, 5};
109 double m_31_buf[] = {1, 1, 3, 2, 1, 2, 3, 3, 2};
110 double m_32_buf[] = {3, 1, 3, 1, 2, 2, 4, 2, 5, 5, 1, 1};
111
112 std::shared_ptr<InnerType> m00(new InnerType(2, 2, m_00_buf));
113 std::shared_ptr<InnerType> m01(new InnerType(2, 3, m_01_buf));
114 std::shared_ptr<InnerType> m02(new InnerType(2, 4, m_02_buf));
115
116 std::shared_ptr<InnerType> m10(new InnerType(3, 2, m_10_buf));
117 std::shared_ptr<InnerType> m11(new InnerType(3, 3, m_11_buf));
118 std::shared_ptr<InnerType> m12(new InnerType(3, 4, m_12_buf));
119
120 std::shared_ptr<InnerType> m20(new InnerType(4, 2, m_20_buf));
121 std::shared_ptr<InnerType> m21(new InnerType(4, 3, m_21_buf));
122 std::shared_ptr<InnerType> m22(new InnerType(4, 4, m_22_buf));
123
124 std::shared_ptr<InnerType> m30(new InnerType(3, 2, m_30_buf));
125 std::shared_ptr<InnerType> m31(new InnerType(3, 3, m_31_buf));
126 std::shared_ptr<InnerType> m32(new InnerType(3, 4, m_32_buf));
127
128 unsigned int rowCounts[] = {2, 3, 4, 3};
129 unsigned int colCounts[] = {2, 3, 4};
130
131 BlockType b(4, 3, rowCounts, colCounts);
132 b.SetBlock(0, 0, m00);
133 b.SetBlock(0, 1, m01);
134 b.SetBlock(0, 2, m02);
135 b.SetBlock(1, 0, m10);
136 b.SetBlock(1, 1, m11);
137 b.SetBlock(1, 2, m12);
138 b.SetBlock(2, 0, m20);
139 b.SetBlock(2, 1, m21);
140 b.SetBlock(2, 2, m22);
141 b.SetBlock(3, 0, m30);
142 b.SetBlock(3, 1, m31);
143 b.SetBlock(3, 2, m32);
144
145 Array<OneD, unsigned int> arrayRowCounts(4, rowCounts);
146 Array<OneD, unsigned int> arrayColCounts(3, colCounts);
147 BlockType b_initializedWithArray(arrayRowCounts, arrayColCounts);
148 b_initializedWithArray.SetBlock(0, 0, m00);
149 b_initializedWithArray.SetBlock(0, 1, m01);
150 b_initializedWithArray.SetBlock(0, 2, m02);
151 b_initializedWithArray.SetBlock(1, 0, m10);
152 b_initializedWithArray.SetBlock(1, 1, m11);
153 b_initializedWithArray.SetBlock(1, 2, m12);
154 b_initializedWithArray.SetBlock(2, 0, m20);
155 b_initializedWithArray.SetBlock(2, 1, m21);
156 b_initializedWithArray.SetBlock(2, 2, m22);
157 b_initializedWithArray.SetBlock(3, 0, m30);
158 b_initializedWithArray.SetBlock(3, 1, m31);
159 b_initializedWithArray.SetBlock(3, 2, m32);
160
161 double rhs_buf[] = {4, 2, 5, 5, 3, 1, 3, 2, 3};
162 NekVector<double> rhs(9, rhs_buf);
163
164 NekVector<double> result = b * rhs;
165 NekVector<double> result1 = b_initializedWithArray * rhs;
166
167 double expected_buf[] = {84, 63, 71, 80, 67, 100, 76, 80, 88, 69, 51, 67};
168 NekVector<double> expected_result(12, expected_buf);
169
170 BOOST_CHECK_EQUAL(expected_result, result);
171 BOOST_CHECK_EQUAL(expected_result, result1);
172}