]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
test for LU decomposition
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 1 Oct 2006 23:02:08 +0000 (23:02 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 1 Oct 2006 23:02:08 +0000 (23:02 +0000)
git-svn-id: https://svn.dealii.org/trunk@13974 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lapack/full_matrix_02.cc [new file with mode: 0644]
tests/lapack/full_matrix_02/cmp/generic [new file with mode: 0644]

diff --git a/tests/lapack/full_matrix_02.cc b/tests/lapack/full_matrix_02.cc
new file mode 100644 (file)
index 0000000..b4e478a
--- /dev/null
@@ -0,0 +1,88 @@
+//--------------------------------------------------------------------
+//    $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.
+//
+//--------------------------------------------------------------------
+
+// LAPACKFullMatrix::compute_lu_factorization
+// LAPACKFullMatrix::apply_lu_factorization
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/lapack_full_matrix.h>
+#include <lac/vector.h>
+
+#include <fstream>
+#include <iostream>
+
+
+// Fill a matrix with the values of the Hilbert matrix
+template <typename number>
+void
+hilbert (LAPACKFullMatrix<number>& M,
+        const bool nonsymmetric)
+{
+  const unsigned int n = M.n_rows();
+  for (unsigned int i=0;i<n;++i)
+    for (unsigned int j=0;j<n;++j)
+      M(i,j) = 1./(i+j+1.)
+              * (nonsymmetric
+                 ? ((i<j) ? -1. : 1.)
+                 : 1.);
+}
+
+
+// Multiply some vectors with the matrix and its transpose, then
+// compute and apply LU factorization and see if the results are equal
+// to the original vector.
+
+void
+test(const unsigned int size, const bool nonsymmetric)
+{
+  LAPACKFullMatrix<double> M(size, size);
+  hilbert(M, nonsymmetric);
+  
+  Vector<double> u(size);
+  Vector<double> v(size);
+  Vector<double> x(size);
+  Vector<double> y(size);
+  
+  for (unsigned int i=0;i<size;++i)
+    {
+      u(i) = i+2.;
+      x(i) = i+2.;
+    }
+  M.vmult(v,u);
+  M.Tvmult(y,x);
+  M.compute_lu_factorization();
+  M.apply_lu_factorization(v, false);
+  M.apply_lu_factorization(y, true);
+
+  v -= u;
+  y -= x;
+
+  deallog << v.l2_norm() << std::endl;
+  deallog << y.l2_norm() << std::endl;
+}
+
+
+int main()
+{
+  std::ofstream logfile("full_matrix_02/output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(10);
+  deallog.threshold_double(1.e-10);
+
+  test(4, false);
+  test(4, true);
+  test(5, false);
+  test(5, true);
+}
diff --git a/tests/lapack/full_matrix_02/cmp/generic b/tests/lapack/full_matrix_02/cmp/generic
new file mode 100644 (file)
index 0000000..9f7b062
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::0
+DEAL::0
+DEAL::0
+DEAL::0
+DEAL::0
+DEAL::0
+DEAL::0
+DEAL::0

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.