Nektar++
Functions
Nektar::StandardMatrixOperationsUnitTests Namespace Reference

Functions

 BOOST_AUTO_TEST_CASE (TestAddition)
 
 BOOST_AUTO_TEST_CASE (TestSubtraction)
 
 BOOST_AUTO_TEST_CASE (TestThreeAdditions)
 
 BOOST_AUTO_TEST_CASE (TestTransposedMultiplication)
 
 BOOST_AUTO_TEST_CASE (TestGlobalTransposeMethod)
 
 BOOST_AUTO_TEST_CASE (TestScalarMatrixMultiply)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

Nektar::StandardMatrixOperationsUnitTests::BOOST_AUTO_TEST_CASE ( TestAddition  )

Definition at line 127 of file TestStandardMatrix.cpp.

128{
129 double lhs_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
130 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
131 double rhs_buf[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0,
132 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0};
133
134 NekMatrix<double> lhs1(4, 4, lhs_buf);
135 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> lhs2;
136 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> lhs3;
137
138 NekMatrix<double> rhs1(4, 4, rhs_buf);
139 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> rhs2;
140 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> rhs3;
141
142 GenerateMatrices(lhs1, 2.0, 2, 2, lhs2, lhs3);
143 GenerateMatrices(rhs1, 3.0, 2, 2, rhs2, rhs3);
144
145 double result_buf[] = {5, 10, 15, 20, 25, 30, 35, 40,
146 45, 50, 55, 60, 65, 70, 75, 80};
147 NekMatrix<double> result(4, 4, result_buf);
148
149 RunAllAddCombinations(lhs1, *lhs2, *lhs3, rhs1, *rhs2, *rhs3, result);
150
151 NekMatrix<double> rhs_transposed = Transpose(rhs1);
152 NekMatrix<double> result_with_one_operand_transposed =
153 lhs1 + rhs_transposed;
154
155 double expected_result_with_one_operand_transposed[] = {
156 5, 19, 33, 47, 16, 30, 44, 58, 27, 41, 55, 69, 38, 52, 66, 80};
157 BOOST_CHECK_EQUAL(
158 NekMatrix<double>(4, 4, expected_result_with_one_operand_transposed),
159 result_with_one_operand_transposed);
160}
void GenerateMatrices(const NekMatrix< NumberType, StandardMatrixTag > &m1, NumberType scale, unsigned int blockRows, unsigned int blockColumns, std::shared_ptr< NekMatrix< NekMatrix< NumberType, StandardMatrixTag >, ScaledMatrixTag > > &m2, std::shared_ptr< NekMatrix< NekMatrix< NumberType >, BlockMatrixTag > > &m3)
void RunAllAddCombinations(const NekMatrix< NekDouble, StandardMatrixTag > &l1, const NekMatrix< NekMatrix< NekDouble, LhsScaledInnerMatrixType >, ScaledMatrixTag > &l2, const NekMatrix< NekMatrix< NekDouble, LhsBlockInnerMatrixType >, BlockMatrixTag > &l3, const NekMatrix< NekDouble, StandardMatrixTag > &r1, const NekMatrix< NekMatrix< NekDouble, RhsScaledInnerMatrixType >, ScaledMatrixTag > &r2, const NekMatrix< NekMatrix< NekDouble, RhsBlockInnerMatrixType >, BlockMatrixTag > &r3, const NekMatrix< NekDouble, StandardMatrixTag > &result)
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)

References Nektar::GenerateMatrices(), Nektar::RunAllAddCombinations(), and Nektar::Transpose().

◆ BOOST_AUTO_TEST_CASE() [2/6]

Nektar::StandardMatrixOperationsUnitTests::BOOST_AUTO_TEST_CASE ( TestGlobalTransposeMethod  )

Definition at line 244 of file TestStandardMatrix.cpp.

245{
246 double buf1[] = {1, 4, 2, 5, 3, 6};
247 double buf2[] = {10, 11, 12, 13, 14, 15};
248
249 double transposed_buf1[] = {1, 2, 3, 4, 5, 6};
250
251 double transposed_buf2[] = {10, 13, 11, 14, 12, 15};
252
253 NekMatrix<double> m1(2, 3, buf1);
254 NekMatrix<double> m2(3, 2, buf2);
255
256 NekMatrix<double> tm1 = Transpose(m1);
257 NekMatrix<double> tm2 = Transpose(m2);
258
259 NekMatrix<double> expected_tm1(3, 2, transposed_buf1);
260 NekMatrix<double> expected_tm2(2, 3, transposed_buf2);
261
262 BOOST_CHECK_EQUAL(tm1, expected_tm1);
263 BOOST_CHECK_EQUAL(tm2, expected_tm2);
264
265 BOOST_CHECK_EQUAL(m1(0, 1), 2);
266 BOOST_CHECK_EQUAL(tm1(1, 0), 2);
267
268 m1(0, 1) = 89;
269 BOOST_CHECK_EQUAL(m1(0, 1), 89);
270 BOOST_CHECK_EQUAL(tm1(1, 0), 89);
271
272 BOOST_CHECK_EQUAL(m1.GetTransposeFlag(), 'N');
273 BOOST_CHECK_EQUAL(tm1.GetTransposeFlag(), 'T');
274}

References Nektar::Transpose().

◆ BOOST_AUTO_TEST_CASE() [3/6]

Nektar::StandardMatrixOperationsUnitTests::BOOST_AUTO_TEST_CASE ( TestScalarMatrixMultiply  )

Definition at line 276 of file TestStandardMatrix.cpp.

