From 9e2a8e4a6ff7fd53b3b5cfaa5a5784d58d7862e6 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 20 Jun 2013 18:46:49 +0000 Subject: [PATCH] Add a test for ConstantTensorFunctions git-svn-id: https://svn.dealii.org/trunk@29843 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/base/functions_09.cc | 148 ++++++++++++++++++++++++++++ tests/base/functions_09/cmp/generic | 133 +++++++++++++++++++++++++ 2 files changed, 281 insertions(+) create mode 100644 tests/base/functions_09.cc create mode 100644 tests/base/functions_09/cmp/generic diff --git a/tests/base/functions_09.cc b/tests/base/functions_09.cc new file mode 100644 index 0000000000..9ffd51fc7c --- /dev/null +++ b/tests/base/functions_09.cc @@ -0,0 +1,148 @@ +//----------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2013 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//----------------------------------------------------------------------------- + +// Test ConstantTensorFunction + +#include "../tests.h" +#include + + + +// Fill a tensor with values: +template +struct FillTensor +{ + static void fill_tensor(Tensor &tensor, int base) + { + for(int i = 0; i < dim; ++i) + FillTensor::fill_tensor(tensor[i], 10 * base + i); + } +}; + +template +struct FillTensor<1, dim> +{ + static void fill_tensor(Tensor<1, dim> &tensor, int base) + { + for(int i = 0; i < dim; ++i) + tensor[i] = 10 * base + i; + } +}; + + + +// Print a tensor of arbitrary rank to the console: +template +struct PrintTensor +{ + static void print_tensor(const Tensor &tensor) + { + for(int i = 0; i < dim; ++i) + { + PrintTensor::print_tensor(tensor[i]); + deallog << " "; + } + } +}; + +template +struct PrintTensor<1, dim> +{ + static void print_tensor(const Tensor<1, dim> &tensor) + { + for(int i = 0; i < dim; ++i) + deallog << tensor[i] << " "; + } +}; + + + +template +void check () +{ + deallog << "ConstantTensorFunction<" + << rank << ", " << dim << ">:" << std::endl; + + Tensor value; + FillTensor::fill_tensor(value, 0); + + ConstantTensorFunction tensor_function(value); + TensorFunction *foo = &tensor_function; + + + Point point; + for (int i = 0; i < dim; ++i) + point(i) = i; + + deallog << "->value:" << std::endl; + PrintTensor::print_tensor( foo->value(point) ); + deallog << std::endl; + + deallog << "->gradient:" << std::endl; + PrintTensor::print_tensor( foo->gradient(point) ); + deallog << std::endl; + + + std::vector > points; + points.push_back(point); + + for (int i = 0; i < dim; ++i) + point(i) = dim-i; + points.push_back(point); + + std::vector > tensors; + std::vector > gradients; + tensors.resize(2); + gradients.resize(2); + + deallog << "->value_list:" << std::endl; + foo->value_list(points, tensors); + PrintTensor::print_tensor(tensors[0]); + deallog << std::endl; + PrintTensor::print_tensor(tensors[1]); + deallog << std::endl; + + deallog << "->gradient_list:" << std::endl; + foo->gradient_list(points, gradients); + PrintTensor::print_tensor(gradients[0]); + deallog << std::endl; + PrintTensor::print_tensor(gradients[1]); + deallog << std::endl; +} + + + +int main() +{ + std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output"); + std::ofstream logfile(logname.c_str()); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + check<1,1>(); + check<2,1>(); + check<3,1>(); + check<4,1>(); + + check<1,2>(); + check<2,2>(); + check<3,2>(); + check<4,2>(); + + check<1,3>(); + check<2,3>(); + check<3,3>(); + check<4,3>(); +} + diff --git a/tests/base/functions_09/cmp/generic b/tests/base/functions_09/cmp/generic new file mode 100644 index 0000000000..cb7e8bdab6 --- /dev/null +++ b/tests/base/functions_09/cmp/generic @@ -0,0 +1,133 @@ + +DEAL::ConstantTensorFunction<1, 1>: +DEAL::->value: +DEAL::0 +DEAL::->gradient: +DEAL::0 +DEAL::->value_list: +DEAL::0 +DEAL::0 +DEAL::->gradient_list: +DEAL::0 +DEAL::0 +DEAL::ConstantTensorFunction<2, 1>: +DEAL::->value: +DEAL::0 +DEAL::->gradient: +DEAL::0 +DEAL::->value_list: +DEAL::0 +DEAL::0 +DEAL::->gradient_list: +DEAL::0 +DEAL::0 +DEAL::ConstantTensorFunction<3, 1>: +DEAL::->value: +DEAL::0 +DEAL::->gradient: +DEAL::0 +DEAL::->value_list: +DEAL::0 +DEAL::0 +DEAL::->gradient_list: +DEAL::0 +DEAL::0 +DEAL::ConstantTensorFunction<4, 1>: +DEAL::->value: +DEAL::0 +DEAL::->gradient: +DEAL::0 +DEAL::->value_list: +DEAL::0 +DEAL::0 +DEAL::->gradient_list: +DEAL::0 +DEAL::0 +DEAL::ConstantTensorFunction<1, 2>: +DEAL::->value: +DEAL::0 1.00000 +DEAL::->gradient: +DEAL::0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 +DEAL::0 1.00000 +DEAL::->gradient_list: +DEAL::0 0 0 0 +DEAL::0 0 0 0 +DEAL::ConstantTensorFunction<2, 2>: +DEAL::->value: +DEAL::0 1.00000 10.0000 11.0000 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 10.0000 11.0000 +DEAL::0 1.00000 10.0000 11.0000 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 +DEAL::ConstantTensorFunction<3, 2>: +DEAL::->value: +DEAL::0 1.00000 10.0000 11.0000 100.000 101.000 110.000 111.000 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 10.0000 11.0000 100.000 101.000 110.000 111.000 +DEAL::0 1.00000 10.0000 11.0000 100.000 101.000 110.000 111.000 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::ConstantTensorFunction<4, 2>: +DEAL::->value: +DEAL::0 1.00000 10.0000 11.0000 100.000 101.000 110.000 111.000 1000.00 1001.00 1010.00 1011.00 1100.00 1101.00 1110.00 1111.00 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 10.0000 11.0000 100.000 101.000 110.000 111.000 1000.00 1001.00 1010.00 1011.00 1100.00 1101.00 1110.00 1111.00 +DEAL::0 1.00000 10.0000 11.0000 100.000 101.000 110.000 111.000 1000.00 1001.00 1010.00 1011.00 1100.00 1101.00 1110.00 1111.00 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::ConstantTensorFunction<1, 3>: +DEAL::->value: +DEAL::0 1.00000 2.00000 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 2.00000 +DEAL::0 1.00000 2.00000 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 0 +DEAL::ConstantTensorFunction<2, 3>: +DEAL::->value: +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::ConstantTensorFunction<3, 3>: +DEAL::->value: +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 100.000 101.000 102.000 110.000 111.000 112.000 120.000 121.000 122.000 200.000 201.000 202.000 210.000 211.000 212.000 220.000 221.000 222.000 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 100.000 101.000 102.000 110.000 111.000 112.000 120.000 121.000 122.000 200.000 201.000 202.000 210.000 211.000 212.000 220.000 221.000 222.000 +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 100.000 101.000 102.000 110.000 111.000 112.000 120.000 121.000 122.000 200.000 201.000 202.000 210.000 211.000 212.000 220.000 221.000 222.000 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::ConstantTensorFunction<4, 3>: +DEAL::->value: +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 100.000 101.000 102.000 110.000 111.000 112.000 120.000 121.000 122.000 200.000 201.000 202.000 210.000 211.000 212.000 220.000 221.000 222.000 1000.00 1001.00 1002.00 1010.00 1011.00 1012.00 1020.00 1021.00 1022.00 1100.00 1101.00 1102.00 1110.00 1111.00 1112.00 1120.00 1121.00 1122.00 1200.00 1201.00 1202.00 1210.00 1211.00 1212.00 1220.00 1221.00 1222.00 2000.00 2001.00 2002.00 2010.00 2011.00 2012.00 2020.00 2021.00 2022.00 2100.00 2101.00 2102.00 2110.00 2111.00 2112.00 2120.00 2121.00 2122.00 2200.00 2201.00 2202.00 2210.00 2211.00 2212.00 2220.00 2221.00 2222.00 +DEAL::->gradient: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::->value_list: +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 100.000 101.000 102.000 110.000 111.000 112.000 120.000 121.000 122.000 200.000 201.000 202.000 210.000 211.000 212.000 220.000 221.000 222.000 1000.00 1001.00 1002.00 1010.00 1011.00 1012.00 1020.00 1021.00 1022.00 1100.00 1101.00 1102.00 1110.00 1111.00 1112.00 1120.00 1121.00 1122.00 1200.00 1201.00 1202.00 1210.00 1211.00 1212.00 1220.00 1221.00 1222.00 2000.00 2001.00 2002.00 2010.00 2011.00 2012.00 2020.00 2021.00 2022.00 2100.00 2101.00 2102.00 2110.00 2111.00 2112.00 2120.00 2121.00 2122.00 2200.00 2201.00 2202.00 2210.00 2211.00 2212.00 2220.00 2221.00 2222.00 +DEAL::0 1.00000 2.00000 10.0000 11.0000 12.0000 20.0000 21.0000 22.0000 100.000 101.000 102.000 110.000 111.000 112.000 120.000 121.000 122.000 200.000 201.000 202.000 210.000 211.000 212.000 220.000 221.000 222.000 1000.00 1001.00 1002.00 1010.00 1011.00 1012.00 1020.00 1021.00 1022.00 1100.00 1101.00 1102.00 1110.00 1111.00 1112.00 1120.00 1121.00 1122.00 1200.00 1201.00 1202.00 1210.00 1211.00 1212.00 1220.00 1221.00 1222.00 2000.00 2001.00 2002.00 2010.00 2011.00 2012.00 2020.00 2021.00 2022.00 2100.00 2101.00 2102.00 2110.00 2111.00 2112.00 2120.00 2121.00 2122.00 2200.00 2201.00 2202.00 2210.00 2211.00 2212.00 2220.00 2221.00 2222.00 +DEAL::->gradient_list: +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -- 2.39.5