@@ -44,7 +44,20 @@ TEST(Metis, permutation)
4444#endif
4545
4646#ifdef METIS_VERSION_5_2_1
47+ // output
48+ sofa::type::vector<int > perm (n);
49+ sofa::type::vector<int > invperm (n);
50+
51+ const auto res = METIS_NodeND (&n , xadj.data (), adj.data (), nullptr , nullptr , perm.data (),invperm.data ());
52+ EXPECT_EQ (res, METIS_OK);
53+
54+ const sofa::type::vector<int > expectedPerm
55+ { 12 , 2 , 0 , 14 , 5 , 11 , 8 , 9 , 1 , 13 , 10 , 7 , 3 , 4 , 6 };
56+ const sofa::type::vector<int > expectedInvPerm
57+ { 2 , 8 , 1 , 12 , 13 , 4 , 14 , 11 , 6 , 7 , 10 , 5 , 0 , 9 , 3 };
4758
59+ EXPECT_EQ (perm, expectedPerm);
60+ EXPECT_EQ (invperm, expectedInvPerm);
4861#endif
4962
5063}
@@ -111,9 +124,6 @@ TEST(SparseLDLSolver, MatrixFactorization)
111124 solver->init ();
112125 solver->invert (matrix);
113126
114- #ifdef METIS_VERSION_5_1_0
115-
116-
117127 auto * genericInvertData = solver->getMatrixInvertData (&matrix);
118128 EXPECT_NE (genericInvertData, nullptr );
119129
@@ -122,6 +132,7 @@ TEST(SparseLDLSolver, MatrixFactorization)
122132 EXPECT_NE (invertData, nullptr );
123133
124134 EXPECT_EQ (invertData->n , 15 );
135+ #ifdef METIS_VERSION_5_1_0
125136
126137 static const sofa::type::vector<int > expected_perm_Values {
127138 14 , 12 , 5 , 2 , 0 , 11 , 8 , 13 , 9 , 1 , 10 , 6 , 3 , 4 , 7
@@ -177,5 +188,87 @@ TEST(SparseLDLSolver, MatrixFactorization)
177188
178189#ifdef METIS_VERSION_5_2_1
179190
191+
192+
193+ static const sofa::type::vector<int > expected_perm_Values {
194+ 12 , 2 , 0 , 14 , 5 , 11 , 8 , 9 , 1 , 13 , 10 , 7 , 3 , 4 , 6
195+ };
196+ EXPECT_EQ (invertData->perm .size (), expected_perm_Values.size ());
197+ for (std::size_t i = 0 ; i < invertData->perm .size (); ++i)
198+ {
199+ EXPECT_EQ (invertData->perm [i], expected_perm_Values[i]);
200+ }
201+
202+ static const sofa::type::vector<SReal> expected_L_Values {
203+ -3.9996192364012998418654198928834e-05 , -9.9970489051262180859626360618364e-05 , -5.9991889146865234069914279979585e-05 , -3.9996192364012998418654198928834e-05 , -5.9991889146865234069914279979585e-05 , -5.5984861234244268e-11 , -9.9978484993670899e-05 , 5.5984861234244268e-11 , 1.6796698539857378e-06 , -3.1325628970804485e-17 , -5.5974788607159332e-11
204+ };
205+
206+ ASSERT_EQ (invertData->L_nnz , expected_L_Values.size ());
207+ for (int i = 0 ; i < invertData->L_nnz ; ++i)
208+ {
209+ EXPECT_FLOATINGPOINT_EQ (invertData->L_values [i], expected_L_Values[i])
210+ }
211+
212+ static const sofa::type::vector<SReal> expected_LT_Values {
213+ -3.9996192364012998419e-05 , -9.997048905126218086e-05 , -5.999188914686523407e-05 , -3.9996192364012998419e-05 , -5.999188914686523407e-05 , -5.5984861234244267715e-11 , -9.9978484993670899313e-05 , 1.67966985398573777e-06 , 5.5984861234244267715e-11 , -3.1325628970804484797e-17 , -5.5974788607159332246e-11
214+ };
215+
216+
217+ ASSERT_EQ (invertData->L_nnz , expected_LT_Values.size ());
218+ for (int i = 0 ; i < invertData->L_nnz ; ++i)
219+ {
220+ EXPECT_FLOATINGPOINT_EQ (invertData->LT_values [i], expected_LT_Values[i])
221+ }
222+
223+ static const sofa::type::vector<SReal> expected_invD_Values {
224+ 8000 , 1 , 1 , 7999.6800304610906096 , 3999.0402967383638497 , 3999.6800464571460907 , 3999.3601920641931429 , 4000 , 1 , 7999.6800304610906096 , 3999.6800464571460907 , 3999.360152090995598 , 3999.9999193790722529 , 3999.0404173018969232 , 4000
225+ };
226+
227+ for (int i = 0 ; i < invertData->n ; ++i)
228+ {
229+ EXPECT_FLOATINGPOINT_EQ (invertData->invD [i], expected_invD_Values[i])
230+ }
231+
232+ static const sofa::type::vector<int > expected_L_rowind_Values { 5 , 6 , 6 , 10 , 11 , 12 , 13 , 14 , 13 , 14 , 14 };
233+ EXPECT_EQ (invertData->L_rowind , expected_L_rowind_Values);
234+
235+ static const sofa::type::vector<int > expected_L_colptr_Values { 0 , 0 , 0 , 0 , 1 , 2 , 3 , 3 , 3 , 3 , 4 , 5 , 8 , 10 , 11 , 11 };
236+ EXPECT_EQ (invertData->L_colptr , expected_L_colptr_Values);
237+
238+ static const sofa::type::vector<int > expected_LT_rowind_Values { 3 , 4 , 5 , 9 , 10 , 11 , 11 , 12 , 11 , 12 , 13 };
239+ EXPECT_EQ (invertData->LT_rowind , expected_LT_rowind_Values);
240+
241+ static const sofa::type::vector<int > expected_LT_colptr_Values { 0 , 0 , 0 , 0 , 0 , 0 , 1 , 3 , 3 , 3 , 3 , 4 , 5 , 6 , 8 , 11 };
242+ EXPECT_EQ (invertData->LT_colptr , expected_LT_colptr_Values);
180243#endif
244+
245+ sofa::linearalgebra::FullVector<SReal> rightHandSide (15 );
246+ rightHandSide[0 ] = 1.0 ;
247+ rightHandSide[1 ] = -1.0 ;
248+ rightHandSide[2 ] = 2.0 ;
249+ rightHandSide[3 ] = 3.2 ;
250+ rightHandSide[4 ] = 1.4 ;
251+ rightHandSide[5 ] = 0.12 ;
252+ rightHandSide[6 ] = -3.11 ;
253+ rightHandSide[7 ] = 0.0 ;
254+ rightHandSide[8 ] = 1.25 ;
255+ rightHandSide[9 ] = 0.002 ;
256+ rightHandSide[10 ] = 1.0 ;
257+ rightHandSide[11 ] = 2.4 ;
258+ rightHandSide[12 ] = -0.5 ;
259+ rightHandSide[13 ] = 0.5 ;
260+ rightHandSide[14 ] = -1.2 ;
261+ sofa::linearalgebra::FullVector<SReal> x (15 );
262+
263+ solver->solve (matrix, x, rightHandSide);
264+ static const sofa::type::vector<SReal> expected_solution_values {
265+ 1 , -1 , 2 , 12799.990338154422716 , 5598.6351128962178336 , 480.38467046272677408 , -12439.999999686555384 , 0.79967843870635979542 , 4999.824036739974872 , 8 , 3999.7600804176322526 , 9599.3400940194769646 , -4000 , 3999.9999904041314949 , -9599.2320995003410644
266+ };
267+
268+ for (int i = 0 ; i < x.size (); ++i)
269+ {
270+ EXPECT_FLOATINGPOINT_EQ (x[i], expected_solution_values[i])
271+ }
272+
181273}
274+
0 commit comments