From 92edfea939d0dea879159f52ea85ec028e7282de Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Sun, 7 Nov 2010 23:11:47 +0000 Subject: [PATCH] some restructuring and test for SVD git-svn-id: https://svn.dealii.org/trunk@22629 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/lapack/full_matrix_01.cc | 50 ++++--- tests/lapack/full_matrix_01/cmp/generic | 20 ++- tests/lapack/full_matrix_02.cc | 5 +- tests/lapack/full_matrix_03.cc | 136 ++++++++++++++++++ tests/lapack/full_matrix_03/cmp/generic | 20 +++ tests/lapack/full_matrix_04.cc | 124 ++++++++++++++++ tests/lapack/full_matrix_04/cmp/generic | 16 +++ .../full_matrix_04/full_matrix_03/cmp/generic | 20 +++ tests/lapack/solver_cg/cmp/generic | 4 +- tests/lapack/tridiagonal_ev1.cc | 7 +- 10 files changed, 367 insertions(+), 35 deletions(-) create mode 100644 tests/lapack/full_matrix_03.cc create mode 100644 tests/lapack/full_matrix_03/cmp/generic create mode 100644 tests/lapack/full_matrix_04.cc create mode 100644 tests/lapack/full_matrix_04/cmp/generic create mode 100644 tests/lapack/full_matrix_04/full_matrix_03/cmp/generic diff --git a/tests/lapack/full_matrix_01.cc b/tests/lapack/full_matrix_01.cc index 8798bfd599..56467c6559 100644 --- a/tests/lapack/full_matrix_01.cc +++ b/tests/lapack/full_matrix_01.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2005, 2006 by the deal.II authors +// Copyright (C) 2005, 2006, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -45,30 +45,23 @@ const double rect[] = }; -int main() +void test_rect(unsigned int m, unsigned int n, const double* values) { - std::ofstream logfile("full_matrix_01/output"); - logfile.precision(3); - deallog.attach(logfile); - deallog.depth_console(0); - deallog.threshold_double(1.e-10); - - FullMatrix A(3,4,rect); - LAPACKFullMatrix LA(3,4); + std::ostringstream prefix; + prefix << m << 'x' << n; + deallog.push(prefix.str()); + + FullMatrix A(m,n,values); + LAPACKFullMatrix LA(m,n); LA = A; - Vector u(4); - Vector v1(3); - Vector v2(3); + Vector u(n); + Vector v1(m); + Vector v2(m); for (unsigned int i=0;i&) ok" << std::endl; A.vmult(v1,u); @@ -97,10 +90,24 @@ int main() deallog << "Tvmult_add ok" << std::endl; deallog.pop(); +} + +int main() +{ + const std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output"); + std::ofstream logfile(logname.c_str()); + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test_rect(3,4,rect); + test_rect(4,3,rect); + test_rect(4,4,symm); // Test symmetric system - A.reinit(4,4); - LA.reinit(4,4); + FullMatrix A(4,4,symm); + LAPACKFullMatrix LA(4,4); A.fill(symm); LA = A; LA.compute_eigenvalues(); @@ -111,7 +118,4 @@ int main() << (int) (lambda.real()+.0001) << '\t' << (int) (lambda.imag()+.0001) << std::endl; } - - v1.reinit(4); - v2.reinit(4); } diff --git a/tests/lapack/full_matrix_01/cmp/generic b/tests/lapack/full_matrix_01/cmp/generic index c8eede55a5..90b8cf7560 100644 --- a/tests/lapack/full_matrix_01/cmp/generic +++ b/tests/lapack/full_matrix_01/cmp/generic @@ -1,9 +1,19 @@ -DEAL:Rect::operator= (const FullMatrix&) ok -DEAL:Rect::vmult ok -DEAL:Rect::vmult_add ok -DEAL:Rect::Tvmult ok -DEAL:Rect::Tvmult_add ok +DEAL:3x4::operator= (const FullMatrix&) ok +DEAL:3x4::vmult ok +DEAL:3x4::vmult_add ok +DEAL:3x4::Tvmult ok +DEAL:3x4::Tvmult_add ok +DEAL:4x3::operator= (const FullMatrix&) ok +DEAL:4x3::vmult ok +DEAL:4x3::vmult_add ok +DEAL:4x3::Tvmult ok +DEAL:4x3::Tvmult_add ok +DEAL:4x4::operator= (const FullMatrix&) ok +DEAL:4x4::vmult ok +DEAL:4x4::vmult_add ok +DEAL:4x4::Tvmult ok +DEAL:4x4::Tvmult_add ok DEAL::Eigenvalues 5 0 DEAL::Eigenvalues 1 0 DEAL::Eigenvalues 5 0 diff --git a/tests/lapack/full_matrix_02.cc b/tests/lapack/full_matrix_02.cc index cd450766c1..7777f271e9 100644 --- a/tests/lapack/full_matrix_02.cc +++ b/tests/lapack/full_matrix_02.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2005, 2006 by the deal.II authors +// Copyright (C) 2005, 2006, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -75,7 +75,8 @@ test(const unsigned int size, const bool nonsymmetric) int main() { - std::ofstream logfile("full_matrix_02/output"); + const std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output"); + std::ofstream logfile(logname.c_str()); logfile.precision(3); deallog.attach(logfile); deallog.depth_console(0); diff --git a/tests/lapack/full_matrix_03.cc b/tests/lapack/full_matrix_03.cc new file mode 100644 index 0000000000..4d6498b84f --- /dev/null +++ b/tests/lapack/full_matrix_03.cc @@ -0,0 +1,136 @@ +//-------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005, 2006, 2010 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//-------------------------------------------------------------------- + +// Tests SVD of LAPACKFullMatrix by comparing to vmult of FullMatrix + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include + +/* + * Eigenvalues and -vectors of this system are + * lambda = 1 v = (1, 1, 1, 1) + * lambda = 5 v = (1,-1, 0, 0) + * lambda = 5 v = (0, 1,-1, 0) + * lambda = 5 v = (0, 0, 1,-1) + */ +const double symm[] = +{ + 4., -1., -1., -1., + -1., 4., -1., -1., + -1., -1., 4., -1., + -1., -1., -1., 4. +}; + +const double rect[] = +{ + 4., 3., 2., 1., + 5., 8., 1., -2., + 11., 13., -4., -5 +}; + + +void test_rect(unsigned int m, unsigned int n, const double* values) +{ + std::ostringstream prefix; + prefix << m << 'x' << n; + deallog.push(prefix.str()); + + FullMatrix A(m,n,values); + LAPACKFullMatrix LA(m,n); + LA = A; + LA.compute_svd(); + + deallog << "Singular values"; + for (unsigned int i=0;i u(n); + Vector v1(m); + Vector v2(m); + + for (unsigned int i=0;i A(4,4,symm); + LAPACKFullMatrix LA(4,4); + A.fill(symm); + LA = A; + LA.compute_eigenvalues(); + for (unsigned int i=0;i lambda = LA.eigenvalue(i); + deallog << "Eigenvalues " + << (int) (lambda.real()+.0001) << '\t' + << (int) (lambda.imag()+.0001) << std::endl; + } +} diff --git a/tests/lapack/full_matrix_03/cmp/generic b/tests/lapack/full_matrix_03/cmp/generic new file mode 100644 index 0000000000..57ea1fd12f --- /dev/null +++ b/tests/lapack/full_matrix_03/cmp/generic @@ -0,0 +1,20 @@ + +DEAL:4x4::Singular values 5.00000 5.00000 5.00000 1.00000 +DEAL:4x4::vmult ok +DEAL:4x4::vmult_add ok +DEAL:4x4::Tvmult ok +DEAL:4x4::Tvmult_add ok +DEAL:4x3::Singular values 16.0315 12.6623 6.13650 0 +DEAL:4x3::vmult ok +DEAL:4x3::vmult_add ok +DEAL:4x3::Tvmult ok +DEAL:4x3::Tvmult_add ok +DEAL:3x4::Singular values 20.7967 4.30713 1.98624 +DEAL:3x4::vmult ok +DEAL:3x4::vmult_add ok +DEAL:3x4::Tvmult ok +DEAL:3x4::Tvmult_add ok +DEAL::Eigenvalues 5 0 +DEAL::Eigenvalues 1 0 +DEAL::Eigenvalues 5 0 +DEAL::Eigenvalues 5 0 diff --git a/tests/lapack/full_matrix_04.cc b/tests/lapack/full_matrix_04.cc new file mode 100644 index 0000000000..0595e6b01c --- /dev/null +++ b/tests/lapack/full_matrix_04.cc @@ -0,0 +1,124 @@ +//-------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005, 2006, 2010 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//-------------------------------------------------------------------- + +// Tests inverse SVD of LAPACKFullMatrix by comparing to vmult of FullMatrix + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include + +/* + * Eigenvalues and -vectors of this system are + * lambda = 1 v = (1, 1, 1, 1) + * lambda = 5 v = (1,-1, 0, 0) + * lambda = 5 v = (0, 1,-1, 0) + * lambda = 5 v = (0, 0, 1,-1) + */ +const double symm[] = +{ + 4., -1., -1., -1., + -1., 4., -1., -1., + -1., -1., 4., -1., + -1., -1., -1., 4. +}; + +const double rect[] = +{ + 4., 3., 2., 1., + 5., 8., 1., -2., + 11., 13., -4., -5 +}; + + +void test_rect(unsigned int m, unsigned int n, const double* values) +{ + std::ostringstream prefix; + prefix << m << 'x' << n; + deallog.push(prefix.str()); + + FullMatrix A(m,n,values); + LAPACKFullMatrix LA(m,n); + LA = A; + LA.compute_inverse_svd(); + + deallog << "Singular values"; + for (unsigned int i=0;i u1(n); + Vector u2(n); + Vector v1(m); + Vector v2(m); + + for (unsigned int i=0;i