From: Martin Kronbichler Date: Thu, 9 Mar 2023 14:15:01 +0000 (+0100) Subject: Add test case X-Git-Tag: v9.5.0-rc1~474^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=853db3e1a0771da2ea618cb04f27a6c23a564509;p=dealii.git Add test case --- diff --git a/tests/lapack/full_matrix_38.cc b/tests/lapack/full_matrix_38.cc new file mode 100644 index 0000000000..2475522972 --- /dev/null +++ b/tests/lapack/full_matrix_38.cc @@ -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 +#include +#include + +#include + +#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 A(2, 2, matrix_pointer); + LAPACKFullMatrix 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 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 index 0000000000..1dd51a200a --- /dev/null +++ b/tests/lapack/full_matrix_38.output @@ -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