]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add new test for general (non-diagonal matrix) interface of Chebyshev
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 27 Oct 2016 13:22:05 +0000 (15:22 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 29 Oct 2016 08:41:47 +0000 (10:41 +0200)
tests/lac/precondition_chebyshev_02.cc [new file with mode: 0644]
tests/lac/precondition_chebyshev_02.with_lapack=true.output [new file with mode: 0644]

diff --git a/tests/lac/precondition_chebyshev_02.cc b/tests/lac/precondition_chebyshev_02.cc
new file mode 100644 (file)
index 0000000..9fc63c1
--- /dev/null
@@ -0,0 +1,137 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Similar to precondition_chebyshev_01 but using a separate preconditioner
+// class for providing the inverse diagonal that goes through another code
+// path in PreconditionChebyshev
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/precondition.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <cmath>
+
+
+class DiagonalMatrixManual
+{
+public:
+  DiagonalMatrixManual() {}
+
+  void set_vector_one (const unsigned int size)
+  {
+    diagonal.reinit(size);
+    diagonal = 1;
+  }
+
+  void reinit (const FullMatrix<double> f)
+  {
+    diagonal.reinit(f.m());
+    for (unsigned int i=0; i<f.m(); ++i)
+      diagonal(i) = 1./f(i,i);
+    diagonal.print(deallog);
+  }
+
+  typename Vector<double>::size_type m() const
+  {
+    return diagonal.size();
+  }
+
+  void vmult(Vector<double> &dst, const Vector<double> &src) const
+  {
+    dst = src;
+    dst.scale(diagonal);
+  }
+
+private:
+  Vector<double> diagonal;
+};
+
+
+void
+check()
+{
+  const unsigned int size = 10;
+  FullMatrix<double> m(size,size);
+  for (unsigned int i=0; i<size; ++i)
+    m(i,i) = i+1;
+
+  Vector<double> in (size), out(size);
+  for (unsigned int i=0; i<size; ++i)
+    in(i) = (double)Testing::rand()/RAND_MAX;
+
+  PreconditionChebyshev<FullMatrix<double>,Vector<double>,DiagonalMatrixManual> prec;
+  PreconditionChebyshev<FullMatrix<double>,Vector<double>,DiagonalMatrixManual>::AdditionalData
+  data;
+  data.smoothing_range = 2 * size;
+  data.degree = 3;
+  data.preconditioner.reset(new DiagonalMatrixManual());
+  data.preconditioner->set_vector_one(size);
+  prec.initialize(m, data);
+
+  deallog << "Exact inverse:     ";
+  for (unsigned int i=0; i<size; ++i)
+    deallog << in(i)/m(i,i) << " ";
+  deallog << std::endl;
+
+  deallog << "Check  vmult ones: ";
+  prec.vmult(out, in);
+  for (unsigned int i=0; i<size; ++i)
+    deallog << out(i) << " ";
+  deallog << std::endl;
+
+  deallog << "Check Tvmult ones: ";
+  prec.Tvmult(out, in);
+  for (unsigned int i=0; i<size; ++i)
+    deallog << out(i) << " ";
+  deallog << std::endl;
+
+  data.preconditioner->reinit(m);
+  data.smoothing_range = 2;
+  data.degree = 5;
+  prec.initialize(m, data);
+
+  deallog << "Check  vmult diag: ";
+  prec.vmult(out, in);
+  for (unsigned int i=0; i<size; ++i)
+    deallog << out(i) << " ";
+  deallog << std::endl;
+
+  deallog << "Check Tvmult diag: ";
+  prec.Tvmult(out, in);
+  for (unsigned int i=0; i<size; ++i)
+    deallog << out(i) << " ";
+  deallog << 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/precondition_chebyshev_02.with_lapack=true.output b/tests/lac/precondition_chebyshev_02.with_lapack=true.output
new file mode 100644 (file)
index 0000000..769900b
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::Exact inverse:     0.84 0.20 0.26 0.20 0.18 0.03 0.05 0.10 0.03 0.06 
+DEAL::Check  vmult ones: 0.82 0.26 0.33 0.21 0.15 0.02 0.03 0.09 0.03 0.07 
+DEAL::Check Tvmult ones: 0.82 0.26 0.33 0.21 0.15 0.02 0.03 0.09 0.03 0.07 
+DEAL::1.00   0.50   0.33   0.25   0.20   0.17   0.14   0.12   0.11   0.10   
+DEAL::Check  vmult diag: 0.84 0.20 0.26 0.20 0.18 0.03 0.05 0.10 0.03 0.06 
+DEAL::Check Tvmult diag: 0.84 0.20 0.26 0.20 0.18 0.03 0.05 0.10 0.03 0.06 

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.