From 433e9fed92df8cf55597a7194f4242c1ef6ba4c1 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Tue, 1 Aug 2017 22:28:05 +0200 Subject: [PATCH] make DiagonalMatrix usable as a linear operator --- doc/news/changes/minor/20170801DenisDavydov-b | 3 + include/deal.II/lac/diagonal_matrix.h | 15 +++ tests/lac/diagonal_matrix_03.cc | 108 ++++++++++++++++++ tests/lac/diagonal_matrix_03.output | 8 ++ 4 files changed, 134 insertions(+) create mode 100644 doc/news/changes/minor/20170801DenisDavydov-b create mode 100644 tests/lac/diagonal_matrix_03.cc create mode 100644 tests/lac/diagonal_matrix_03.output diff --git a/doc/news/changes/minor/20170801DenisDavydov-b b/doc/news/changes/minor/20170801DenisDavydov-b new file mode 100644 index 0000000000..31ba64f0ef --- /dev/null +++ b/doc/news/changes/minor/20170801DenisDavydov-b @@ -0,0 +1,3 @@ +Fixed: DiagonalMatrix can now be used as a linear operator. +
+(Denis Davydov, 2017/08/01) diff --git a/include/deal.II/lac/diagonal_matrix.h b/include/deal.II/lac/diagonal_matrix.h index 54966bb293..621ece0709 100644 --- a/include/deal.II/lac/diagonal_matrix.h +++ b/include/deal.II/lac/diagonal_matrix.h @@ -178,6 +178,12 @@ public: void Tvmult_add (VectorType &dst, const VectorType &src) const; + /** + * Initialize vector @p dst. This is a part of the interface required + * by linear operator. + */ + void initialize_dof_vector(VectorType &dst) const; + /** * Return the memory consumption of this object. */ @@ -221,6 +227,15 @@ DiagonalMatrix::reinit(const VectorType &vec) +template +void +DiagonalMatrix::initialize_dof_vector(VectorType &dst) const +{ + dst.reinit(diagonal); +} + + + template void DiagonalMatrix::compress (VectorOperation::values operation) diff --git a/tests/lac/diagonal_matrix_03.cc b/tests/lac/diagonal_matrix_03.cc new file mode 100644 index 0000000000..18696b36e8 --- /dev/null +++ b/tests/lac/diagonal_matrix_03.cc @@ -0,0 +1,108 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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. +// +// --------------------------------------------------------------------- + + +// Make sure DiagonalMatrix can be used with linear_operator +// Otherwise this test is exact copy of diagonal_matrix.cc + + +#include "../tests.h" +#include +#include +#include +#include + + + +void +check() +{ + const unsigned int size = 10; + Vector vec(size); + for (unsigned int i=0; i > mat; + mat.reinit(vec); + const auto op = linear_operator>(mat); + + Vector in (size), out(size), exact(size); + for (unsigned int i=0; i > &>(mat)(i,i); + mat(i,i) = in(i); + in(i) = mat_entry; + } + op.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_03.output b/tests/lac/diagonal_matrix_03.output new file mode 100644 index 0000000000..97ce615a67 --- /dev/null +++ b/tests/lac/diagonal_matrix_03.output @@ -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 -- 2.39.5