From fadf55490d527d8c03b74bc3f11382f766b20369 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 13 Feb 2019 16:46:32 -0600 Subject: [PATCH] add a test --- tests/lac/linear_operator_01d.cc | 90 ++++++++++++++++++++++++++++ tests/lac/linear_operator_01d.output | 2 + 2 files changed, 92 insertions(+) create mode 100644 tests/lac/linear_operator_01d.cc create mode 100644 tests/lac/linear_operator_01d.output diff --git a/tests/lac/linear_operator_01d.cc b/tests/lac/linear_operator_01d.cc new file mode 100644 index 0000000000..b5482f5a9d --- /dev/null +++ b/tests/lac/linear_operator_01d.cc @@ -0,0 +1,90 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2015 - 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Verify that the inverse_operator function signature without a +// preconditioner argument and the one with PreconditionIdentity() as a +// temporary works correctly. + +#include +#include +#include +#include +#include +#include +#include + +#include "../tests.h" + +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); + + const auto lo_A_inv = inverse_operator(lo_A, solver_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_01d.output b/tests/lac/linear_operator_01d.output new file mode 100644 index 0000000000..9694fcba7f --- /dev/null +++ b/tests/lac/linear_operator_01d.output @@ -0,0 +1,2 @@ + +DEAL::number of mistakes: 0 -- 2.39.5