From 96f4a9ff8976b4a0e1c1a82a9baade3fed62f80f Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 17 Sep 2015 00:49:01 -0500 Subject: [PATCH] Testsuite: Add a small test for contract<..,..> --- tests/base/tensor_09.cc | 130 ++++++++++++++++++++++++++++++++++++ tests/base/tensor_09.output | 46 +++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 tests/base/tensor_09.cc create mode 100644 tests/base/tensor_09.output diff --git a/tests/base/tensor_09.cc b/tests/base/tensor_09.cc new file mode 100644 index 0000000000..50cdacda34 --- /dev/null +++ b/tests/base/tensor_09.cc @@ -0,0 +1,130 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2006 - 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. +// +// --------------------------------------------------------------------- + + +// check generic contract variants tha allow to specifiy the indices which +// will be contracted. + +#include "../tests.h" +#include + +int main () +{ + initlog(); + + Tensor<1, 3, int> rank1; + rank1[0] = 1; + rank1[1] = 2; + rank1[2] = 4; + + Tensor<2, 3, int> rank2; + rank2[0] = 4 * rank1; + rank2[1] = 2 * rank1; + rank2[2] = 1 * rank1; + + Tensor<3, 3, int> rank3; + rank3[0] = 7 * rank2; + rank3[1] = 6 * rank2; + rank3[2] = 9 * rank2; + + Tensor<4, 3, int> rank4; + rank4[0] = 4 * rank3; + rank4[1] = 3 * rank3; + rank4[2] = 2 * rank3; + + + // rank3 * rank1 over all possible indices: + { + Tensor<2, 3, int> result; + + deallog << contract<0, 0>(rank3, rank1) << std::endl; + contract(result, rank3, 1, rank1); + deallog << result << std::endl << std::endl; + + deallog << contract<1, 0>(rank3, rank1) << std::endl; + contract(result, rank3, 2, rank1); + deallog << result << std::endl << std::endl; + + deallog << contract<2, 0>(rank3, rank1) << std::endl; + contract(result, rank3, 3, rank1); + deallog << result << std::endl << std::endl; + } + + + // rank2 * rank2 over all possible indices: + { + Tensor<2, 3, int> result; + + deallog << contract<0, 0>(rank2, rank2) << std::endl; + contract(result, rank2, 1, rank2, 1); + deallog << result << std::endl << std::endl; + + deallog << contract<1, 0>(rank2, rank2) << std::endl; + contract(result, rank2, 2, rank2, 1); + deallog << result << std::endl << std::endl; + + deallog << contract<0, 1>(rank2, rank2) << std::endl; + contract(result, rank2, 1, rank2, 2); + deallog << result << std::endl << std::endl; + + deallog << contract<1, 1>(rank2, rank2) << std::endl; + contract(result, rank2, 2, rank2, 2); + deallog << result << std::endl << std::endl; + } + + + // rank3 * rank2 over all possible indices: + { + Tensor<3, 3, int> result; + + deallog << contract<0, 0>(rank3, rank2) << std::endl; + contract(result, rank3, 1, rank2, 1); + deallog << result << std::endl << std::endl; + + deallog << contract<1, 0>(rank3, rank2) << std::endl; + contract(result, rank3, 2, rank2, 1); + deallog << result << std::endl << std::endl; + + deallog << contract<2, 0>(rank3, rank2) << std::endl; + contract(result, rank3, 3, rank2, 1); + deallog << result << std::endl << std::endl; + + deallog << contract<0, 1>(rank3, rank2) << std::endl; + contract(result, rank3, 1, rank2, 2); + deallog << result << std::endl << std::endl; + + deallog << contract<1, 1>(rank3, rank2) << std::endl; + contract(result, rank3, 2, rank2, 2); + deallog << result << std::endl << std::endl; + + deallog << contract<2, 1>(rank3, rank2) << std::endl; + contract(result, rank3, 3, rank2, 2); + deallog << result << std::endl << std::endl; + } + + + // rank4 ** rank2, double contraction: + { + Tensor<2, 3, int> result; + + deallog << contract<2, 0, 3, 1>(rank4, rank2) << std::endl; + deallog << contract<3, 1, 2, 0>(rank4, rank2) << std::endl; + deallog << contract<0, 2, 1, 3>(rank2, rank4) << std::endl; + deallog << contract<1, 3, 0, 2>(rank2, rank4) << std::endl; + + double_contract(result, rank4, rank2); + deallog << result << std::endl << std::endl; + } +} diff --git a/tests/base/tensor_09.output b/tests/base/tensor_09.output new file mode 100644 index 0000000000..993e7d6f6c --- /dev/null +++ b/tests/base/tensor_09.output @@ -0,0 +1,46 @@ + +DEAL::220 440 880 110 220 440 55 110 220 +DEAL::220 440 880 110 220 440 55 110 220 +DEAL:: +DEAL::84 168 336 72 144 288 108 216 432 +DEAL::84 168 336 72 144 288 108 216 432 +DEAL:: +DEAL::588 294 147 504 252 126 756 378 189 +DEAL::588 294 147 504 252 126 756 378 189 +DEAL:: +DEAL::21 42 84 42 84 168 84 168 336 +DEAL::21 42 84 42 84 168 84 168 336 +DEAL:: +DEAL::48 96 192 24 48 96 12 24 48 +DEAL::48 96 192 24 48 96 12 24 48 +DEAL:: +DEAL::48 24 12 96 48 24 192 96 48 +DEAL::48 24 12 96 48 24 192 96 48 +DEAL:: +DEAL::336 168 84 168 84 42 84 42 21 +DEAL::336 168 84 168 84 42 84 42 21 +DEAL:: +DEAL::196 392 784 392 784 1568 784 1568 3136 98 196 392 196 392 784 392 784 1568 49 98 196 98 196 392 196 392 784 +DEAL::196 392 784 392 784 1568 784 1568 3136 98 196 392 196 392 784 392 784 1568 49 98 196 98 196 392 196 392 784 +DEAL:: +DEAL::147 294 588 294 588 1176 588 1176 2352 126 252 504 252 504 1008 504 1008 2016 189 378 756 378 756 1512 756 1512 3024 +DEAL::147 294 588 294 588 1176 588 1176 2352 126 252 504 252 504 1008 504 1008 2016 189 378 756 378 756 1512 756 1512 3024 +DEAL:: +DEAL::336 672 1344 168 336 672 84 168 336 288 576 1152 144 288 576 72 144 288 432 864 1728 216 432 864 108 216 432 +DEAL::336 672 1344 168 336 672 84 168 336 288 576 1152 144 288 576 72 144 288 432 864 1728 216 432 864 108 216 432 +DEAL:: +DEAL::880 440 220 1760 880 440 3520 1760 880 440 220 110 880 440 220 1760 880 440 220 110 55 440 220 110 880 440 220 +DEAL::880 440 220 1760 880 440 3520 1760 880 440 220 110 880 440 220 1760 880 440 220 110 55 440 220 110 880 440 220 +DEAL:: +DEAL::336 168 84 672 336 168 1344 672 336 288 144 72 576 288 144 1152 576 288 432 216 108 864 432 216 1728 864 432 +DEAL::336 168 84 672 336 168 1344 672 336 288 144 72 576 288 144 1152 576 288 432 216 108 864 432 216 1728 864 432 +DEAL:: +DEAL::2352 1176 588 1176 588 294 588 294 147 2016 1008 504 1008 504 252 504 252 126 3024 1512 756 1512 756 378 756 378 189 +DEAL::2352 1176 588 1176 588 294 588 294 147 2016 1008 504 1008 504 252 504 252 126 3024 1512 756 1512 756 378 756 378 189 +DEAL:: +DEAL::12348 10584 15876 9261 7938 11907 6174 5292 7938 +DEAL::12348 10584 15876 9261 7938 11907 6174 5292 7938 +DEAL::12348 10584 15876 9261 7938 11907 6174 5292 7938 +DEAL::12348 10584 15876 9261 7938 11907 6174 5292 7938 +DEAL::12348 10584 15876 9261 7938 11907 6174 5292 7938 +DEAL:: -- 2.39.5