From: Wolfgang Bangerth Date: Thu, 8 Jun 2023 23:30:15 +0000 (-0600) Subject: Add a test. X-Git-Tag: v9.5.0-rc1~134^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6784fba0e06691a6968933319d38409771d59e2;p=dealii.git Add a test. --- diff --git a/tests/tensors/copy_from_01.cc b/tests/tensors/copy_from_01.cc new file mode 100644 index 0000000000..d5e68e0864 --- /dev/null +++ b/tests/tensors/copy_from_01.cc @@ -0,0 +1,53 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Check copy_to() and copy_from() between tensors and full matrices. + +#include + +#include + +#include "../tests.h" + +int +main() +{ + initlog(); + + const unsigned int matrix_dimension = 4; + + Tensor<2, matrix_dimension> myTensor; + + FullMatrix myMatrix(matrix_dimension, matrix_dimension); + + for (unsigned int i = 0; i < matrix_dimension; i++) + for (unsigned int j = 0; j < matrix_dimension; j++) + { + myMatrix(i, j) = i + j; + } + + myMatrix.copy_to(myTensor); + + deallog << myTensor.dimension << std::endl; + deallog.get_file_stream() << myTensor << std::endl; + + myTensor *= 2; + myMatrix.copy_from(myTensor); + for (unsigned int i = 0; i < matrix_dimension; i++) + for (unsigned int j = 0; j < matrix_dimension; j++) + { + Assert(myMatrix(i, j) == 2. * (i + j), ExcInternalError()); + } +} diff --git a/tests/tensors/copy_from_01.output b/tests/tensors/copy_from_01.output new file mode 100644 index 0000000000..4f29e0dcf1 --- /dev/null +++ b/tests/tensors/copy_from_01.output @@ -0,0 +1,3 @@ + +DEAL::4 +0.00000 1.00000 2.00000 3.00000 1.00000 2.00000 3.00000 4.00000 2.00000 3.00000 4.00000 5.00000 3.00000 4.00000 5.00000 6.00000