浏览代码

Optimizing solvers

master
Trevor Irons 5 年前
父节点
当前提交
232d83febd
共有 3 个文件被更改,包括 31 次插入28 次删除
  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 查看文件

116
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
116
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
117
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
117
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
118
     auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
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
     EM3D->SetRectilinearGrid( gimp->GetGrid() );
122
     EM3D->SetRectilinearGrid( gimp->GetGrid() );

+ 26
- 25
include/EMSchur3D.h 查看文件

215
 
215
 
216
         /////////////////////////////////////////
216
         /////////////////////////////////////////
217
         // Solve for RHS
217
         // Solve for RHS
218
-        CSolver[iw].setMaxIterations(10000);
218
+        //CSolver[iw].setMaxIterations(750);
219
         VectorXcr A = CSolver[iw].solve(Se);
219
         VectorXcr A = CSolver[iw].solve(Se);
220
 
220
 
221
 //         // Solve Real system instead
221
 //         // Solve Real system instead
236
         logio << "|| Div(A) || = " << ADiv.norm()
236
         logio << "|| Div(A) || = " << ADiv.norm()
237
                 // << " in " << iter_done << " iterations"
237
                 // << " in " << iter_done << " iterations"
238
               //<<  " with error " << errorn << "\t"
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
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
243
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
243
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
244
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
499
         CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
500
         CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
500
         for (int iw=0; iw<Omegas.size(); ++iw) {
501
         for (int iw=0; iw<Omegas.size(); ++iw) {
501
             Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
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
             jsw_timer timer;
505
             jsw_timer timer;
505
             timer.begin();
506
             timer.begin();
506
             /*  Complex system */
507
             /*  Complex system */
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
 //     template<>
584
 //     template<>
584
 //     void EMSchur3D<   Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
585
 //     void EMSchur3D<   Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {

+ 4
- 3
include/bicgstab.h 查看文件

473
                         int& max_it) {
473
                         int& max_it) {
474
     VectorXcr b = (ioms).asDiagonal() * (D.transpose()*Phi);
474
     VectorXcr b = (ioms).asDiagonal() * (D.transpose()*Phi);
475
     VectorXcr y = solver.solve(b);
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
     //errorn = solver.error();
478
     //errorn = solver.error();
479
     return  D*y;
479
     return  D*y;
480
 }
480
 }
639
         logio << "iteration " << std::setw(3) << iter
639
         logio << "iteration " << std::setw(3) << iter
640
               << "  errorn " << std::setw(6) << std::setprecision(4) << std::scientific << errorn
640
               << "  errorn " << std::setw(6) << std::setprecision(4) << std::scientific << errorn
641
               //<< "\timplicit iterations " << std::setw(5) << max_it1+max_it2
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
         // Check to see how progress is going
645
         // Check to see how progress is going
645
 
646
 

正在加载...
取消
保存