]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a regression test
authorMatthias Maier <tamiko@43-1.org>
Wed, 30 Dec 2015 17:26:48 +0000 (18:26 +0100)
committerMatthias Maier <tamiko@43-1.org>
Wed, 30 Dec 2015 17:27:13 +0000 (18:27 +0100)
tests/lac/linear_operator_08a.cc [new file with mode: 0644]
tests/lac/linear_operator_08a.with_cxx11=on.output [new file with mode: 0644]

diff --git a/tests/lac/linear_operator_08a.cc b/tests/lac/linear_operator_08a.cc
new file mode 100644 (file)
index 0000000..ff2b7b4
--- /dev/null
@@ -0,0 +1,89 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 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.
+//
+// ---------------------------------------------------------------------
+
+// Verify that Tvmult of an inverse_operator works correctly.
+
+#include "../tests.h"
+
+#include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/linear_operator.h>
+#include <deal.II/lac/packaged_operation.h>
+#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <deal.II/lac/precondition.h>
+#include <deal.II/lac/solver_cg.h>
+
+using namespace dealii;
+
+int main()
+{
+  initlog();
+
+  Vector<double> answer(2);
+  answer[0] = 0.25;
+  answer[1] = 0.25;
+
+  SparsityPattern sparsity_pattern(2, 2, 1);
+  sparsity_pattern.add(0, 0);
+  sparsity_pattern.add(1, 1);
+  sparsity_pattern.compress();
+
+  SparseMatrix<double> A(sparsity_pattern);
+  A.set(0, 0, 4.0);
+  A.set(1, 1, 4.0);
+
+  Vector<double> b(2);
+  b[0] = 1.0;
+  b[1] = 1.0;
+
+  const auto lo_A = linear_operator(A);
+
+  // As we all remember from numerical analysis class, CG will converge in
+  // at most two iterations
+  SolverControl solver_control_A (2, 1.0e-15);
+
+  SolverCG<Vector<double>> solver_A(solver_control_A);
+  PreconditionIdentity preconditioner_A;
+
+  const auto lo_A_inv = inverse_operator(lo_A, solver_A, preconditioner_A);
+  const auto lo_A_inv_t = transpose_operator(lo_A_inv);
+
+  deallog.depth_file(0);
+
+  unsigned int n_mistakes {0};
+
+  Vector<double> residual; // keep storage location to trigger bug.
+
+  for (unsigned int j = 0; j < 1000; ++j)
+    {
+      // test Tvmult:
+      residual = lo_A_inv_t * b;
+      residual -= answer;
+      if (residual.l2_norm() > 1e-10)
+          ++n_mistakes;
+
+      // test Tvmult_add:
+      residual = lo_A_inv_t * b - answer;
+      if (residual.l2_norm() > 1e-10)
+          ++n_mistakes;
+    }
+
+  deallog.depth_file(3);
+
+  deallog << "number of mistakes: " << n_mistakes << std::endl;
+  if (n_mistakes != 0)
+    deallog << "Ooops!" << std::endl;
+}
diff --git a/tests/lac/linear_operator_08a.with_cxx11=on.output b/tests/lac/linear_operator_08a.with_cxx11=on.output
new file mode 100644 (file)
index 0000000..9694fcb
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::number of mistakes: 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.