Browse Source

SparseLU

master
Trevor Irons 5 years ago
parent
commit
fde3516b79
3 changed files with 38 additions and 5 deletions
  1. 9
    1
      examples/EMSchur3D-vtk.cpp
  2. 28
    3
      include/EMSchur3D.h
  3. 1
    1
      include/bicgstab.h

+ 9
- 1
examples/EMSchur3D-vtk.cpp View File

@@ -112,12 +112,20 @@ int main( int argc, char** argv ) {
112 112
 
113 113
     //////////////////////////////////////////////////
114 114
     // And solve
115
+
115 116
     // Use BiCGSTAB Diagonal preconditioner
116 117
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
117 118
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
118
-    auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
119
+
120
+    // LS CG
121
+    //auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
122
+
123
+    // CG...dangerous
119 124
     //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > >::NewSP();
125
+    //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > >::NewSP();
120 126
 
127
+    // LU direct
128
+    auto EM3D = EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::COLAMDOrdering<int> > >::NewSP();
121 129
 
122 130
     EM3D->SetRectilinearGrid( gimp->GetGrid() );
123 131
 

+ 28
- 3
include/EMSchur3D.h View File

@@ -237,8 +237,10 @@ namespace Lemma {
237 237
                 // << " in " << iter_done << " iterations"
238 238
               //<<  " with error " << errorn << "\t"
239 239
               << "\tInital solution error="<<   Error.norm()  // Iteritive info
240
-              << "\tSolver reported error="<<   CSolver[iw].error()  // Iteritive info
241
-              << "\ttime " << timer.end() / 60. << " [m]   " <<  CSolver[iw].iterations() << "  iterations" << std::endl;
240
+//              << "\tSolver reported error="<<   CSolver[iw].error()  // Iteritive info
241
+              << "\ttime " << timer.end() / 60. << " [m]   "
242
+//             <<  CSolver[iw].iterations() << "  iterations"
243
+            << std::endl;
242 244
 
243 245
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
244 246
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
@@ -393,7 +395,9 @@ namespace Lemma {
393 395
             timer.begin();
394 396
 
395 397
             CSolver[iw].isSymmetric(true);
396
-            CSolver[iw].setPivotThreshold(0.0);
398
+            //CSolver[iw].setPivotThreshold(0.0); // OK for symmetric complex systems with real and imaginary positive definite parts.
399
+            //                                  // but our imaginary part is negative definite
400
+            //http://www.ams.org/journals/mcom/1998-67-224/S0025-5718-98-00978-8/S0025-5718-98-00978-8.pdf
397 401
 
398 402
             /*  Complex system */
399 403
             std::cout << "SparseLU pattern analyzing C_" << iw << ",";
@@ -581,6 +585,27 @@ namespace Lemma {
581 585
         }
582 586
     }
583 587
 
588
+    template<>
589
+    void EMSchur3D<   Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > > ::BuildCDirectSolver() {
590
+        CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > [Omegas.size()];
591
+        for (int iw=0; iw<Omegas.size(); ++iw) {
592
+            //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
593
+            jsw_timer timer;
594
+            timer.begin();
595
+            /*  Complex system */
596
+            std::cout << "ConjugateGradient<IncompleteCholesky> pattern analyzing C_" << iw << ",";
597
+            std::cout.flush();
598
+            CSolver[iw].analyzePattern( Cvec[iw] );
599
+            std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
600
+            // factorize
601
+            timer.begin();
602
+            std::cout << "ConjugateGradient<IncompleteCholesky> factorising C_" << iw << ", ";
603
+            std::cout.flush();
604
+            CSolver[iw].factorize( Cvec[iw] );
605
+            std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
606
+        }
607
+    }
608
+
584 609
 //     template<>
585 610
 //     void EMSchur3D<   Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
586 611
 //         CSolver = new Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];

+ 1
- 1
include/bicgstab.h View File

@@ -474,7 +474,7 @@ inline VectorXcr implicitDCInvBPhi3 (const SparseMat& D, const Solver& solver,
474 474
     VectorXcr b = (ioms).asDiagonal() * (D.transpose()*Phi);
475 475
     VectorXcr y = solver.solve(b);
476 476
     //max_it = 0;
477
-    max_it = solver.iterations();
477
+    //max_it = solver.iterations();
478 478
     //errorn = solver.error();
479 479
     return  D*y;
480 480
 }

Loading…
Cancel
Save