From: Rene Gassmoeller Date: Mon, 4 Nov 2024 10:03:25 +0000 (+0100) Subject: Add test X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F17838%2Fhead;p=dealii.git Add test --- diff --git a/tests/tensors/tensor_33.cc b/tests/tensors/tensor_33.cc new file mode 100644 index 0000000000..7f3d2c6d46 --- /dev/null +++ b/tests/tensors/tensor_33.cc @@ -0,0 +1,67 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2017 - 2020 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +// Test that we can convert a Tensor of a given rank and dimension to a Tensor +// of Tensors of rank-1 and dimension dim. + +#include +#include +#include + +#include "../tests.h" + + +template +void +test() +{ + std::vector values(Utilities::fixed_power(dim), 0.0); + std::iota(values.begin(), values.end(), 0.0); + + Tensor t(make_array_view(values)); + TableIndices indices; + + Tensor<1, dim, Tensor> t2(t); + + // Check for Tensor + deallog << "Rank: " << std::to_string(rank) + << ". Dim: " << std::to_string(dim) << ". Tensor1: " << t + << std::endl; + + // Check for Tensor<1,dim,Tensor> + deallog << "Rank: " << std::to_string(rank) + << ". Dim: " << std::to_string(dim) << ". Tensor2: " << t2 + << std::endl; +} + +int +main(int argc, char *argv[]) +{ + initlog(); + + test<1, 1>(); + test<2, 1>(); + test<3, 1>(); + test<1, 2>(); + test<2, 2>(); + test<3, 2>(); + test<1, 3>(); + test<2, 3>(); + test<3, 3>(); + + deallog << "OK" << std::endl; + + return 0; +} diff --git a/tests/tensors/tensor_33.output b/tests/tensors/tensor_33.output new file mode 100644 index 0000000000..8bb86ac0e2 --- /dev/null +++ b/tests/tensors/tensor_33.output @@ -0,0 +1,20 @@ + +DEAL::Rank: 1. Dim: 1. Tensor1: 0.00000 +DEAL::Rank: 1. Dim: 1. Tensor2: 0.00000 +DEAL::Rank: 2. Dim: 1. Tensor1: 0.00000 +DEAL::Rank: 2. Dim: 1. Tensor2: 0.00000 +DEAL::Rank: 3. Dim: 1. Tensor1: 0.00000 +DEAL::Rank: 3. Dim: 1. Tensor2: 0.00000 +DEAL::Rank: 1. Dim: 2. Tensor1: 0.00000 1.00000 +DEAL::Rank: 1. Dim: 2. Tensor2: 0.00000 1.00000 +DEAL::Rank: 2. Dim: 2. Tensor1: 0.00000 1.00000 2.00000 3.00000 +DEAL::Rank: 2. Dim: 2. Tensor2: 0.00000 1.00000 2.00000 3.00000 +DEAL::Rank: 3. Dim: 2. Tensor1: 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 +DEAL::Rank: 3. Dim: 2. Tensor2: 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 +DEAL::Rank: 1. Dim: 3. Tensor1: 0.00000 1.00000 2.00000 +DEAL::Rank: 1. Dim: 3. Tensor2: 0.00000 1.00000 2.00000 +DEAL::Rank: 2. Dim: 3. Tensor1: 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 +DEAL::Rank: 2. Dim: 3. Tensor2: 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 +DEAL::Rank: 3. Dim: 3. Tensor1: 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000 21.0000 22.0000 23.0000 24.0000 25.0000 26.0000 +DEAL::Rank: 3. Dim: 3. Tensor2: 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000 21.0000 22.0000 23.0000 24.0000 25.0000 26.0000 +DEAL::OK