############################################################
tests_x = vector-vector \
- full_matrix householder tridiagonal_matrix \
+ full_matrix householder \
+ tridiagonal_matrix tridiagonal_matrix_sym \
sparsity_pattern sparse_matrices matrices \
block_sparsity_pattern_01 \
block_vector block_vector_* block_matrices \
//
//---------------------------------------------------------------------------
+// Tests TridiagonalMatrix::all_zero
+// Tests TridiagonalMatrix::matrix_scalar_product
+// Tests TridiagonalMatrix::vmult
+// Tests TridiagonalMatrix::Tvmult
+// Tests TridiagonalMatrix::vmult_add
+// Tests TridiagonalMatrix::Tvmult_add
+// Tests TridiagonalMatrix::print
+
#include "../tests.h"
#include <base/logstream.h>
const unsigned int n = M.n();
Vector<number> u(n);
Vector<number> v(n);
+ Vector<number> w(n);
for (unsigned int i=0;i<n;++i)
u(i) = 1 << i;
-
+
+ deallog << "u ";
for (unsigned int i=0;i<u.size();++i)
deallog << ' ' << std::setw(6) << u(i);
deallog << std::endl;
M.vmult(v,u);
+
+ deallog << "u^TMw ";
+ for (unsigned int i=0;i<w.size();++i)
+ {
+ w = 0.;
+ w(i) = 2.;
+// number p1 = v*w;
+ number p2 = M.matrix_scalar_product(u,w);
+ deallog << ' ' << std::setw(6) << p2;
+ }
+ deallog << std::endl;
+
+ deallog << "vmult ";
for (unsigned int i=0;i<v.size();++i)
deallog << ' ' << std::setw(6) << v(i);
deallog << std::endl;
- M.vmult_add(v,u);
+ M.Tvmult_add(v,u);
+ deallog << "+Tvm ";
for (unsigned int i=0;i<v.size();++i)
deallog << ' ' << std::setw(6) << v(i);
deallog << std::endl;
M.Tvmult(v,u);
+ deallog << "Tvmult";
for (unsigned int i=0;i<v.size();++i)
deallog << ' ' << std::setw(6) << v(i);
deallog << std::endl;
- M.Tvmult_add(v,u);
+ M.vmult_add(v,u);
+ deallog << "+vm ";
for (unsigned int i=0;i<v.size();++i)
deallog << ' ' << std::setw(6) << v(i);
deallog << std::endl;
check(unsigned int size)
{
TridiagonalMatrix<number>M(size);
+ deallog << "all_zero " << M.all_zero();
matrix1(M);
+ deallog << " " << M.all_zero() << std::endl;
deallog << "Matrix [-1,2,-1]" << std::endl;
M.print(deallog, 7, 0);
check_vmult(M);
+DEAL::all_zero 1 0
DEAL::Matrix [-1,2,-1]
DEAL:: 2. -1.
DEAL::-1. 2. -1.
DEAL::-1. 2. -1.
DEAL::-1. 2. -1.
DEAL::-1. 2.
-DEAL:: 1. 2. 4. 8. 16.
-DEAL:: 0 -1. -2. -4. 24.
-DEAL:: 0 -2. -4. -8. 48.
-DEAL:: 0 -1. -2. -4. 24.
-DEAL:: 0 -2. -4. -8. 48.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw 0 -2. -4. -8. 48.
+DEAL::vmult 0 -1. -2. -4. 24.
+DEAL::+Tvm 0 -2. -4. -8. 48.
+DEAL::Tvmult 0 -1. -2. -4. 24.
+DEAL::+vm 0 -2. -4. -8. 48.
DEAL::Matrix [-1,2,-3]
DEAL:: 2. -3.
DEAL::-1. 2. -3.
DEAL::-1. 2. -3.
DEAL::-1. 2. -3.
DEAL::-1. 2.
-DEAL:: 1. 2. 4. 8. 16.
-DEAL:: -4. -9. -18. -36. 24.
-DEAL:: -8. -18. -36. -72. 48.
-DEAL:: 0 -3. -6. -12. 8.
-DEAL:: 0 -6. -12. -24. 16.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw 0 -6. -12. -24. 16.
+DEAL::vmult -4. -9. -18. -36. 24.
+DEAL::+Tvm -4. -12. -24. -48. 32.
+DEAL::Tvmult 0 -3. -6. -12. 8.
+DEAL::+vm -4. -12. -24. -48. 32.
DEAL::Matrix increasing symmetric rows
DEAL:: 2. -1.
DEAL::-2. 3. -2.
DEAL::-3. 4. -3.
DEAL::-4. 5. -4.
DEAL::-5. 6.
-DEAL:: 1. 2. 4. 8. 16.
-DEAL:: 0 -4. -14. -40. 56.
-DEAL:: 0 -8. -28. -80. 112.
-DEAL:: -2. -7. -20. -52. 64.
-DEAL:: -4. -14. -40. -104. 128.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw -4. -14. -40. -104. 128.
+DEAL::vmult 0 -4. -14. -40. 56.
+DEAL::+Tvm -2. -11. -34. -92. 120.
+DEAL::Tvmult -2. -7. -20. -52. 64.
+DEAL::+vm -2. -11. -34. -92. 120.
DEAL::Matrix increasing symmetric
DEAL:: 2. -1.
DEAL::-1. 3. -2.
DEAL::-2. 4. -3.
DEAL::-3. 5. -4.
DEAL::-4. 6.
-DEAL:: 1. 2. 4. 8. 16.
-DEAL:: 0 -3. -12. -36. 64.
-DEAL:: 0 -6. -24. -72. 128.
-DEAL:: 0 -3. -12. -36. 64.
-DEAL:: 0 -6. -24. -72. 128.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw 0 -6. -24. -72. 128.
+DEAL::vmult 0 -3. -12. -36. 64.
+DEAL::+Tvm 0 -6. -24. -72. 128.
+DEAL::Tvmult 0 -3. -12. -36. 64.
+DEAL::+vm 0 -6. -24. -72. 128.
DEAL::Matrix increasing nonsymmetric
DEAL:: 2. 5.
DEAL::-2. 3. 3.
DEAL::-3. 4. 1.
DEAL::-4. 5. -1.
DEAL::-5. 6.
-DEAL:: 1. 2. 4. 8. 16.
-DEAL:: 12. 16. 18. 8. 56.
-DEAL:: 24. 32. 36. 16. 112.
-DEAL:: -2. -1. -10. -36. 88.
-DEAL:: -4. -2. -20. -72. 176.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw -4. -2. -20. -72. 176.
+DEAL::vmult 12. 16. 18. 8. 56.
+DEAL::+Tvm 10. 15. 8. -28. 144.
+DEAL::Tvmult -2. -1. -10. -36. 88.
+DEAL::+vm 10. 15. 8. -28. 144.
+DEAL::all_zero 1 0
DEAL::Matrix [-1,2,-1]
DEAL:: 2. -1.
DEAL::-1. 2. -1.
DEAL::-1. 2. -1.
DEAL::-1. 2.
-DEAL:: 1. 2. 4. 8.
-DEAL:: 0. -1. -2. 12.
-DEAL:: 0. -2. -4. 24.
-DEAL:: 0. -1. -2. 12.
-DEAL:: 0. -2. -4. 24.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw 0. -2. -4. 24.
+DEAL::vmult 0. -1. -2. 12.
+DEAL::+Tvm 0. -2. -4. 24.
+DEAL::Tvmult 0. -1. -2. 12.
+DEAL::+vm 0. -2. -4. 24.
DEAL::Matrix [-1,2,-3]
DEAL:: 2. -3.
DEAL::-1. 2. -3.
DEAL::-1. 2. -3.
DEAL::-1. 2.
-DEAL:: 1. 2. 4. 8.
-DEAL:: -4. -9. -18. 12.
-DEAL:: -8. -18. -36. 24.
-DEAL:: 0. -3. -6. 4.
-DEAL:: 0. -6. -12. 8.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw 0. -6. -12. 8.
+DEAL::vmult -4. -9. -18. 12.
+DEAL::+Tvm -4. -12. -24. 16.
+DEAL::Tvmult 0. -3. -6. 4.
+DEAL::+vm -4. -12. -24. 16.
DEAL::Matrix increasing symmetric rows
DEAL:: 2. -1.
DEAL::-2. 3. -2.
DEAL::-3. 4. -3.
DEAL::-4. 5.
-DEAL:: 1. 2. 4. 8.
-DEAL:: 0. -4. -14. 24.
-DEAL:: 0. -8. -28. 48.
-DEAL:: -2. -7. -20. 28.
-DEAL:: -4. -14. -40. 56.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw -4. -14. -40. 56.
+DEAL::vmult 0. -4. -14. 24.
+DEAL::+Tvm -2. -11. -34. 52.
+DEAL::Tvmult -2. -7. -20. 28.
+DEAL::+vm -2. -11. -34. 52.
DEAL::Matrix increasing symmetric
DEAL:: 2. -1.
DEAL::-1. 3. -2.
DEAL::-2. 4. -3.
DEAL::-3. 5.
-DEAL:: 1. 2. 4. 8.
-DEAL:: 0. -3. -12. 28.
-DEAL:: 0. -6. -24. 56.
-DEAL:: 0. -3. -12. 28.
-DEAL:: 0. -6. -24. 56.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw 0. -6. -24. 56.
+DEAL::vmult 0. -3. -12. 28.
+DEAL::+Tvm 0. -6. -24. 56.
+DEAL::Tvmult 0. -3. -12. 28.
+DEAL::+vm 0. -6. -24. 56.
DEAL::Matrix increasing nonsymmetric
DEAL:: 2. 5.
DEAL::-2. 3. 3.
DEAL::-3. 4. 1.
DEAL::-4. 5.
-DEAL:: 1. 2. 4. 8.
-DEAL:: 12. 16. 18. 24.
-DEAL:: 24. 32. 36. 48.
-DEAL:: -2. -1. -10. 44.
-DEAL:: -4. -2. -20. 88.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw -4. -2. -20. 88.
+DEAL::vmult 12. 16. 18. 24.
+DEAL::+Tvm 10. 15. 8. 68.
+DEAL::Tvmult -2. -1. -10. 44.
+DEAL::+vm 10. 15. 8. 68.
--- /dev/null
+//---------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2005, 2006 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.
+//
+//---------------------------------------------------------------------------
+
+// Test for symmetric tridiagonal matrices;
+// copies part of the tests in tridiagonal_matrix.cc
+
+// Tests TridiagonalMatrix::all_zero
+// Tests TridiagonalMatrix::matrix_scalar_product
+// Tests TridiagonalMatrix::vmult
+// Tests TridiagonalMatrix::Tvmult
+// Tests TridiagonalMatrix::vmult_add
+// Tests TridiagonalMatrix::Tvmult_add
+// Tests TridiagonalMatrix::print
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/tridiagonal_matrix.h>
+#include <lac/vector.h>
+
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <cmath>
+
+
+// Symmetric matrix with constant diagonals [-1,2,-1]
+template<typename number>
+void
+matrix1(TridiagonalMatrix<number>& M)
+{
+ const unsigned int n = M.n();
+ for (unsigned int i=0;i<n;++i)
+ {
+ M(i,i) = 2.;
+ // Set both diagonals, one will
+ // override other.
+ if (i>0) M(i,i-1) = -1.;
+ if (i<n-1) M(i,i+1) = -1.;
+ }
+}
+
+
+// Symmetric matrix with increasing diagonals
+template<typename number>
+void
+matrix4(TridiagonalMatrix<number>& M)
+{
+ const unsigned int n = M.n();
+ for (unsigned int i=0;i<n;++i)
+ {
+ M(i,i) = 2.+i;
+ if (i>0) M(i,i-1) = 0.-i;
+ if (i<n-1) M(i,i+1) = -1.-i;
+ }
+}
+
+
+template<typename number>
+void
+check_vmult(TridiagonalMatrix<number>& M)
+{
+ const unsigned int n = M.n();
+ Vector<number> u(n);
+ Vector<number> v(n);
+ Vector<number> w(n);
+
+ for (unsigned int i=0;i<n;++i)
+ u(i) = 1 << i;
+
+ deallog << "u ";
+ for (unsigned int i=0;i<u.size();++i)
+ deallog << ' ' << std::setw(6) << u(i);
+ deallog << std::endl;
+
+ M.vmult(v,u);
+
+ deallog << "u^TMw ";
+ for (unsigned int i=0;i<w.size();++i)
+ {
+ w = 0.;
+ w(i) = 2.;
+// number p1 = v*w;
+ number p2 = M.matrix_scalar_product(u,w);
+ deallog << ' ' << std::setw(6) << p2;
+ }
+ deallog << std::endl;
+
+ deallog << "vmult ";
+ for (unsigned int i=0;i<v.size();++i)
+ deallog << ' ' << std::setw(6) << v(i);
+ deallog << std::endl;
+
+ M.Tvmult_add(v,u);
+ deallog << "+Tvm ";
+ for (unsigned int i=0;i<v.size();++i)
+ deallog << ' ' << std::setw(6) << v(i);
+ deallog << std::endl;
+
+ M.Tvmult(v,u);
+ deallog << "Tvmult";
+ for (unsigned int i=0;i<v.size();++i)
+ deallog << ' ' << std::setw(6) << v(i);
+ deallog << std::endl;
+
+ M.vmult_add(v,u);
+ deallog << "+vm ";
+ for (unsigned int i=0;i<v.size();++i)
+ deallog << ' ' << std::setw(6) << v(i);
+ deallog << std::endl;
+}
+
+
+template<typename number>
+void
+check(unsigned int size)
+{
+ TridiagonalMatrix<number>M(size, true);
+ deallog << "all_zero " << M.all_zero();
+ matrix1(M);
+ deallog << " " << M.all_zero() << std::endl;
+ deallog << "Matrix [-1,2,-1]" << std::endl;
+ M.print(deallog, 7, 0);
+ check_vmult(M);
+ matrix4(M);
+ deallog << "Matrix increasing symmetric" << std::endl;
+ M.print(deallog, 7, 0);
+ check_vmult(M);
+}
+
+int main()
+{
+ std::ofstream logfile("tridiagonal_matrix_sym/output");
+ logfile.setf(std::ios::fixed);
+ logfile.precision(0);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ check<double>(5);
+ check<float>(4);
+}
--- /dev/null
+
+DEAL::all_zero 1 0
+DEAL::Matrix [-1,2,-1]
+DEAL:: 2. -1.
+DEAL::-1. 2. -1.
+DEAL::-1. 2. -1.
+DEAL::-1. 2. -1.
+DEAL::-1. 2.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw 0 -2. -4. -8. 48.
+DEAL::vmult 0 -1. -2. -4. 24.
+DEAL::+Tvm 0 -2. -4. -8. 48.
+DEAL::Tvmult 0 -1. -2. -4. 24.
+DEAL::+vm 0 -2. -4. -8. 48.
+DEAL::Matrix increasing symmetric
+DEAL:: 2. -1.
+DEAL::-1. 3. -2.
+DEAL::-2. 4. -3.
+DEAL::-3. 5. -4.
+DEAL::-4. 6.
+DEAL::u 1. 2. 4. 8. 16.
+DEAL::u^TMw 0 -6. -24. -72. 128.
+DEAL::vmult 0 -3. -12. -36. 64.
+DEAL::+Tvm 0 -6. -24. -72. 128.
+DEAL::Tvmult 0 -3. -12. -36. 64.
+DEAL::+vm 0 -6. -24. -72. 128.
+DEAL::all_zero 1 0
+DEAL::Matrix [-1,2,-1]
+DEAL:: 2. -1.
+DEAL::-1. 2. -1.
+DEAL::-1. 2. -1.
+DEAL::-1. 2.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw 0. -2. -4. 24.
+DEAL::vmult 0. -1. -2. 12.
+DEAL::+Tvm 0. -2. -4. 24.
+DEAL::Tvmult 0. -1. -2. 12.
+DEAL::+vm 0. -2. -4. 24.
+DEAL::Matrix increasing symmetric
+DEAL:: 2. -1.
+DEAL::-1. 3. -2.
+DEAL::-2. 4. -3.
+DEAL::-3. 5.
+DEAL::u 1. 2. 4. 8.
+DEAL::u^TMw 0. -6. -24. 56.
+DEAL::vmult 0. -3. -12. 28.
+DEAL::+Tvm 0. -6. -24. 56.
+DEAL::Tvmult 0. -3. -12. 28.
+DEAL::+vm 0. -6. -24. 56.