Nektar++
Functions
Nektar::LinearSystemUnitTests Namespace Reference

Functions

 BOOST_AUTO_TEST_CASE (TestLinearSystemSolveWithReturnValue)
 
 BOOST_AUTO_TEST_CASE (TestLinearSystemSolveWithSoluationAsParameter)
 
 BOOST_AUTO_TEST_CASE (TestDiagonalSystem)
 
 BOOST_AUTO_TEST_CASE (TestDiagonalSystemAsFullSystem)
 
 BOOST_AUTO_TEST_CASE (TestSmallFullSystem)
 
 BOOST_AUTO_TEST_CASE (TestLargeFullSystem)
 
 BOOST_AUTO_TEST_CASE (TestFullSystemWithWrappedVectors)
 
 BOOST_AUTO_TEST_CASE (TestSymmetricMatrix)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestDiagonalSystem  )

Definition at line 112 of file testLinearSystem.cpp.

113{
114 double matrix_buf[] = {10, 5, 2};
115
116 double result_buf[] = {20, 50, 10};
117
118 std::shared_ptr<NekMatrix<double>> A(
119 new NekMatrix<double>(3, 3, matrix_buf, eDIAGONAL));
120 std::shared_ptr<NekVector<double>> b(new NekVector<double>(3, result_buf));
121
122 LinearSystem linsys(A);
123
124 NekVector<double> result = linsys.Solve(b);
125
126 double expected_result_buf[] = {2, 10, 5};
127 NekVector<double> expectedResult(3, expected_result_buf);
128
129 BOOST_CHECK_EQUAL(result, expectedResult);
130 std::shared_ptr<NekVector<double>> b1 = b;
131 NekVector<double> result1 = linsys.Solve(b1);
132 BOOST_CHECK_EQUAL(result1, expectedResult);
133
134 NekVector<double> result2 = linsys.SolveTranspose(b);
135 BOOST_CHECK_EQUAL(expectedResult, result2);
136}

References Nektar::eDIAGONAL, Nektar::LinearSystem::Solve(), and Nektar::LinearSystem::SolveTranspose().

◆ BOOST_AUTO_TEST_CASE() [2/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestDiagonalSystemAsFullSystem  )

Definition at line 138 of file testLinearSystem.cpp.

139{
140 double matrix_buf[] = {10.0, 0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 2.0};
141
142 double result_buf[] = {20, 50, 10};
143
144 std::shared_ptr<NekMatrix<double>> A(
145 new NekMatrix<double>(3, 3, matrix_buf, eFULL));
146 std::shared_ptr<NekVector<double>> b(new NekVector<double>(3, result_buf));
147
148 LinearSystem linsys(A);
149
150 NekVector<double> result = linsys.Solve(b);
151
152 double epsilon = 1e-14;
153
154 BOOST_CHECK_CLOSE(result[0], 2.0, epsilon);
155 BOOST_CHECK_CLOSE(result[1], 10.0, epsilon);
156 BOOST_CHECK_CLOSE(result[2], 5.0, epsilon);
157}

References Nektar::eFULL, and Nektar::LinearSystem::Solve().

◆ BOOST_AUTO_TEST_CASE() [3/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestFullSystemWithWrappedVectors  )

Definition at line 254 of file testLinearSystem.cpp.

255{
256 // Larger matrix.
257 double matrix_buf[] = {
258 -85, -55, -37, -35, 97, 50, 79, 56, 49, 63, 57, -59, 45,
259 -8, -93, 92, 43, -62, 77, 66, 54, -5, 99, -61, -50, -12,
260 -18, 31, -26, -62, 1, -47, -91, -47, -61, 41, -58, -90, 53,
261 -1, 94, 83, -86, 23, -84, 19, -50, 88, -53, 85, 49, 78,
262 17, 72, -99, -85, -86, 30, 80, 72, 66, -29, -91, -53, -19,
263 -47, 68, -72, -87, 79, 43, -66, -53, -61, -23, -37, 31, -34,
264 -42, 88, -76, -65, 25, 28, -61, -60, 9, 29, -66, -32, 78,
265 39, 94, 68, -17, -98, -36, 40, 22, 5};
266
267 double b_buf[] = {12719, -3169, -16810, 7408, -14945,
268 -6822, 10166, 7023, 8679, -11826};
269 double result_buf[10] = {0};
270
271 std::shared_ptr<NekMatrix<double>> A(
272 new NekMatrix<double>(10, 10, matrix_buf, eFULL));
273 std::shared_ptr<NekVector<double>> b(
274 new NekVector<double>(Array<OneD, double>(10, b_buf), eWrapper));
275 NekVector<double> result(Array<OneD, double>(10, result_buf), eWrapper);
276
277 LinearSystem linsys(A);
278
279 linsys.SolveTranspose(b, result);
280 double epsilon = 1e-11;
281 BOOST_CHECK_CLOSE(result[0], -88.0, epsilon);
282 BOOST_CHECK_CLOSE(result[1], -43.0, epsilon);
283 BOOST_CHECK_CLOSE(result[2], -73.0, epsilon);
284 BOOST_CHECK_CLOSE(result[3], 25.0, epsilon);
285 BOOST_CHECK_CLOSE(result[4], 4.0, epsilon);
286 BOOST_CHECK_CLOSE(result[5], -59.0, epsilon);
287 BOOST_CHECK_CLOSE(result[6], 62.0, epsilon);
288 BOOST_CHECK_CLOSE(result[7], -55.0, epsilon);
289 BOOST_CHECK_CLOSE(result[8], 25.0, epsilon);
290 BOOST_CHECK_CLOSE(result[9], 9.0, epsilon);
291}

