]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test. 8599/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 19 Aug 2019 03:01:51 +0000 (21:01 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 20 Aug 2019 21:56:06 +0000 (15:56 -0600)
tests/tensors/tensor_30.cc [new file with mode: 0644]
tests/tensors/tensor_30.output [new file with mode: 0644]

diff --git a/tests/tensors/tensor_30.cc b/tests/tensors/tensor_30.cc
new file mode 100644 (file)
index 0000000..72bfb85
--- /dev/null
@@ -0,0 +1,77 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 - 2018 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Additional tests for tensor contraction
+//
+// A mysteriously failing pull request suggested that the contraction
+// of a rank-3 tensor and a rank-1 tensor might be using the wrong
+// indices. Check this.
+
+#include <deal.II/base/symmetric_tensor.h>
+#include <deal.II/base/tensor.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+template <int dim>
+void
+test()
+{
+  Tensor<3, dim> a;
+  Tensor<1, dim> b;
+
+  for (unsigned int i = 0; i < dim; ++i)
+    for (unsigned int j = 0; j < dim; ++j)
+      for (unsigned int k = 0; k < dim; ++k)
+        a[i][j][k] = i + 2 * j + 3 * k;
+
+  for (unsigned int k = 0; k < dim; ++k)
+    b[k] = k;
+
+  // Compute
+  //   c(i,j) = sum_k a(i,j,k)*b(k)
+  //          = sum_k (i + 2j + 3k)k
+  //          = (i + 2j) sum k  + 3 sum k^2
+  // which in 2d equates to
+  //          = (i + 2j) + 3
+  // and in 3d equates to
+  //          = 3(i + 2j) + 3*5
+  //
+  // In other words, in 2d this is the 2x2 matrix
+  //    [[3,4],[4,6]]
+  // and in 3d is the 3x3 matrix
+  //    [[15,21,27],[18,24,30],[21,27,33]]
+  Tensor<2, dim> c = a * b;
+
+  deallog << c << std::endl;
+}
+
+
+
+int
+main(int argc, char *argv[])
+{
+  initlog();
+
+  test<1>();
+  test<2>();
+  test<3>();
+
+  deallog << "OK" << std::endl;
+
+  return 0;
+}
diff --git a/tests/tensors/tensor_30.output b/tests/tensors/tensor_30.output
new file mode 100644 (file)
index 0000000..ad198cb
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::0.00000
+DEAL::3.00000 5.00000 4.00000 6.00000
+DEAL::15.0000 21.0000 27.0000 18.0000 24.0000 30.0000 21.0000 27.0000 33.0000
+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.