]> https://gitweb.dealii.org/ - dealii.git/commitdiff
test for constexpr SymmetricTensor added
authorReza Rastak <rastak@stanford.edu>
Tue, 16 Jul 2019 09:26:59 +0000 (02:26 -0700)
committerReza Rastak <rastak@stanford.edu>
Tue, 16 Jul 2019 09:26:59 +0000 (02:26 -0700)
include/deal.II/base/symmetric_tensor.h
tests/tensors/constexpr_symmetric_tensor.cc [new file with mode: 0644]
tests/tensors/constexpr_symmetric_tensor.output [new file with mode: 0644]

index 84c62f5c32a7226b165b8a278f4a9e3fb7fc09cb..5be47f7cab009551a45de5239da4a697fe202ded 100644 (file)
@@ -1626,7 +1626,7 @@ namespace internal
 
     const unsigned int data_dim = SymmetricTensorAccessors::
       StorageType<2, dim, value_type>::n_independent_components;
-    value_type tmp[data_dim];
+    value_type tmp[data_dim]{};
     for (unsigned int i = 0; i < data_dim; ++i)
       tmp[i] =
         perform_double_contraction<dim, Number, OtherNumber>(data[i], sdata);
diff --git a/tests/tensors/constexpr_symmetric_tensor.cc b/tests/tensors/constexpr_symmetric_tensor.cc
new file mode 100644 (file)
index 0000000..e34d0d1
--- /dev/null
@@ -0,0 +1,74 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+// create and manipulate constexpr SymmetricTensor objects
+
+#include <deal.II/base/symmetric_tensor.h>
+
+#include "../tests.h"
+
+DEAL_II_CONSTEXPR SymmetricTensor<2, 2>
+                  get_tensor_2()
+{
+  SymmetricTensor<2, 2> A;
+  A[0][0] = 1.;
+  A[1][1] = 3.;
+  A[0][1] = -5.;
+  return A;
+}
+
+
+DEAL_II_CONSTEXPR SymmetricTensor<4, 2>
+                  get_tensor_4()
+{
+  SymmetricTensor<4, 2> B;
+  B[0][0][0][0] = 1.;
+  B[1][1][1][1] = 2.5;
+  B[0][1][0][1] = 0.2;
+  return B;
+}
+
+
+int
+main()
+{
+  initlog();
+
+  DEAL_II_CONSTEXPR const auto A = get_tensor_2();
+  {
+    LogStream::Prefix              p("SymmetricTensor<2,2>");
+    DEAL_II_CONSTEXPR const double calculation  = A[0][0] * A[1][0] - A[1][1];
+    DEAL_II_CONSTEXPR const double invariants[] = {first_invariant(A),
+                                                   second_invariant(A),
+                                                   third_invariant(A)};
+    DEAL_II_CONSTEXPR const double norm_square  = scalar_product(A, A);
+    deallog << "calculation result = " << calculation << std::endl;
+    deallog << "invariants = " << invariants[0] << ", " << invariants[1] << ", "
+            << invariants[2] << std::endl;
+    deallog << "norm square = " << norm_square << std::endl;
+  }
+
+  DEAL_II_CONSTEXPR const auto B = get_tensor_4();
+  {
+    LogStream::Prefix              p("SymmetricTensor<4,2>");
+    DEAL_II_CONSTEXPR const double calculation =
+      B[0][0][0][0] * B[1][0][0][1] - B[1][1][0][0];
+    DEAL_II_CONSTEXPR const auto B_times_A = B * A;
+    deallog << "calculation result = " << calculation << std::endl;
+    deallog << "B times A (0,0) = " << B_times_A[0][0] << std::endl;
+  }
+  deallog << "OK" << std::endl;
+  return 0;
+}
\ No newline at end of file
diff --git a/tests/tensors/constexpr_symmetric_tensor.output b/tests/tensors/constexpr_symmetric_tensor.output
new file mode 100644 (file)
index 0000000..6f69b6b
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL:SymmetricTensor<2,2>::calculation result = -8.00000
+DEAL:SymmetricTensor<2,2>::invariants = 4.00000, -22.0000, -22.0000
+DEAL:SymmetricTensor<2,2>::norm square = 60.0000
+DEAL:SymmetricTensor<4,2>::calculation result = 0.200000
+DEAL:SymmetricTensor<4,2>::B times A (0,0) = 1.00000
+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.