References Nektar::eFULL, Nektar::eWrapper, and Nektar::LinearSystem::SolveTranspose().

◆ BOOST_AUTO_TEST_CASE() [4/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestLargeFullSystem  )

Definition at line 182 of file testLinearSystem.cpp.

183{
184
185 // Larger matrix.
186 double matrix_buf[] = {
187 -85, -55, -37, -35, 97, 50, 79, 56, 49, 63, 57, -59, 45,
188 -8, -93, 92, 43, -62, 77, 66, 54, -5, 99, -61, -50, -12,
189 -18, 31, -26, -62, 1, -47, -91, -47, -61, 41, -58, -90, 53,
190 -1, 94, 83, -86, 23, -84, 19, -50, 88, -53, 85, 49, 78,
191 17, 72, -99, -85, -86, 30, 80, 72, 66, -29, -91, -53, -19,
192 -47, 68, -72, -87, 79, 43, -66, -53, -61, -23, -37, 31, -34,
193 -42, 88, -76, -65, 25, 28, -61, -60, 9, 29, -66, -32, 78,
194 39, 94, 68, -17, -98, -36, 40, 22, 5};
195
196 double b_buf[] = {12719, -3169, -16810, 7408, -14945,
197 -6822, 10166, 7023, 8679, -11826};
198
199 std::shared_ptr<NekMatrix<double>> A(
200 new NekMatrix<double>(10, 10, matrix_buf, eFULL));
201 std::shared_ptr<NekVector<double>> b(new NekVector<double>(10, b_buf));
202 LinearSystem linsys(A);
203
204 NekVector<double> result = linsys.SolveTranspose(b);
205 double epsilon = 1e-11;
206 BOOST_CHECK_CLOSE(result[0], -88.0, epsilon);
207 BOOST_CHECK_CLOSE(result[1], -43.0, epsilon);
208 BOOST_CHECK_CLOSE(result[2], -73.0, epsilon);
209 BOOST_CHECK_CLOSE(result[3], 25.0, epsilon);
210 BOOST_CHECK_CLOSE(result[4], 4.0, epsilon);
211 BOOST_CHECK_CLOSE(result[5], -59.0, epsilon);
212 BOOST_CHECK_CLOSE(result[6], 62.0, epsilon);
213 BOOST_CHECK_CLOSE(result[7], -55.0, epsilon);
214 BOOST_CHECK_CLOSE(result[8], 25.0, epsilon);
215 BOOST_CHECK_CLOSE(result[9], 9.0, epsilon);
216}

References Nektar::eFULL, and Nektar::LinearSystem::SolveTranspose().

◆ BOOST_AUTO_TEST_CASE() [5/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestLinearSystemSolveWithReturnValue  )

Definition at line 41 of file testLinearSystem.cpp.

42{
43 double matrix_buf[] = {10, 5, 2};
44
45 double b_buf[] = {20, 50, 10};
46
47 std::shared_ptr<NekMatrix<double>> A(
48 new NekMatrix<double>(3, 3, matrix_buf, eDIAGONAL));
49 NekVector<double> b1(3, b_buf);
50 std::shared_ptr<NekVector<double>> b2(new NekVector<double>(3, b_buf));
51 NekVector<double> b3(3, b_buf);
52 std::shared_ptr<NekVector<double>> b4(new NekVector<double>(3, b_buf));
53
54 LinearSystem linsys(A);
55
56 NekVector<double> result1 = linsys.Solve(b1);
57 NekVector<double> result2 = linsys.Solve(b2);
58 NekVector<double> result3 = linsys.Solve(&b1);
59 NekVector<double> result4 = linsys.Solve(b2.get());
60
61 NekVector<double> result5 = linsys.Solve(b3);
62 NekVector<double> result6 = linsys.Solve(b4);
63 NekVector<double> result7 = linsys.Solve(&b3);
64 NekVector<double> result8 = linsys.Solve(b4.get());
65
66 double expected_result_buf[] = {2, 10, 5};
67 NekVector<double> expectedResult(3, expected_result_buf);
68
69 BOOST_CHECK_EQUAL(result1, expectedResult);
70 BOOST_CHECK_EQUAL(result2, expectedResult);
71 BOOST_CHECK_EQUAL(result3, expectedResult);
72 BOOST_CHECK_EQUAL(result4, expectedResult);
73 BOOST_CHECK_EQUAL(result5, expectedResult);
74 BOOST_CHECK_EQUAL(result6, expectedResult);
75 BOOST_CHECK_EQUAL(result7, expectedResult);
76 BOOST_CHECK_EQUAL(result8, expectedResult);
77}

