From ab868f03b781edcfb94ad3b17f14fe6f7a3b1cc6 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 13 Feb 2015 08:47:57 -0600 Subject: [PATCH] Add a test. --- tests/base/product_type_04.cc | 67 +++++++++++++++++++++++++ tests/base/product_type_04.debug.output | 2 + 2 files changed, 69 insertions(+) create mode 100644 tests/base/product_type_04.cc create mode 100644 tests/base/product_type_04.debug.output diff --git a/tests/base/product_type_04.cc b/tests/base/product_type_04.cc new file mode 100644 index 0000000000..99962fce8c --- /dev/null +++ b/tests/base/product_type_04.cc @@ -0,0 +1,67 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 that the product between a tensor and an integer behaves just +// like that of the tensor and the integer-converted-to-double + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + +#include +#include + + + +int main() +{ + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + // try it for a rank-1 tensor + { + Tensor<1,3> t; + t[0] = 1.23456; + t[1] = 2.46802; + t[2] = 3.69258; + Assert (7*t == 7.0 * t, ExcInternalError()); + Assert (t*7 == t * 7.0, ExcInternalError()); + Assert (t*7 == 7*t , ExcInternalError()); + Assert ((t*7 - (t+t+t+t+t+t+t)).norm() < 1e-12, ExcInternalError()); + } + + // now also try it for a rank-2 tensor (higher rank tensors are + // composed of lower-rank tensors) + { + Tensor<2,2> t; + t[0][0] = 1.23456; + t[0][1] = 7.87965; + t[1][0] = 2.64686; + t[1][1] = 3.35792; + Assert (7*t == 7.0 * t, ExcInternalError()); + Assert (t*7 == t * 7.0, ExcInternalError()); + Assert (t*7 == 7*t , ExcInternalError()); + Assert ((t*7 - (t+t+t+t+t+t+t)).norm() < 1e-12, ExcInternalError()); + } + + deallog << "OK" << std::endl; +} diff --git a/tests/base/product_type_04.debug.output b/tests/base/product_type_04.debug.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/base/product_type_04.debug.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5