]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Reduce size of matrix with non-real eigenvalues to avoid trouble with roundoff.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 12 May 2014 19:35:36 +0000 (19:35 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Mon, 12 May 2014 19:35:36 +0000 (19:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@32899 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lac/gmres_eigenvalues.cc
tests/lac/gmres_eigenvalues.output

index 688190fdf4ddbab46114bc398071780ea8199195..94ff53077d49b80c1862458c325c06c46c5c9ab9 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "../tests.h"
 #include <deal.II/lac/vector.h>
-#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/lapack_full_matrix.h>
 #include <deal.II/lac/solver_gmres.h>
 #include <deal.II/lac/precondition.h>
 
 template <typename number>
 void test (unsigned int variant)
 {
-  const unsigned int n = 64;
+  const unsigned int n = variant < 3 ? 64 : 16;
   Vector<number> rhs(n), sol(n);
   rhs = 1.;
 
-  FullMatrix<number> matrix(n, n);
+  LAPACKFullMatrix<number> matrix(n, n);
 
   // put diagonal entries of different strengths. these are very challenging
   // for GMRES and will usually take a lot of iterations until the Krylov
@@ -53,7 +53,9 @@ void test (unsigned int variant)
         if (i<n-1)
           matrix(i,i+1) = 1.5+i;
         if (i<n-2)
-          matrix(i,i+2) = -0.25;
+          matrix(i,i+2) = -1.65;
+       matrix(i,n-1) = 2.;
+       matrix(n-1,i) = -2.;
       }
   else
     Assert(false, ExcMessage("Invalid variant"));
@@ -79,6 +81,21 @@ void test (unsigned int variant)
       solver_cg.solve(matrix, sol, rhs, PreconditionIdentity());
     }
 
+  if (variant == 3)
+    {
+      matrix.compute_eigenvalues();
+      std::vector<std::complex<double> > eigenvalues(n);
+      for (unsigned int i=0; i<n; ++i)
+        eigenvalues[i] = matrix.eigenvalue(i);
+
+      std::sort(eigenvalues.begin(), eigenvalues.end(),
+                internal::SolverGMRES::complex_less_pred);
+
+      deallog << "Actual eigenvalues:        ";
+      for (unsigned int i=0; i<n; ++i)
+        deallog << ' ' << eigenvalues[i];
+      deallog << std::endl;
+    }
   deallog.pop();
 }
 
index 66e5c8e5925e0732e6ed63aa12385a9c849ad11b..ff01b9bef38b8e69d12cb6454f51fb795068afc5 100644 (file)
@@ -11,6 +11,7 @@ DEAL:double:1:GMRES::Eigenvalue estimate:  (1.00,0.00) (16.0,0.00) (81.0,0.00) (
 DEAL:double:2:GMRES::Starting value 8.00
 DEAL:double:2:GMRES::Convergence step 64 value 0
 DEAL:double:2:GMRES::Eigenvalue estimate:  (-63.0,0.00) (-61.0,0.00) (-59.0,0.00) (-57.0,0.00) (-55.0,0.00) (-53.0,0.00) (-51.0,0.00) (-49.0,0.00) (-47.0,0.00) (-45.0,0.00) (-43.0,0.00) (-41.0,0.00) (-39.0,0.00) (-37.0,0.00) (-35.0,0.00) (-33.0,0.00) (-31.0,0.00) (-29.0,0.00) (-27.0,0.00) (-25.0,0.00) (-23.0,0.00) (-21.0,0.00) (-19.0,0.00) (-17.0,0.00) (-15.0,0.00) (-13.0,0.00) (-11.0,0.00) (-9.00,0.00) (-7.00,0.00) (-5.00,0.00) (-3.00,0.00) (-1.00,0.00) (2.00,0.00) (4.00,0.00) (6.00,0.00) (8.00,0.00) (10.0,0.00) (12.0,0.00) (14.0,0.00) (16.0,0.00) (18.0,0.00) (20.0,0.00) (22.0,0.00) (24.0,0.00) (26.0,0.00) (28.0,0.00) (30.0,0.00) (32.0,0.00) (34.0,0.00) (36.0,0.00) (38.0,0.00) (40.0,0.00) (42.0,0.00) (44.0,0.00) (46.0,0.00) (48.0,0.00) (50.0,0.00) (52.0,0.00) (54.0,0.00) (56.0,0.00) (58.0,0.00) (60.0,0.00) (62.0,0.00) (64.0,0.00)
-DEAL:double:3:GMRES::Starting value 8.00
-DEAL:double:3:GMRES::Convergence step 64 value 0
-DEAL:double:3:GMRES::Eigenvalue estimate:  (1.00,0.00) (2.00,0.00) (3.00,0.00) (4.00,0.00) (5.00,0.00) (6.00,0.00) (7.00,0.00) (8.01,0.00) (8.92,0.00) (10.1,-0.640) (10.1,0.640) (11.5,-1.65) (11.5,1.65) (13.2,-2.58) (13.2,2.58) (14.3,-2.78) (14.3,2.78) (15.3,-4.42) (15.3,4.42) (17.1,-5.86) (17.1,5.86) (19.0,-7.19) (19.0,7.19) (21.1,-8.46) (21.1,8.46) (23.4,-9.65) (23.4,9.65) (25.2,0.00) (25.8,-10.8) (25.8,10.8) (28.4,-11.8) (28.4,11.8) (31.2,-12.7) (31.2,12.7) (34.3,-13.4) (34.3,13.4) (37.7,-13.7) (37.7,13.7) (38.7,-2.89) (38.7,2.89) (40.4,-12.1) (40.4,12.1) (41.9,-13.9) (41.9,13.9) (45.4,-14.3) (45.4,14.3) (48.8,-14.1) (48.8,14.1) (52.2,-13.5) (52.2,13.5) (55.2,-12.4) (55.2,12.4) (57.9,-11.1) (57.9,11.1) (60.3,-9.81) (60.3,9.81) (62.8,-8.25) (62.8,8.25) (65.0,-6.22) (65.0,6.22) (66.6,-3.85) (66.6,3.85) (67.4,-1.30) (67.4,1.30)
+DEAL:double:3:GMRES::Starting value 4.00
+DEAL:double:3:GMRES::Convergence step 16 value 0
+DEAL:double:3:GMRES::Eigenvalue estimate:  (0.272,-1.14) (0.272,1.14) (1.52,-3.81) (1.52,3.81) (2.81,-3.71) (2.81,3.71) (4.50,-4.11) (4.50,4.11) (7.18,-5.38) (7.18,5.38) (10.3,-5.98) (10.3,5.98) (13.9,-5.92) (13.9,5.92) (18.5,-4.07) (18.5,4.07)
+DEAL:double:3::Actual eigenvalues:         (0.272,-1.14) (0.272,1.14) (1.52,-3.81) (1.52,3.81) (2.81,-3.71) (2.81,3.71) (4.50,-4.11) (4.50,4.11) (7.18,-5.38) (7.18,5.38) (10.3,-5.98) (10.3,5.98) (13.9,-5.92) (13.9,5.92) (18.5,-4.07) (18.5,4.07)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.