]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test for symmetric tensor access. 2651/head
authorDavid Wells <wellsd2@rpi.edu>
Sun, 29 May 2016 22:42:31 +0000 (18:42 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sun, 29 May 2016 22:42:47 +0000 (18:42 -0400)
tests/base/symmetric_tensor_30.cc [new file with mode: 0644]
tests/base/symmetric_tensor_30.output [new file with mode: 0644]

diff --git a/tests/base/symmetric_tensor_30.cc b/tests/base/symmetric_tensor_30.cc
new file mode 100644 (file)
index 0000000..61a6baf
--- /dev/null
@@ -0,0 +1,118 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+// Verify that SymmetricTensor::operator() and SymmetricTensor::operator[] do
+// what we think they should do.
+
+#include "../tests.h"
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/table_indices.h>
+#include <deal.II/base/logstream.h>
+
+
+template <int dim>
+void check_2 ()
+{
+  using namespace dealii;
+  Testing::rand(true, 42);
+
+  SymmetricTensor<2, dim> change_with_brackets;
+  SymmetricTensor<2, dim> change_with_parentheses;
+  for (unsigned int k = 0; k < dim; ++k)
+    {
+      for (unsigned int l = 0; l < dim; ++l)
+        {
+          const double entry = double(Testing::rand());
+          TableIndices<2> indices(k, l);
+
+          // check assignment
+          change_with_brackets[indices] = entry;
+          change_with_parentheses(indices) = entry;
+          AssertThrow(change_with_brackets[k][l] == entry,
+                      ExcMessage("Entries should match"));
+          AssertThrow(change_with_parentheses[k][l] == entry,
+                      ExcMessage("Entries should match"));
+
+          // and access
+          const double brackets_entry = change_with_brackets[indices];
+          const double parentheses_entry = change_with_parentheses(indices);
+          AssertThrow(brackets_entry == entry,
+                      ExcMessage("Entries should match"));
+          AssertThrow(parentheses_entry == entry,
+                      ExcMessage("Entries should match"));
+        }
+    }
+}
+
+template <int dim>
+void check_4 ()
+{
+  using namespace dealii;
+  Testing::rand(true, 42);
+
+  SymmetricTensor<4, dim> change_with_brackets;
+  SymmetricTensor<4, dim> change_with_parentheses;
+  for (unsigned int i = 0; i < dim; ++i)
+    {
+      for (unsigned int j = 0; j < dim; ++j)
+        {
+          for (unsigned int k = 0; k < dim; ++k)
+            {
+              for (unsigned int l = 0; l < dim; ++l)
+                {
+                  const double entry = double(Testing::rand());
+                  TableIndices<4> indices(i, j, k, l);
+
+                  // check assignment
+                  change_with_brackets[indices] = entry;
+                  change_with_parentheses(indices) = entry;
+                  AssertThrow(change_with_brackets[i][j][k][l] == entry,
+                              ExcMessage("Entries should match"));
+                  AssertThrow(change_with_parentheses[i][j][k][l] == entry,
+                              ExcMessage("Entries should match"));
+
+                  // and access
+                  const double brackets_entry = change_with_brackets[indices];
+                  const double parentheses_entry = change_with_parentheses(indices);
+                  AssertThrow(brackets_entry == entry,
+                              ExcMessage("Entries should match"));
+                  AssertThrow(parentheses_entry == entry,
+                              ExcMessage("Entries should match"));
+                }
+            }
+        }
+    }
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog << std::setprecision(3);
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  deallog << "check rank 2 tensors" << std::endl;
+  check_2<1>();
+  check_2<2>();
+  check_2<3>();
+
+  deallog << "check rank 4 tensors" << std::endl;
+  check_4<1>();
+  check_4<2>();
+  check_4<3>();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/base/symmetric_tensor_30.output b/tests/base/symmetric_tensor_30.output
new file mode 100644 (file)
index 0000000..8201db9
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::check rank 2 tensors
+DEAL::check rank 4 tensors
+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.