277{
278 double buf1[] = {1, 4, 2, 5, 3, 6};
279
280 NekMatrix<double> m1(2, 3, buf1);
281 NekMatrix<double> m2 = m1 * 2.0;
282 NekMatrix<double> m3 = 3.0 * m1;
283
284 double m2_expected_result_buf[] = {2.0, 8.0, 4.0, 10.0, 6.0, 12.0};
285
286 double m3_expected_result_buf[] = {3.0, 12.0, 6.0, 15.0, 9.0, 18.0};
287
288 NekMatrix<double> m2_expected_result(2, 3, m2_expected_result_buf);
289 NekMatrix<double> m3_expected_result(2, 3, m3_expected_result_buf);
290
291 BOOST_CHECK_EQUAL(m2_expected_result, m2);
292 BOOST_CHECK_EQUAL(m3_expected_result, m3);
293}

◆ BOOST_AUTO_TEST_CASE() [4/6]

Nektar::StandardMatrixOperationsUnitTests::BOOST_AUTO_TEST_CASE ( TestSubtraction  )

Definition at line 162 of file TestStandardMatrix.cpp.

163{
164 double lhs_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
165 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
166 double rhs_buf[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0,
167 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0};
168
169 NekMatrix<double> lhs1(4, 4, lhs_buf);
170 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> lhs2;
171 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> lhs3;
172
173 NekMatrix<double> rhs1(4, 4, rhs_buf);
174 std::shared_ptr<NekMatrix<NekMatrix<double>, ScaledMatrixTag>> rhs2;
175 std::shared_ptr<NekMatrix<NekMatrix<double>, BlockMatrixTag>> rhs3;
176
177 GenerateMatrices(lhs1, 2.0, 2, 2, lhs2, lhs3);
178 GenerateMatrices(rhs1, 3.0, 2, 2, rhs2, rhs3);
179
180 double result_buf[] = {-1, -2, -3, -4, -5, -6, -7, -8,
181 -9, -10, -11, -12, -13, -14, -15, -16};
182 NekMatrix<double> result(4, 4, result_buf);
183
184 RunAllSubCombinations(lhs1, *lhs2, *lhs3, rhs1, *rhs2, *rhs3, result);
185}
void RunAllSubCombinations(const NekMatrix< NekDouble, StandardMatrixTag > &l1, const NekMatrix< NekMatrix< NekDouble, LhsScaledInnerMatrixType >, ScaledMatrixTag > &l2, const NekMatrix< NekMatrix< NekDouble, LhsBlockInnerMatrixType >, BlockMatrixTag > &l3, const NekMatrix< NekDouble, StandardMatrixTag > &r1, const NekMatrix< NekMatrix< NekDouble, RhsScaledInnerMatrixType >, ScaledMatrixTag > &r2, const NekMatrix< NekMatrix< NekDouble, RhsBlockInnerMatrixType >, BlockMatrixTag > &r3, const NekMatrix< NekDouble, StandardMatrixTag > &result)

References Nektar::GenerateMatrices(), and Nektar::RunAllSubCombinations().

◆ BOOST_AUTO_TEST_CASE() [5/6]

Nektar::StandardMatrixOperationsUnitTests::BOOST_AUTO_TEST_CASE ( TestThreeAdditions  )

Definition at line 187 of file TestStandardMatrix.cpp.

188{
189 double lhs_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
190 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
191 double middle_buf[] = {2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0,
192 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0, 32.0};
193 double rhs_buf[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0,
194 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0};
195
196 NekMatrix<double> lhs(4, 4, lhs_buf);
197 NekMatrix<double> middle(4, 4, middle_buf);
198 NekMatrix<double> rhs(4, 4, rhs_buf);
199
200 NekMatrix<double> result = lhs + middle + rhs;
201}

◆ BOOST_AUTO_TEST_CASE() [6/6]

Nektar::StandardMatrixOperationsUnitTests::BOOST_AUTO_TEST_CASE ( TestTransposedMultiplication  )

Definition at line 203 of file TestStandardMatrix.cpp.

204{
205 {
206 double buf1[] = {1, 4, 2, 5, 3, 6};
207 double buf2[] = {10, 11, 12, 13, 14, 15};
208
209 double transposed_buf1[] = {1, 2, 3, 4, 5, 6};
210
211 double transposed_buf2[] = {10, 13, 11, 14, 12, 15};
212
213 double result_buf[] = {68, 167, 86, 212};
214
215 double transposed_result_buf[] = {62, 85, 108, 67, 92,
216 117, 72, 99, 126};
217
218 NekMatrix<double> m1(2, 3, buf1);
219 NekMatrix<double> m2(3, 2, buf2);
220 NekMatrix<double> transposed_m1(3, 2, transposed_buf1);
221 NekMatrix<double> transposed_m2(2, 3, transposed_buf2);
222
223 NekMatrix<double> expected_result(2, 2, result_buf);
224 NekMatrix<double> expected_transposed_result(3, 3,
225 transposed_result_buf);
226
227 BOOST_CHECK_EQUAL(expected_result, m1 * m2);
228 BOOST_CHECK_EQUAL(expected_transposed_result,
229 transposed_m1 * transposed_m2);
230 m1.Transpose();
231 m2.Transpose();
232 BOOST_CHECK_EQUAL(expected_transposed_result, m1 * m2);
233 m1.Transpose();
234 m2.Transpose();
235 BOOST_CHECK_EQUAL(expected_result, m1 * m2);
236
237 NekMatrix<double> tm1 = Transpose(m1);
238 NekMatrix<double> tm2 = Transpose(m2);
239 BOOST_CHECK_EQUAL(expected_result, m1 * m2);
240 BOOST_CHECK_EQUAL(expected_transposed_result, tm1 * tm2);
241 }
242}

References Nektar::Transpose().