Sfoglia il codice sorgente

Optimizing solvers

master
Trevor Irons 6 anni fa
parent
commit
232d83febd
3 ha cambiato i file con 31 aggiunte e 28 eliminazioni
  1. 1
    0
      examples/EMSchur3D-vtk.cpp
  2. 26
    25
      include/EMSchur3D.h
  3. 4
    3
      include/bicgstab.h

+ 1
- 0
examples/EMSchur3D-vtk.cpp Vedi File

@@ -116,6 +116,7 @@ int main( int argc, char** argv ) {
116 116
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
117 117
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
118 118
     auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
119
+    //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > >::NewSP();
119 120
 
120 121
 
121 122
     EM3D->SetRectilinearGrid( gimp->GetGrid() );

+ 26
- 25
include/EMSchur3D.h Vedi File

@@ -215,7 +215,7 @@ namespace Lemma {
215 215
 
216 216
         /////////////////////////////////////////
217 217
         // Solve for RHS
218
-        CSolver[iw].setMaxIterations(10000);
218
+        //CSolver[iw].setMaxIterations(750);
219 219
         VectorXcr A = CSolver[iw].solve(Se);
220 220
 
221 221
 //         // Solve Real system instead
@@ -236,8 +236,9 @@ namespace Lemma {
236 236
         logio << "|| Div(A) || = " << ADiv.norm()
237 237
                 // << " in " << iter_done << " iterations"
238 238
               //<<  " with error " << errorn << "\t"
239
-              << "\tInital solution error "<<   Error.norm()  // Iteritive info
240
-              << "\ttime " << timer.end() / 60. << " [m]" << std::endl;
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;
241 242
 
242 243
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
243 244
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
@@ -499,8 +500,8 @@ namespace Lemma {
499 500
         CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
500 501
         for (int iw=0; iw<Omegas.size(); ++iw) {
501 502
             Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
502
-            CSolver[iw].preconditioner().setDroptol(1e-12);
503
-            CSolver[iw].preconditioner().setFillfactor(1e2);
503
+            CSolver[iw].preconditioner().setDroptol(1e-12);      // 1e-12
504
+            CSolver[iw].preconditioner().setFillfactor(1e1);     // 1e2
504 505
             jsw_timer timer;
505 506
             timer.begin();
506 507
             /*  Complex system */
@@ -559,26 +560,26 @@ namespace Lemma {
559 560
         }
560 561
     }
561 562
 
562
-//     template<>
563
-//     void EMSchur3D<   Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
564
-//         CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
565
-//         for (int iw=0; iw<Omegas.size(); ++iw) {
566
-//             //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
567
-//             jsw_timer timer;
568
-//             timer.begin();
569
-//             /*  Complex system */
570
-//             std::cout << "ConjugateGradient pattern analyzing C_" << iw << ",";
571
-//             std::cout.flush();
572
-//             CSolver[iw].analyzePattern( Cvec[iw] );
573
-//             std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
574
-//             // factorize
575
-//             timer.begin();
576
-//             std::cout << "ConjugateGradient factorising C_" << iw << ", ";
577
-//             std::cout.flush();
578
-//             CSolver[iw].factorize( Cvec[iw] );
579
-//             std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
580
-//         }
581
-//     }
563
+    template<>
564
+    void EMSchur3D<   Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
565
+        CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
566
+        for (int iw=0; iw<Omegas.size(); ++iw) {
567
+            //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
568
+            jsw_timer timer;
569
+            timer.begin();
570
+            /*  Complex system */
571
+            std::cout << "ConjugateGradient pattern analyzing C_" << iw << ",";
572
+            std::cout.flush();
573
+            CSolver[iw].analyzePattern( Cvec[iw] );
574
+            std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
575
+            // factorize
576
+            timer.begin();
577
+            std::cout << "ConjugateGradient factorising C_" << iw << ", ";
578
+            std::cout.flush();
579
+            CSolver[iw].factorize( Cvec[iw] );
580
+            std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
581
+        }
582
+    }
582 583
 
583 584
 //     template<>
584 585
 //     void EMSchur3D<   Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {

+ 4
- 3
include/bicgstab.h Vedi File

@@ -473,8 +473,8 @@ inline VectorXcr implicitDCInvBPhi3 (const SparseMat& D, const Solver& solver,
473 473
                         int& max_it) {
474 474
     VectorXcr b = (ioms).asDiagonal() * (D.transpose()*Phi);
475 475
     VectorXcr y = solver.solve(b);
476
-    max_it = 0;
477
-    //max_it = solver.iterations();
476
+    //max_it = 0;
477
+    max_it = solver.iterations();
478 478
     //errorn = solver.error();
479 479
     return  D*y;
480 480
 }
@@ -639,7 +639,8 @@ int implicitbicgstab(//const SparseMat& D,
639 639
         logio << "iteration " << std::setw(3) << iter
640 640
               << "  errorn " << std::setw(6) << std::setprecision(4) << std::scientific << errorn
641 641
               //<< "\timplicit iterations " << std::setw(5) << max_it1+max_it2
642
-              << "  time " << std::setw(6) << std::fixed << std::setprecision(2) << timer.end() << std::endl;
642
+              << "  time " << std::setw(6) << std::fixed << std::setprecision(2) << timer.end()/60. << " [m]  "
643
+              << max_it2+max_it2 << " iterations " << std::endl;
643 644
 
644 645
         // Check to see how progress is going
645 646
 

Loading…
Annulla
Salva