From: Matthias Maier Date: Fri, 11 Sep 2015 19:44:10 +0000 (-0500) Subject: Add a test for TensorAccessors::extract X-Git-Tag: v8.4.0-rc2~438^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9a97f1c5a20b137e1948a2b11831f3134bea1d1;p=dealii.git Add a test for TensorAccessors::extract --- diff --git a/tests/base/tensor_accessors_02.cc b/tests/base/tensor_accessors_02.cc new file mode 100644 index 0000000000..fe3d5a4172 --- /dev/null +++ b/tests/base/tensor_accessors_02.cc @@ -0,0 +1,83 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2015 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. +// +// --------------------------------------------------------------------- + +#include "../tests.h" +#include +#include +#include + + +int main() +{ + initlog(); + + Tensor<9, 3, int> t; + t[0][1][2][0][1][2][0][1][2] = 42; + + TableIndices<9> indices(0, 1, 2, 0, 1, 2, 0, 1, 2); + + deallog << TensorAccessors::extract<9>(t, indices) << std::endl; + + TensorAccessors::extract<9>(t, indices) = 84; + + deallog << t[0][1][2][0][1][2][0][1][2] << std::endl; + + const Tensor<9, 3, int> &t_ref = t; + + deallog << TensorAccessors::extract<9>(t_ref, indices) << std::endl; + + // Reduced access: + { + deallog << TensorAccessors::extract<8>(t_ref, indices)[2] << std::endl; + deallog << TensorAccessors::extract<7>(t_ref, indices)[1][2] << std::endl; + deallog << TensorAccessors::extract<6>(t_ref, indices)[0][1][2] << std::endl; + deallog << TensorAccessors::extract<5>(t_ref, indices)[2][0][1][2] << std::endl; + deallog << TensorAccessors::extract<4>(t_ref, indices)[1][2][0][1][2] << std::endl; + deallog << TensorAccessors::extract<3>(t_ref, indices)[0][1][2][0][1][2] << std::endl; + deallog << TensorAccessors::extract<2>(t_ref, indices)[2][0][1][2][0][1][2] << std::endl; + deallog << TensorAccessors::extract<1>(t_ref, indices)[1][2][0][1][2][0][1][2] << std::endl; + deallog << TensorAccessors::extract<0>(t_ref, indices)[0][1][2][0][1][2][0][1][2] << std::endl; + } + + // Apply on c-style arrays: + { + double foo[3][3][3][3][3]; + + foo[2][1][0][2][1] = 42.; + + unsigned int indices[5]; + indices[0] = 2; + indices[1] = 1; + indices[2] = 0; + indices[3] = 2; + indices[4] = 1; + + deallog << TensorAccessors::extract<5>(foo, indices) << std::endl; + + // read-only: + + const double (& foo2)[3][3][3][3][3] = foo; + deallog << TensorAccessors::extract<5>(foo2, indices) << std::endl; + + // via std::array + +#ifdef DEAL_II_WITH_CXX11 + deallog << TensorAccessors::extract<5>(foo, std::array({2, 1, 0, 2, 1})) << std::endl; +#else + deallog << 42. << std::endl; +#endif + } + +} diff --git a/tests/base/tensor_accessors_02.output b/tests/base/tensor_accessors_02.output new file mode 100644 index 0000000000..13b8e341b8 --- /dev/null +++ b/tests/base/tensor_accessors_02.output @@ -0,0 +1,16 @@ + +DEAL::42 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::84 +DEAL::42.0000 +DEAL::42.0000 +DEAL::42.0000