From aa12e1607832cfad12bda7ff90c3b91eef602b74 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 11 Sep 2015 14:46:29 -0500 Subject: [PATCH] Add a test for TensorAccessors::contract3 --- tests/base/tensor_accessors_04.cc | 138 ++++++++++++++++++++++++++ tests/base/tensor_accessors_04.output | 37 +++++++ 2 files changed, 175 insertions(+) create mode 100644 tests/base/tensor_accessors_04.cc create mode 100644 tests/base/tensor_accessors_04.output diff --git a/tests/base/tensor_accessors_04.cc b/tests/base/tensor_accessors_04.cc new file mode 100644 index 0000000000..6ecc954b9b --- /dev/null +++ b/tests/base/tensor_accessors_04.cc @@ -0,0 +1,138 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + +// Test TensorAccessors::contract3 + +#include "../tests.h" +#include +#include +#include + + +int main() +{ + initlog(); + + // Contract rank 0, rank 0, rank 0: + { + int a = 1; + int b = 2; + int c = 4; + + deallog << "left: " << a << std::endl; + deallog << "middle: " << b << std::endl; + deallog << "right: " << c << std::endl; + deallog << "Result: " << TensorAccessors::contract3<0, 0, 5, int>(a, b, c) << std::endl; + deallog << std::endl; + } + + int c_left [5] = {0, 1, 2, 3, 4}; + Tensor<1, 5, int> left (c_left); + + int c_right [5] = {0, 100, 200, 300, 400}; + const Tensor<1, 5, int> right (c_right); + + + // Contract rank 1, rank 1, rank 0: + { + const int c = -10; + + deallog << "left: " << left << std::endl; + deallog << "middle: " << right << std::endl; + deallog << "right: " << c << std::endl; + deallog << "Result: " << TensorAccessors::contract3<1, 0, 5, int>(left, right, c) << std::endl; + deallog << std::endl; + } + + + // Contract rank 0, rank 1, rank 1: + { + const int c = -5; + + deallog << "left: " << c << std::endl; + deallog << "middle: " << left << std::endl; + deallog << "right: " << right << std::endl; + deallog << "Result: " << TensorAccessors::contract3<0, 1, 5, int>(c, left, right) << std::endl; + deallog << std::endl; + } + + Tensor<2, 5, int> middle; + middle[0] = left; + middle[1] = 2 * left; + middle[2] = 4 * left; + middle[3] = 8 * left; + middle[4] = 16 * left; + + // Contract rank 1, rank 2, rank 1: + { + deallog << "left: " << left << std::endl; + deallog << "middle: " << middle << std::endl; + deallog << "right: " << right << std::endl; + deallog << "Result: " << TensorAccessors::contract3<1, 1, 5, int>(left, middle, right) << std::endl; + deallog << std::endl; + // manually verified to be equal to the old implementation + // deallog << contract3(left, middle, right) << std::endl; + } + + Tensor<3, 5, int> middle3; + middle3[0] = middle; + middle3[1] = 2 * middle; + middle3[2] = 4 * middle; + middle3[3] = 8 * middle; + middle3[4] = 16 * middle; + + // Contract rank 2, rank 3, rank 1: + { + deallog << "left: " << middle << std::endl; + deallog << "middle: " << middle3 << std::endl; + deallog << "right: " << right << std::endl; + deallog << "Result: " << TensorAccessors::contract3<2, 1, 5, int>(middle, middle3, right) << std::endl; + deallog << std::endl; +// manually verified to be equal to the old implementation +// deallog << contract3(middle, middle3, right) << std::endl; + } + + // Contract rank 1, rank 3, rank 2: + { + deallog << "left: " << left << std::endl; + deallog << "middle: " << middle3 << std::endl; + deallog << "right: " << middle << std::endl; + deallog << "Result: " << TensorAccessors::contract3<1, 2, 5, int>(left, middle3, middle) << std::endl; + deallog << std::endl; +// manually verified to be equal to the old implementation +// deallog << contract3(left, middle3, middle) << std::endl; + } + + + Tensor<4, 5, int> middle4; + middle4[0] = middle3; + middle4[1] = 2 * middle3; + middle4[2] = 4 * middle3; + middle4[3] = 8 * middle3; + middle4[4] = 16 * middle3; + + Tensor<2, 5, int> left2 = 17 * middle; + + // Contract rank 2, rank 4, rank 2: + { + deallog << "left: " << left2 << std::endl; + deallog << "middle: " << middle4 << std::endl; + deallog << "right: " << middle << std::endl; + deallog << "Result: " << TensorAccessors::contract3<2, 2, 5, int>(left2, middle4, middle) << std::endl; + deallog << std::endl; +// manually verified to be equal to the old implementation +// deallog << contract3(left2, middle4, middle) << std::endl; + } +} diff --git a/tests/base/tensor_accessors_04.output b/tests/base/tensor_accessors_04.output new file mode 100644 index 0000000000..6770e8517f --- /dev/null +++ b/tests/base/tensor_accessors_04.output @@ -0,0 +1,37 @@ + +DEAL::left: 1 +DEAL::middle: 2 +DEAL::right: 4 +DEAL::Result: 8 +DEAL:: +DEAL::left: 0 1 2 3 4 +DEAL::middle: 0 100 200 300 400 +DEAL::right: -10 +DEAL::Result: -30000 +DEAL:: +DEAL::left: -5 +DEAL::middle: 0 1 2 3 4 +DEAL::right: 0 100 200 300 400 +DEAL::Result: -15000 +DEAL:: +DEAL::left: 0 1 2 3 4 +DEAL::middle: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 +DEAL::right: 0 100 200 300 400 +DEAL::Result: 294000 +DEAL:: +DEAL::left: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 +DEAL::middle: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 +DEAL::right: 0 100 200 300 400 +DEAL::Result: 100254000 +DEAL:: +DEAL::left: 0 1 2 3 4 +DEAL::middle: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 +DEAL::right: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 +DEAL::Result: 1002540 +DEAL:: +DEAL::left: 0 17 34 51 68 0 34 68 102 136 0 68 136 204 272 0 136 272 408 544 0 272 544 816 1088 +DEAL::middle: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 1024 2048 3072 4096 0 8 16 24 32 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 1024 2048 3072 4096 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 1024 2048 3072 4096 0 2048 4096 6144 8192 0 16 32 48 64 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 32 64 96 128 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 64 128 192 256 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 1024 2048 3072 4096 0 128 256 384 512 0 256 512 768 1024 0 512 1024 1536 2048 0 1024 2048 3072 4096 0 2048 4096 6144 8192 0 256 512 768 1024 0 512 1024 1536 2048 0 1024 2048 3072 4096 0 2048 4096 6144 8192 0 4096 8192 12288 16384 +DEAL::right: 0 1 2 3 4 0 2 4 6 8 0 4 8 12 16 0 8 16 24 32 0 16 32 48 64 +DEAL::Result: 1516757084 +DEAL:: +DEAL::1516757084 -- 2.39.5