From 611d0c72f8c36ecdebc65dcb532a254a102cd289 Mon Sep 17 00:00:00 2001 From: Jonathan Robey Date: Tue, 6 Aug 2019 16:56:32 -0600 Subject: [PATCH] Add test for Frobenius norm calculation --- tests/lac/block_matrices_05.cc | 65 ++++++++++++++++++++++++++++++ tests/lac/block_matrices_05.output | 3 ++ 2 files changed, 68 insertions(+) create mode 100644 tests/lac/block_matrices_05.cc create mode 100644 tests/lac/block_matrices_05.output diff --git a/tests/lac/block_matrices_05.cc b/tests/lac/block_matrices_05.cc new file mode 100644 index 0000000000..0a2d6d219a --- /dev/null +++ b/tests/lac/block_matrices_05.cc @@ -0,0 +1,65 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 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. +// +// --------------------------------------------------------------------- + +#include +#include +#include + +#include + +#include "../tests.h" + + + +int +main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(2); + deallog.attach(logfile); + + BlockSparsityPattern bsp(2, 2); + // set sizes + for (unsigned int i = 0; i < 2; ++i) + for (unsigned int j = 0; j < 2; ++j) + bsp.block(i, j).reinit(5, 5, 5); + bsp.collect_sizes(); + + // make a full matrix + for (unsigned int row = 0; row < 10; ++row) + for (unsigned int i = 0; i < 10; ++i) + bsp.add(row, i); + bsp.compress(); + + BlockSparseMatrix bsm(bsp); + + for (unsigned int i = 0; i < bsm.m(); ++i) + for (unsigned int j = 0; j < bsm.n(); ++j) + { + bsm.add(i, j, 1.0); + } + + const double accuracy = 1e-12; + const double correct_frob_norm = 10.0; + const double frob_norm = bsm.frobenius_norm(); + + Assert(std::fabs(frob_norm - correct_frob_norm) < accuracy, ExcInternalError()); + + deallog << "OK" << std::endl; + deallog << std::flush; + + return 0; +} diff --git a/tests/lac/block_matrices_05.output b/tests/lac/block_matrices_05.output new file mode 100644 index 0000000000..a1019b879a --- /dev/null +++ b/tests/lac/block_matrices_05.output @@ -0,0 +1,3 @@ + +DEAL::OK +DEAL:: -- 2.39.5