]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add test for Frobenius norm calculation
authorJonathan Robey <class4kayaker@gmail.com>
Tue, 6 Aug 2019 22:56:32 +0000 (16:56 -0600)
committerJonathan Robey <class4kayaker@gmail.com>
Tue, 6 Aug 2019 22:56:32 +0000 (16:56 -0600)
tests/lac/block_matrices_05.cc [new file with mode: 0644]
tests/lac/block_matrices_05.output [new file with mode: 0644]

diff --git a/tests/lac/block_matrices_05.cc b/tests/lac/block_matrices_05.cc
new file mode 100644 (file)
index 0000000..0a2d6d2
--- /dev/null
@@ -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 <deal.II/lac/block_sparse_matrix.h>
+#include <deal.II/lac/block_sparsity_pattern.h>
+#include <deal.II/lac/block_vector.h>
+
+#include <algorithm>
+
+#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<double> 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 (file)
index 0000000..a1019b8
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::OK
+DEAL::

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.