From 34aae1bf8574a07cff321504c2cedd5b671ab83b Mon Sep 17 00:00:00 2001 From: Reza Rastak Date: Tue, 16 Jul 2019 02:26:59 -0700 Subject: [PATCH] test for constexpr SymmetricTensor added --- include/deal.II/base/symmetric_tensor.h | 2 +- tests/tensors/constexpr_symmetric_tensor.cc | 74 +++++++++++++++++++ .../tensors/constexpr_symmetric_tensor.output | 7 ++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/tensors/constexpr_symmetric_tensor.cc create mode 100644 tests/tensors/constexpr_symmetric_tensor.output diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index 84c62f5c32..5be47f7cab 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -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(data[i], sdata); diff --git a/tests/tensors/constexpr_symmetric_tensor.cc b/tests/tensors/constexpr_symmetric_tensor.cc new file mode 100644 index 0000000000..e34d0d130d --- /dev/null +++ b/tests/tensors/constexpr_symmetric_tensor.cc @@ -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 + +#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 index 0000000000..6f69b6bb62 --- /dev/null +++ b/tests/tensors/constexpr_symmetric_tensor.output @@ -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 -- 2.39.5