]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for diagonal matrix
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 27 Oct 2016 13:20:42 +0000 (15:20 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 29 Oct 2016 08:41:33 +0000 (10:41 +0200)
tests/lac/diagonal_matrix.cc [new file with mode: 0644]
tests/lac/diagonal_matrix.output [new file with mode: 0644]

diff --git a/tests/lac/diagonal_matrix.cc b/tests/lac/diagonal_matrix.cc
new file mode 100644 (file)
index 0000000..b4b4211
--- /dev/null
@@ -0,0 +1,105 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// Tests DiagonalMatrix
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/diagonal_matrix.h>
+#include <deal.II/lac/vector.h>
+
+
+
+void
+check()
+{
+  const unsigned int size = 10;
+  Vector<double> vec(size);
+  for (unsigned int i=0; i<size; ++i)
+    vec(i) = 2;
+  DiagonalMatrix<Vector<double> > mat;
+  mat.reinit(vec);
+
+  Vector<double> in (size), out(size), exact(size);
+  for (unsigned int i=0; i<size; ++i)
+    in(i) = 0.5;
+  exact = 1;
+
+  mat.vmult(out, in);
+  out -= exact;
+  deallog << "Error vmult: " << out.linfty_norm() << std::endl;
+
+  mat.Tvmult(out, in);
+  out -= exact;
+  deallog << "Error Tvmult: " << out.linfty_norm() << std::endl;
+
+  out = exact;
+  mat.vmult_add(out, in);
+  out -= exact;
+  out -= exact;
+  deallog << "Error vmult_add: " << out.linfty_norm() << std::endl;
+
+  out = exact;
+  mat.Tvmult_add(out, in);
+  out -= exact;
+  out -= exact;
+  deallog << "Error Tvmult_add: " << out.linfty_norm() << std::endl;
+
+  for (unsigned int i=0; i<size; ++i)
+    {
+      mat(i,i) = i+1;
+      in(i) = 1./mat(i,i);
+    }
+
+  mat.vmult(out, in);
+  out -= exact;
+  deallog << "Error vmult set 1: " << out.linfty_norm() << std::endl;
+
+  for (unsigned int i=0; i<size; ++i)
+    {
+      mat.get_vector()(i) = 1./(i+1);
+      in(i) = i+1;
+    }
+  mat.vmult(out, in);
+  out -= exact;
+  deallog << "Error vmult set 2: " << out.linfty_norm() << std::endl;
+
+  for (unsigned int i=0; i<size; ++i)
+    {
+      const double mat_entry =
+        const_cast<const DiagonalMatrix<Vector<double> > &>(mat)(i,i);
+      mat(i,i) = in(i);
+      in(i) = mat_entry;
+    }
+  mat.vmult(out, in);
+  out -= exact;
+  deallog << "Error vmult set 3: " << out.linfty_norm() << std::endl;
+}
+
+
+int main()
+{
+  std::ofstream logfile("output");
+  deallog << std::fixed;
+  deallog << std::setprecision(2);
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  check();
+
+  return 0;
+}
diff --git a/tests/lac/diagonal_matrix.output b/tests/lac/diagonal_matrix.output
new file mode 100644 (file)
index 0000000..97ce615
--- /dev/null
@@ -0,0 +1,8 @@
+
+DEAL::Error vmult: 0
+DEAL::Error Tvmult: 0
+DEAL::Error vmult_add: 0
+DEAL::Error Tvmult_add: 0
+DEAL::Error vmult set 1: 0
+DEAL::Error vmult set 2: 0
+DEAL::Error vmult set 3: 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.