References Nektar::eDIAGONAL, and Nektar::LinearSystem::Solve().

◆ BOOST_AUTO_TEST_CASE() [6/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestLinearSystemSolveWithSoluationAsParameter  )

Definition at line 79 of file testLinearSystem.cpp.

80{
81 double matrix_buf[] = {10, 5, 2};
82
83 double b_buf[] = {20, 50, 10};
84
85 std::shared_ptr<NekMatrix<double>> A(
86 new NekMatrix<double>(3, 3, matrix_buf, eDIAGONAL));
87 NekVector<double> b1(3, b_buf);
88 std::shared_ptr<NekVector<double>> b2(new NekVector<double>(3, b_buf));
89 NekVector<double> b3(3, b_buf);
90 std::shared_ptr<NekVector<double>> b4(new NekVector<double>(3, b_buf));
91
92 NekVector<double> result1(3, 0.0);
93 std::shared_ptr<NekVector<double>> result2(new NekVector<double>(3, 0.0));
94 NekVector<double> result3(3, 0.0);
95 std::shared_ptr<NekVector<double>> result4(new NekVector<double>(3, 0.0));
96
97 LinearSystem linsys(A);
98 double expected_result_buf[] = {2, 10, 5};
99 NekVector<double> expectedResult(3, expected_result_buf);
100
101 linsys.Solve(b1, result1);
102 linsys.Solve(b2, result3);
103 linsys.Solve(b3, result4);
104 linsys.Solve(b4, result2);
105
106 BOOST_CHECK_EQUAL(result1, expectedResult);
107 BOOST_CHECK_EQUAL(*result2, expectedResult);
108 BOOST_CHECK_EQUAL(result3, expectedResult);
109 BOOST_CHECK_EQUAL(*result4, expectedResult);
110}

References Nektar::eDIAGONAL, and Nektar::LinearSystem::Solve().

◆ BOOST_AUTO_TEST_CASE() [7/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestSmallFullSystem  )

Definition at line 159 of file testLinearSystem.cpp.

160{
161
162 double matrix_buf[] = {81, -5, -28, 4};
163
164 double b_buf[] = {-941, 348};
165
166 std::shared_ptr<NekMatrix<double>> A(
167 new NekMatrix<double>(2, 2, matrix_buf, eFULL));
168 std::shared_ptr<NekVector<double>> b(new NekVector<double>(2, b_buf));
169 LinearSystem linsys(A);
170
171 NekVector<double> result = linsys.Solve(b);
172 double epsilon = 1e-11;
173
174 BOOST_CHECK_CLOSE(result[0], 32.5, epsilon);
175 BOOST_CHECK_CLOSE(result[1], 127.625, epsilon);
176
177 result = linsys.SolveTranspose(b);
178 BOOST_CHECK_CLOSE(result[0], -11.0, epsilon);
179 BOOST_CHECK_CLOSE(result[1], 10.0, epsilon);
180}

References Nektar::eFULL, Nektar::LinearSystem::Solve(), and Nektar::LinearSystem::SolveTranspose().

◆ BOOST_AUTO_TEST_CASE() [8/8]

Nektar::LinearSystemUnitTests::BOOST_AUTO_TEST_CASE ( TestSymmetricMatrix  )

Definition at line 293 of file testLinearSystem.cpp.

294{
296 m.SetValue(0, 0, 3.0);
297 m.SetValue(0, 1, 4.0);
298 m.SetValue(0, 2, 9);
299 m.SetValue(1, 1, 7);
300 m.SetValue(1, 2, 2);
301 m.SetValue(2, 2, 11);
302
303 BOOST_CHECK_EQUAL(4.0, m(1, 0));
304
305 double b_buf[] = {-20.0, 30.0, -20.0};
306 NekVector<double> b(3, b_buf);
307
308 LinearSystem linsys(m);
309 NekVector<double> x = linsys.Solve(b);
310 NekVector<double> xt = linsys.SolveTranspose(b);
311
312 double epsilon = 1e-11;
313 BOOST_CHECK_CLOSE(x[0], 3.0, epsilon);
314 BOOST_CHECK_CLOSE(x[1], 4.0, epsilon);
315 BOOST_CHECK_CLOSE(x[2], -5.0, epsilon);
316 BOOST_CHECK_CLOSE(xt[0], 3.0, epsilon);
317 BOOST_CHECK_CLOSE(xt[1], 4.0, epsilon);
318 BOOST_CHECK_CLOSE(xt[2], -5.0, epsilon);
319}

References Nektar::eSYMMETRIC, Nektar::LinearSystem::Solve(), and Nektar::LinearSystem::SolveTranspose().