Trevor Irons преди 5 години
родител
ревизия
fde3516b79
променени са 3 файла, в които са добавени 38 реда и са изтрити 5 реда
  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 Целия файл

112
 
112
 
113
     //////////////////////////////////////////////////
113
     //////////////////////////////////////////////////
114
     // And solve
114
     // And solve
115
+
115
     // Use BiCGSTAB Diagonal preconditioner
116
     // Use BiCGSTAB Diagonal preconditioner
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>, Eigen::IncompleteLUT<Complex> > >::NewSP();
117
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
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
     //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > >::NewSP();
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
     EM3D->SetRectilinearGrid( gimp->GetGrid() );
130
     EM3D->SetRectilinearGrid( gimp->GetGrid() );
123
 
131
 

+ 28
- 3
include/EMSchur3D.h Целия файл

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
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
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
245
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
244
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
246
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
393
             timer.begin();
395
             timer.begin();
394
 
396
 
395
             CSolver[iw].isSymmetric(true);
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
             /*  Complex system */
402
             /*  Complex system */
399
             std::cout << "SparseLU pattern analyzing C_" << iw << ",";
403
             std::cout << "SparseLU pattern analyzing C_" << iw << ",";
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
 //     template<>
609
 //     template<>
585
 //     void EMSchur3D<   Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
610
 //     void EMSchur3D<   Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
586
 //         CSolver = new Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
611
 //         CSolver = new Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];

+ 1
- 1
include/bicgstab.h Целия файл

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;
476
     //max_it = 0;
477
-    max_it = solver.iterations();
477
+    //max_it = solver.iterations();
478
     //errorn = solver.error();
478
     //errorn = solver.error();
479
     return  D*y;
479
     return  D*y;
480
 }
480
 }

Loading…
Отказ
Запис