]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test case
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Thu, 9 Mar 2023 14:15:01 +0000 (15:15 +0100)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Tue, 14 Mar 2023 13:17:16 +0000 (14:17 +0100)
tests/lapack/full_matrix_38.cc [new file with mode: 0644]
tests/lapack/full_matrix_38.output [new file with mode: 0644]

diff --git a/tests/lapack/full_matrix_38.cc b/tests/lapack/full_matrix_38.cc
new file mode 100644 (file)
index 0000000..2475522
--- /dev/null
@@ -0,0 +1,82 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2023 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Tests eigenvectors of LAPACKFullMatrix
+
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/lapack_full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <iostream>
+
+#include "../tests.h"
+
+/*
+ * Eigenvalues and -vectors of this system are
+ * lambda = 3     v = (0.707,  0.707)
+ * lambda = 5     v = (0.707, -0.707)
+ */
+const double mat1[2][2] = {{4., -1.}, {-1., 4.}};
+
+/*
+ * Eigenvalues and -vectors of this system are
+ * lambda = 1+1i     v = (0.707, -0.707i)
+ * lambda = 1-1i     v = (0.707,  0.707i)
+ */
+const double mat2[2][2] = {{1., -1.}, {1., 1.}};
+
+
+void
+check_matrix(const double *matrix_pointer)
+{
+  FullMatrix<double>       A(2, 2, matrix_pointer);
+  LAPACKFullMatrix<double> LA(2, 2);
+  LA = A;
+
+  deallog << "Checking matrix " << std::endl;
+  LA.print_formatted(deallog.get_file_stream());
+
+  LA.compute_eigenvalues(true, true);
+  deallog << "Eigenvalues: ";
+  for (unsigned int i = 0; i < A.m(); ++i)
+    {
+      std::complex<double> lambda = LA.eigenvalue(i);
+      deallog << lambda << " ";
+    }
+  deallog << std::endl;
+  deallog << "Right eigenvectors ";
+  for (const auto d : LA.get_right_eigenvectors())
+    deallog << d << " ";
+  deallog << std::endl;
+  deallog << "Left eigenvectors ";
+  for (const auto d : LA.get_left_eigenvectors())
+    deallog << d << " ";
+  deallog << std::endl;
+}
+
+
+
+int
+main()
+{
+  initlog();
+
+  // Test symmetric system
+  check_matrix(&mat1[0][0]);
+
+  // Test non-symmetric system with complex eigenvalues/eigenvectors
+  check_matrix(&mat2[0][0]);
+}
diff --git a/tests/lapack/full_matrix_38.output b/tests/lapack/full_matrix_38.output
new file mode 100644 (file)
index 0000000..1dd51a2
--- /dev/null
@@ -0,0 +1,13 @@
+
+DEAL::Checking matrix 
+4.000e+00  -1.000e+00 
+-1.000e+00 4.000e+00  
+DEAL::Eigenvalues: (5.00000,0.00000) (3.00000,0.00000) 
+DEAL::Right eigenvectors 0.707107 -0.707107 0.707107 0.707107 
+DEAL::Left eigenvectors 0.707107 -0.707107 0.707107 0.707107 
+DEAL::Checking matrix 
+1.000e+00  -1.000e+00 
+1.000e+00  1.000e+00  
+DEAL::Eigenvalues: (1.00000,1.00000) (1.00000,-1.00000) 
+DEAL::Right eigenvectors 0.707107 0.00000 0.00000 -0.707107 
+DEAL::Left eigenvectors -0.707107 0.00000 0.00000 0.707107 

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.