]> https://gitweb.dealii.org/ - dealii.git/commitdiff
added two unit tests and its output for compute_mmult_pattern(..)
authorChristoph Goering <christoph.goering@tum.de>
Wed, 20 Dec 2017 13:25:23 +0000 (14:25 +0100)
committerChristoph Goering <christoph.goering@tum.de>
Thu, 21 Dec 2017 07:45:04 +0000 (08:45 +0100)
tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc [new file with mode: 0644]
tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.output [new file with mode: 0644]
tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.cc [new file with mode: 0644]
tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.output [new file with mode: 0644]

diff --git a/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc b/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc
new file mode 100644 (file)
index 0000000..c04d0cd
--- /dev/null
@@ -0,0 +1,98 @@
+
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2004 - 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check DynamicSparsityPattern::compute_mmult_pattern(). Test if multiplication
+// with each combination of SparsityPatternTypes is possible.
+
+#include "../tests.h"
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <deal.II/lac/sparsity_pattern.h>
+
+
+void test ()
+{
+  // create different (dynamic) sparsity pattern and add entries at
+  // destinct locations. Check if mmultiplication creates entries at the right
+  // rows and columns.
+  const unsigned int M = 100;
+  const unsigned int N = 50;
+  const unsigned int O = 75;
+
+  const unsigned int m_entries = 4;
+  const unsigned int n_entries = 5;
+  const unsigned int o_entries = 6;
+
+  bool test_failed = false;
+
+  DynamicSparsityPattern dyn_left (M,N),
+                         dyn_right (N,O);
+
+  DynamicSparsityPattern out;
+
+  SparsityPattern left,
+                  right;
+
+  // add manually entries to pattern
+  for (unsigned int i=0; i<M; i+=m_entries)
+    for (unsigned int j=0; j<N; j+=n_entries)
+      dyn_left.add (i,j);
+  // add manually entries to pattern
+  for (unsigned int i=0; i<N; i+=n_entries)
+    for (unsigned int j=0; j<O; j+=o_entries)
+      dyn_right.add (i,j);
+  // copy DynamicSparsityPattern to SparsityPattern
+  left.copy_from(dyn_left);
+  right.copy_from(dyn_right);
+  // test DynamicSparsityPattern and DynamicSparsityPattern
+  out.compute_mmult_pattern(dyn_left,dyn_right);
+  for (unsigned int i=0; i<M; i+=m_entries)
+    for (unsigned int j=0; j<O; j+=o_entries)
+      if (!out.exists(i,j))
+        test_failed = true;
+  // test SparsityPattern and DynamicSparsityPattern
+  out.compute_mmult_pattern(left,dyn_right);
+  for (unsigned int i=0; i<M; i+=m_entries)
+    for (unsigned int j=0; j<O; j+=o_entries)
+      if (!out.exists(i,j))
+        test_failed = true;
+  // test DynamicSparsityPattern and SparsityPattern
+  out.compute_mmult_pattern(dyn_left,right);
+  for (unsigned int i=0; i<M; i+=m_entries)
+    for (unsigned int j=0; j<O; j+=o_entries)
+      if (!out.exists(i,j))
+        test_failed = true;
+  // test SparsityPattern and SparsityPattern
+  out.compute_mmult_pattern(left,right);
+  for (unsigned int i=0; i<M; i+=m_entries)
+    for (unsigned int j=0; j<O; j+=o_entries)
+      if (!out.exists(i,j))
+        test_failed = true;
+
+  Assert(!test_failed, ExcInternalError());
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  initlog();
+
+  test ();
+  return 0;
+}
diff --git a/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.output b/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.cc b/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.cc
new file mode 100644 (file)
index 0000000..21801cb
--- /dev/null
@@ -0,0 +1,111 @@
+
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2004 - 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check DynamicSparsityPattern::compute_mmult_pattern(). Test if multiplication
+// of two pattern yield the right DynamicSparsityPattern.
+
+#include "../tests.h"
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/sparse_matrix.h>
+
+
+void test ()
+{
+  // create two different FullMatrix objects and add entries randomly to it.
+  // Multiply them via FullMatrix::mmult(..), go through each row and column,
+  // and check if DynamicSparsityPattern::compute_mmult_pattern(..) predicts
+  // the entries (i,j) where values supposed to be because of the multiplication.
+
+  const unsigned int M = 100;
+  const unsigned int N = 50;
+  const unsigned int O = 75;
+
+  const unsigned int m_entries = 4;
+  const unsigned int n_entries = 5;
+  const unsigned int o_entries = 6;
+
+  bool test_failed = false;
+
+  DynamicSparsityPattern dyn_left (M,N),
+                         dyn_right (N,O);
+  DynamicSparsityPattern dyn_out;
+
+  FullMatrix<double> mat_left(M,N),
+             mat_right(N,O),
+             mat_out(M,O);
+
+  // add randomly entries to the left matrices/pattern starting at the 2nd row
+  for (unsigned int m=1; m<M; ++m)
+    for (unsigned int n=0; n<N; ++n)
+      if (Utilities::generate_normal_random_number(0,0.2) > 0)
+        {
+          dyn_left.add (m,n);
+          mat_left[m][n] = 1;
+        }
+  // add randomly entries to the right matrices/pattern starting at the 2nd column
+  for (unsigned int n=0; n<N; ++n)
+    for (unsigned int o=1; o<O; ++o)
+      if (Utilities::generate_normal_random_number(0,0.2) > 0)
+        {
+          dyn_right.add (n,o);
+          mat_right[n][o] = 1;
+        }
+  // first row of left and first column of right in such a way that no entry
+  // is created in final matrix
+  for (unsigned int n=0; n<N; ++n)
+    if (Utilities::generate_normal_random_number(0,0.2) > 0)
+      {
+        dyn_right.add (n,0);
+        mat_right[n][0] = 1;
+      }
+    else
+      {
+        dyn_left.add (0,n);
+        mat_left[0][n] = 1;
+      }
+
+
+  // do matrix-matrix-multiplication
+  mat_left.mmult(mat_out,mat_right);
+  dyn_out.compute_mmult_pattern(dyn_left,dyn_right);
+
+  // go through whole matrix and check if pattern are equal
+  for (unsigned int i=0; i<M; ++i)
+    for (unsigned int j=0; j<O; ++j)
+      {
+        if (mat_out[i][j] != 0 && !dyn_out.exists(i,j))
+          test_failed = true;
+        else if (mat_out[i][j] == 0  && dyn_out.exists(i,j))
+          test_failed = true;
+      }
+
+  Assert(!test_failed, ExcInternalError());
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main ()
+{
+  initlog();
+
+  test ();
+  return 0;
+}
diff --git a/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.output b/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.