From bad5b100b7b564a21fa9a9a2899f9f1fdeade702 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 30 Dec 2015 18:26:48 +0100 Subject: [PATCH] Add a regression test --- tests/lac/linear_operator_08a.cc | 89 +++++++++++++++++++ .../linear_operator_08a.with_cxx11=on.output | 2 + 2 files changed, 91 insertions(+) create mode 100644 tests/lac/linear_operator_08a.cc create mode 100644 tests/lac/linear_operator_08a.with_cxx11=on.output diff --git a/tests/lac/linear_operator_08a.cc b/tests/lac/linear_operator_08a.cc new file mode 100644 index 0000000000..ff2b7b43f1 --- /dev/null +++ b/tests/lac/linear_operator_08a.cc @@ -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 +#include +#include +#include +#include + +#include +#include + +using namespace dealii; + +int main() +{ + initlog(); + + Vector 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 A(sparsity_pattern); + A.set(0, 0, 4.0); + A.set(1, 1, 4.0); + + Vector 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> 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 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 index 0000000000..9694fcba7f --- /dev/null +++ b/tests/lac/linear_operator_08a.with_cxx11=on.output @@ -0,0 +1,2 @@ + +DEAL::number of mistakes: 0 -- 2.39.5